#!/usr/bin/perl

while (<>) {
	next unless /Optimal/;
	/.*Time:(\d+)\s.*Reward:([\-\d\.]+)\s.*Optimal:(\w+)\s*$/;
	$time = $1;
	next if ($time == 0);
	if (exists $COUNT{$time}) { $COUNT{$time}++; }
	else { $COUNT{$time} = 1; }
	$REWARD{$time} += $2;
	$OPTIMAL{$time}++ if ($3 eq "true");
}

foreach $time (sort numeric keys %COUNT) {
	print "$time\t" .
		($REWARD{$time} / $COUNT{$time}) . "\t" .
		($OPTIMAL{$time} /$COUNT{$time}) . "\n";
}

sub numeric {
   $a <=> $b;
}
