#!/usr/athena/bin/perl

#	For stats of usage:
#	percfree filename clustername|totals

if($#ARGV<0){print"percfree filename clustername\n"; exit;}

open (LFF, "$ARGV[0]");
$minute=0;
while (<LFF>) {

	if(/\d\d:\d\d:\d\d/) {
		split;
		@time = split(/:/, $_[3]);
		$month = $_[1];
		if($_[2] ne $day){
			$day = $_[2];
			print(STDERR "\n$month $day: ");	
}
		$hour = $time[0];
		$x = int($time[1]);
		if($x >= 50) {
			$minute = "00";
			$hour++; }
		if($x <= 50) { 
		$minute = 30; }
	}

	if(/$ARGV[1]/) {
		split;
		if($_[$#_]!=0){
		$perc = 100*($_[$#_-1]/$_[$#_]);
		$tindex = 2*$hour;
		if ($minute == 30) { $tindex++; }
		$percents[$tindex]=($dats[$tindex]*$percents[$tindex])+$perc;
		$dats[$tindex]++;
		$percents[$tindex] = $percents[$tindex]/($dats[$tindex]);
		$iperc = int($percents[$tindex]);
#		print("At $hour:$minute average free-- $iperc    ($dats[$tindex])\n");
#		$y = int($tindex/2);
#		print("$y: $iperc\n");
		print(STDERR ".");
	}
		}
	}
print(STDERR "\n");
foreach $i (0..49) {
	$y = int($i/2);
	$iperc = int($percents[$i]);
	print("$y: $iperc\n");
}





