#!/mit/perl5/bin/perl -w

use strict;

if ($ARGV[0]=~/-h/) {
    print "Usage: $0 actor logfile\n";
    exit(1);
}

my $actor=$ARGV[0];
my $in=$ARGV[1];
open(IN, $in) || die "Can't open '$in' for reading!\n";
my $base_time=0;
my $last_action=0;
my @summary;
my $delta;
my $tc=0;
while(<IN>) {
    chomp;
    next if (#!/$actor gains Shield Block/ &&
	     !/$actor\s*\'s Revenge/ &&
	     #!/$actor\s*\'s Heroic Strike/ &&
	     !/$actor\s*\'s Shield Slam/ &&
	     !/$actor\s*\'s Devastate/ &&
	     !/$actor\s*\'s Thunder Clap/ &&
	     #!/$actor\s*\'s Cleave/ &&
	     !/$actor\s*\'s Hamstring/);
    if (/Thunder Clap/) {
	next if $tc==1;
	$tc=1;
    } else {
	$tc=0;
    }
    my ($date, $time, $else)=split(/\s+/, $_, 3);
    my ($hour, $minute, $second)=split(/:/, $time);
    if ($base_time==0) {
	$base_time=$hour*3600 + $minute*60 + $second;
	next;
    } else {
	$time=$hour*3600 + $minute*60 + $second - $base_time;
	$delta=$time-$last_action;
#	if ($delta<1) {print "$_\n";}
#	printf ("%.1f\n", $delta);
	$last_action=$time;
    }
    if ($delta<=5) {
	$summary[int($delta*10)]++;
#    } else {
#	print "skipping: $delta\n";
    }
}
for (my $i=0;$i<=50;$i++) {
    next if !defined($summary[$i]);
    printf "%.1f, $summary[$i]\n", ($i/10);
}
close(IN);
