#!/usr/ug/bin/perl5 # # sample use: # hothour # # by Wei-Hwa Huang (whuang@ugcs.caltech.edu) use strict; my $ct; my $TIME = `date +%s`; chomp $TIME; my @MESSAGE; my $muck; my %catlist = (); # add the old cats to catlist. if (-e "/home/whuang/gale/stats") { open(FHAND,"; chomp(@data); my $line; foreach $line (@data) { my ($tm, $guy, $ct) = split(' ',$line); if ($TIME - $tm <= (60 * 60 * 99)) { my @ar = (); if ($catlist{$ct} == 0) { $catlist{$ct} = \@ar; } push(@{$catlist{$ct}},"$tm $guy"); } } close(FHAND); } my $outstring = "| /usr/contrib/bin/gsend bot.hot.hourly.".(($TIME/60/60-7)%24); my %weighthash = (); sub bymedian { my @ta = @$a; my @tb = @$b; } sub metric { my @test = @_; my $num; my $sum = 0; for $num (0..$#test) { $sum += 1/($test[$num]+1); } return -$sum; } sub metricold { my @test = @_; my $num; my $sum = 0; for $num (0..$#test) { $sum += 1/($test[$num]+1); } return -$sum; } sub metrictest { my @test = @_; my $num; my $best = $test[0]*2; for ($num = 1; 2*$num <= $#test; $num ++) { if ($best > $test[$num]/$num) { $best = $test[$num]/$num; } } return $best; } sub numerically { $a <=> $b; } sub bykey { return -($weighthash{$a} <=> $weighthash{$b}); } sub numform { (my $boog) = @_; my $result = ''; $result .= '0' if (int($boog/3600) < 10); $result .= (int($boog/3600)); $result .= ':'; $result .= '0' if (int($boog/60%60) < 10); $result .= (int($boog/60%60)); $result .= ':'; $result .= '0' if (int($boog%60) < 10); $result .= (int($boog%60)); return $result; } my $ct; my %namecount = (); open(FRAC,">/home/whuang/tmtmtmtm"); foreach $ct (keys %catlist) { my $tmp = $catlist{$ct}; my %namehash = (); foreach (@$tmp) { my ($timm, $guy) = split(' ',$_); $_ = $TIME - $timm; $namehash{$_} = $guy; } my @tmp = sort numerically (@$tmp); my %namecthash = (); foreach (@tmp) { $namecthash{$namehash{$_}} ++; $weighthash{$ct} += 1/($namecthash{$namehash{$_}}+20)/($_ + 300); print FRAC ($namecthash{$namehash{$_}}),"/",($_+1)," $ct $namehash{$_}\n"; } my @boog = keys %namecthash; $namecount{$ct} = $#boog+1; } close(FRAC); sub prependspaces { my $value = $_[0]; return (" ".$value) if ($value < 10); return (" ".$value) if ($value < 100); return $value; } my @statcatlist = (); my @keylist = sort bykey (keys %catlist); foreach $ct (@keylist) { my @tmp = @{$catlist{$ct}}; my @tempstats; push(@tempstats,&prependspaces($#tmp+1)); push(@tempstats,&numform($tmp[0])); push(@tempstats,&numform($tmp[$#tmp/2])); push(@tempstats,&numform($tmp[$#tmp])); push(@tempstats,&prependspaces($namecount{$ct})); $ct =~ s/^\./\//g; push(@tempstats,$ct); push(@statcatlist,\@tempstats); } #@statcatlist = sort bymedian @statcatlist; my $ct = 0; while ($ct < $#statcatlist) { my @junk1 = @{$statcatlist[$ct]}; my @junk2 = @{$statcatlist[$ct+1]}; if ($junk1[0] == $junk2[0] and $junk1[1] == $junk2[1] and $junk1[2] == $junk2[2] and $junk1[3] == $junk2[3]) { ${statcatlist[$ct]}[5] .= ','.$junk2[5]; splice(@statcatlist,$ct+1,1); } else { ${statcatlist[$ct]}[5] = substr(${statcatlist[$ct]}[5],0,35); $ct++; } } @MESSAGE = (); $MESSAGE[0] = "Hottest categories in pub\@ofb.net in the last 100 hours:\n"; $MESSAGE[1] = "Puff(-er)s Oldest Median Newest Category\n"; my $junk; my @junk; foreach $junk (@statcatlist[0..((17<$#statcatlist)?17:$#statcatlist)]) { @junk = @$junk; my $first = $junk[0]; $first = '>1k' if ($first >= 1000); push(@MESSAGE," $first $junk[4] $junk[1] $junk[2] $junk[3] $junk[5]\n"); } $ENV{'GALE_FROM'}= 'Bean Counter'; open(FHAND, $outstring); print FHAND @MESSAGE; close(FHAND);