Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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 stats file to get the infos, instead of grabbing the page from perlmonks.


#!/usr/bin/perl -w # mstats Version 1.2 # 7/29/2000 by ase ( # 6/13/2001 by OeufMayo ( # # 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 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;
my $OeufMayo = new PerlMonger::Paris({http => ''});</kbd>

In reply to Re: Personal Monk Stats plot creator (xrepwalker patch) by OeufMayo
in thread Personal PerlMonks Stats plot creator by ase

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (3)
    As of 2018-07-21 21:46 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (450 votes). Check out past polls.