#!/afs/athena/contrib/perl/perl 

require 'ctime.pl';
%mondaytrans = ("Jan", 0,
          "Feb", 31,
          "Mar", 59,
          "Apr", 90,
          "May", 120,
          "Jun", 151,
          "Jul", 181,
          "Aug", 212,
          "Sep", 243,
          "Oct", 273,
          "Nov", 304,
          "Dec", 334);
 

@debugger = ('mkgray', 'bbartley', 'jsheena', 'lacsap', 'biff',
		'deverell', 'dbkoen', 'rtwhitma');

open (LOG, "/afs/fishwrap.mit.edu/export/data/log/ErrorLog") ||
die "Error----  I can't seem to get at the Errorlog: $!";
while(<LOG>)
	{
	next if !/paper/;
	($jpaper, $failed, $for, $user, $with, $blah, $weekday, 
	$month, $day, $time, @trash) = split;
	$day = $day+$mondaytrans{$month};
	($hour, $minute, $sec) = split(/:/, $time);
	$hours{int($hour)}++;
	$edays{$day}++;
	$errors{$user}++;
	$toterrs++;
	$debugerrs++ if grep(/$user/, @debugger);
	}
print("Total errors: $toterrs with $debugerrs debugging errors\n");


open (LOG, "/afs/fishwrap.mit.edu/export/data/log/PaperLog") ||
die "Error----  I can't seem to get at the Paperlog: $!";
while(<LOG>)
	{
	next if !/paper/;
	($jpaper, $user, $weekday, $month, $day, $time, @trash) = split;
	($hour, $minute, $sec) = split(/:/, $time);
	$day = $day+$mondaytrans{$month};
	$hours{int($hour)}++;
	$newusers{$day}++ unless $users{$user};
	$users{$user}++;
	$days{$day}++;
	$udays{$day}++ unless $foo{$day, $user};
	$foo{$day, $user} = 1;
	$firsttime{$user} = "$day:$time" unless $firsttime{$user};
	$lasttime{$user} = "$day:$time";
	}

$binsize = .05;
for $u (keys %users){
#	printf("%.2f\n", $errors{$u}/$users{$u});
	print("User $u:  ", int(100*$errors{$u}/$users{$u}), "% errors ",
	"($users{$u} papers generated)\n") 
	if ($errors{$u}/$users{$u})> .5;
	$histogram[int(($errors{$u}/$users{$u})/$binsize)]++;
}
print("Average errors per use (for users)\n");
for $h (0..$#histogram){
	printf("%.2f-%.2f ",$h*$binsize, ($h*$binsize)+$binsize); 
	print "-" x ($histogram[$h]/8);
	print " $histogram[$h]\n";
}
print("Average errors per use by day\n");
$binsize = .05;
for $d (1..150){
	printf("%2d ", $d);
	print "-" x ($edays{$d}/$days{$d}*100) unless !$days{$d};
	printf("%.2f", $edays{$d}/$days{$d}) unless !$days{$d};
	print("\n");

}
@histogram=();
print("Percentage errors received by number of papers generated\n");
for $u (keys %users){
	$histogram[$users{$u}] += $errors{$u}/$users{$u};
	$histn[$users{$u}]++;
}
for $h (0..$#histogram){
	printf("%2d ", $h);
	print "-" x ($histogram[$h]/($histn[$h])*100) unless !$histn[$h];
	printf(" %.2f", $histogram[$h]/$histn[$h]) unless !$histn[$h];
	print("\n");
}



close(LOG);


