#!/usr/local/bin/perl
#
# Matthew Gray (mkgray@mit.edu) June '94 Converted to CGI
#


print("Content-Type: text/html\n\n");
&studliness;

sub studliness {

# If you need to modify the metric used for each dash on the chart, don't
# try to change the program. Just change this variable.

$dash_represents = 8001;

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

open(DAILY, "/var/local/plexus/logs/get.plexus.daily");
print("<h1>Web server usage (number of requests) since Jan 1</h1><h2>By week (Sat->Fri)</h2>Week ending...<pre>\n");
while(<DAILY>){
    split;
#    print("0: $_[1], 1: $_[2], 2: $_[3]..\n");
    next if $month{$_[2]} > 200;
    $day[$month{$_[2]} + $_[3]-1] = $_[1];
    $nom[$month{$_[2]} + $_[3]-1] = "$_[2] $_[3]";

}
$max=0;
for $d (0..365){
    $thisweek +=$day[$d];
    $week++;
    if($week == 7){
	$ticks = '-' x ($thisweek/$dash_represents);
	$nom[$d] = "This week so far" unless $nom[$d];
	$h = $nom[$d].(' ' x (18-length($nom[$d])));
	$lastweek = 1 unless $lastweek;
	$perc = int((($thisweek/$lastweek) - 1)*100);
	print("$h: $ticks ($thisweek)") if $thisweek > $n;
	# I added a bit of code here so that negative percentages
	# don't print as "+-nn%" ... - nocturne
	print( "  ",$perc>0?"+":"","$perc%") if $thisweek > $n && $lastweek != 1;
	print("\n") if $thisweek > $n;
	if($thisweek > $max){ $max = $thisweek;}
	if($thisweek > $max){ $mh = $nom[$d+1];}
	$week = 0;
	$lastweek = $thisweek;
	$thisweek = 0;
    }
}
#$max = ($max) ? 1:$max;
print("</pre>\n");
$# = '%1g';
print("\nThat is, a request every ", 604800/$max, " seconds (for the week with $max requests)  Each '-' represents $dash_represents connections\n");
}

1;

