#!/usr/athena/bin/perl


# attach bitbucket

open (FI, "/mit/bitbucket/zephyr-log/.stats") || die "Couldn't open file: $!";


while (<FI>) {

($tl, $sigl, $ml, $usnam, $tim, $inst)
= split (/[ ]+/, $_);

if ($#ARGV < 1) {
	die "Usage: -------";
	}
	else {
	if ($ARGV[0] eq "-u") {
		$user = $ARGV[1];
		if ($usnam eq $user) {
			$UIN{$inst}++;
			#print $inst;
			}
		}
	if ($ARGV[0] eq "-i") {
		chop ($inst);
		$instance = $ARGV[1];
		if ($inst eq $instance) {
			$UIN{$usnam}++;
			#print $usnam;
			}
		}
	}
}

print "Done with the .stats sorting...\n\n\n\n";
@ukeys = keys %UIN;
sub byvalue { $UIN{$b} <=> $UIN{$a}; }
	@sortedinst = sort byvalue @ukeys;
	for ($x =0; $x <= $#sortedinst; $x++) {
		$item = $sortedinst[$x];
		$q = $UIN{$item};
		if ($ARGV[0] eq "-u") {
			chop ($item); }
		print "$q\t  $item\n";
		}



