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

$thistime = time;
%ACT = ('m', 'Reading and Sending Mail',
        'd', 'Using Discuss',
        'n', 'Netnews',
        'z', 'Zephyr',
        'p', 'Perl stuff',
        'u', 'UROP',
        'a', 'Away from the machine',
        's', 'SIPB stuff',
        'o', 'OLCR',
        'c', 'Class Work',
        'h', 'Hacking (not perl)',
        'e', 'Elvhs list maintenance',
        'g', 'Playing Games',
        'w', 'Wasted',
        'f', 'File management',
        'l', 'Logging activities',
        'x', 'Other');

$lasttime = `tail -1 /tmp/activitylog`;
$ltime = int($lasttime);

$dtime = $thistime - $ltime;

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($dtime);

print("---------------------------------\n");
print("Time since last log entry: $hour:$min:$sec\n");
print("---------------------------------\n");
while(($letter, $descrip)= each %ACT){
print("$letter:\t$descrip\n");
}
print("---------------------------------\n");
print("Enter activities in the form 33 m   for 33% mail\n");
$use = &gettext();
@actions = split(/\n/, $use);
foreach (@actions){
split;
$p = int($_[0]);
$a = $_[1];

$time = int($p*$dtime/100);
open(LOG, ">>/tmp/activitylog");
print(LOG "$time $a\n");
close(LOG);
}
print("\nUsage so far this session:\n");
open(LOG, "/tmp/activitylog");
while(<LOG>){
	if(/ /){
		split;
		$TT{$_[1]} += int($_[0]);
		$ttm += int($_[0]);
	}
}
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($ttm);
print("$hour:$min:$sec total session time\n");
while(($acti, $utime)= each %TT){
	$per = int(($utime*100)/$ttm);

	print("$per% \t$ACT{$acti}\n");
}

$logtime = time;
$lt = $logtime - $thistime;
open(LOG, ">>/tmp/activitylog");
print(LOG "$lt l\n");
print(LOG "$logtime\n");
close(LOG);
print("Done.\n");


sub gettext{
    local($msg);
    $msg = "";
        print("End with a . on a line by itself.\n");
        while($line ne ".\n") {
                $msg = $msg.$line;
                $line = (<STDIN>);
        }
        $msg;
    }
