I did this version of ase's excellent stat grapher a while ago but never posted it. Too bad ase don't come around the monastery often these days, as he wrote some really good nodes, be sure to read them!
I revamped a bit the whole thing, the main difference in this version is that it uses jcwren's xluke_repwalker.pl stats file to get the infos, instead of grabbing the page from perlmonks.
Enjoy!
#!/usr/bin/perl -w
# mstats Version 1.2
# 7/29/2000 by ase (alevenson@uswest.net)
# 6/13/2001 by OeufMayo (briac@pilpre.com)
#
# To do: give the choice between repwalker format and
# epoptai's reputer format
#
#Freely redistributable under the same terms as perl itself.
#
use strict; # Of course.
use Date::Manip; # Manipulate the Create times
use GD::Graph::lines3d; # Create the plots
use Net::FTP;
use vars qw($VERSION);
$VERSION = 1.2;
# User configuration
$Date::Manip::TZ = 'PST5PDT'; # Timezone:see Date::Manip docs
# ftp info
my $ftpurl = 'ftp.foo.bar'; # ftp url
my $ftpuser = 'login'; # user name
my $ftppass = 'password'; # passwd (protect this script)
my $ftpdir = '/home'; # directory
# Monk Username
my $user = 'Anonymous Monk';
# Path for the repwalker rep file
my $stats = "/usr/monkstats/rep.$user";
#end of user configuration
my %data;
open (REP, $stats) or die "Can't open stats file $stats: $!\n";
# Process the table data into a hash
while (<REP>){
# id title rep date
$_ =~ m/^"(\d+)","([^"]+)","(-?\d+)","([^ ]+)\s[0-9:]+"$/;
my $key = UnixDate($4,"%Q");
$data{$key}{REP} += $3; # Add it to the rep total for that day
$data{$key}{NUM}++; # Increment number of posts for that d
+ay
}
# Create a list of lists for the plot objects
my ($count,$rep); # Running total number of writeups and reps
my @g_data; # The data: munged for GD::graph::lines3d objects
my $birth; # Earliest create time in the data
for my $key (sort keys %data) { # Loop through chronologically
$birth ||= $key;
$count += $data{$key}{NUM}; # Add days writeups to total
$rep += $data{$key}{REP}; # Add days rep to total
push @{$g_data[0]}, # Days since $b
+irth
sprintf("%d",Delta_Format(DateCalc($birth,$key),0
+,"%dt"));
push @{$g_data[1]},$count/($g_data[0][-1]+1); # Avg post/da
+y to date
push @{$g_data[2]},$rep/($g_data[0][-1]+1); # Avg rep/d
+ay to date
push @{$g_data[3]},sprintf("%.3f",$rep/$count); # Avg rep/post
+to date
}
# Create some plot settings
my %plot= (avg=>{
ylabel => 'Reputation/Writeup',
title => 'Rep/Writeup',
column => 3,
},
post=>{
ylabel => 'Writeups/Day',
title => 'Writeups/Day',
column => 1,
},
rep=>{
ylabel => 'Reputation/Day',
title => 'Rep/Day',
column => 2,
},
);
# This does most of the work in actually making the plots
for my $key (keys %plot) {
$plot{$key}{GD} = new GD::Graph::lines3d(350,200);
$plot{$key}{GD}->set(
x_label => 'Days since ' . UnixDate($birth,"%b %d, %Y"),
y_label => 'Avg ' . $plot{$key}{ylabel},
x_label_skip => 7, # You may want to change this to get a
+nice x-scaled graphed
title => sprintf("%s %.2f)","Recent Avg. " .
$plot{$key}{title} .
"(currently",$g_data[$plot{$key}{column}][-1])
);
$plot{$key}{PLOT} = $plot{$key}{GD}->plot(
[$g_data[0],$g_data[$plot{$key}{column}]]
);
open(IMG,">$key.png") or die $!;
binmode IMG;
print IMG $plot{$key}{PLOT}->png;
close IMG;
}
# Now send them to our webserver
my $ftp = Net::FTP->new($ftpurl);
$ftp->login($ftpuser,$ftppass);
$ftp->cwd($ftpdir) if $ftpdir;
for my $file (keys %plot) {
$ftp->binary;
$ftp->put("$file.png");
}
$ftp->quit;
<kbd>--
my $OeufMayo = new PerlMonger::Paris({http => 'paris.mongueurs.net'});</kbd> |