Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
#!/usr/bin/perl -w #mstats Version 1.0 #7/29/2000 by ase ( # #Freely redistributable under the same terms as perl itself. # use strict; #Of course. use PerlMonksChat; #access perlmonks and get the page use HTML::TableExtract; #extract the HTML table use Date::Manip; #manipulate the Create times use GD::Graph::lines3d; #create the plots use Net::FTP; #Send them to a webserver #user configuration $Date::Manip::TZ='PST5PDT'; #timezone:see Date::Manip docs my $user = 'ase'; #monk Username (change) #ftp info my $ftpurl = 'CHANGETHIS.ftp'; #ftp url my $ftpuser = 'CHANGETHIS'; #user name my $ftppass = '*******'; #passwd (protect this script) #end of user configuration #users home node (shouldn't have to change) my $url = "" . "node=Perl+Monks+User+Search&" . "usersearch=$user&orderby=createtime%20DESC"; my $p = new PerlMonksChat; #Create Chat Object $p->add_cookies(); #Get the login cookie my $c = $p->getpage($url); #get the users home node $c=~s/bgcolor=>/bgcolor="">/mg; #makes HTML::TableExtract happy my $te = new HTML::TableExtract(headers=>['Rep','Create Time'] ) ->parse($c); #Create the parser and get the table #process the table data into a hash my %data; for my $ts ($te->table_states) { #only one table should be returned for my $row ($ts->rows) { #the row contains [rep, create time] if ($row->[1]) { #if there's a create time my $key = UnixDate($row->[1],"%Q"); #makes key 'yyyymmdd' if(defined($row->[0])) { #if there's a Rep $data{$key}{REP}+=$row->[0]; #add it to the rep total f +or that day $data{$key}{NUM}++; #increment number of posts for that +day } } } } #create a list of lists for the plot objects my ($count,$rep); #running total number of writeups and reps my @data; #the data: munged for GD::graph::lines3d objects my $flag; #has $birth been set? my $birth; #earliest create time in the data for my $key (sort keys %data) { #loop through dates from earliest to + latest; if(!$flag) { #first item? (earliest) $birth=$key; #Set it $flag=1; #don't set it again. } $count+=$data{$key}{NUM}; #Add days writeups to total $rep+=$data{$key}{REP}; #add days rep to total push @{$data[0]}, #days since $birth sprintf("%d",Delta_Format(DateCalc($birth,$key),0 +,"%dt")); push @{$data[1]},$count/($data[0][-1]+1); #avg post/day to date push @{$data[2]},$rep/($data[0][-1]+1); #avg rep/day to date push @{$data[3]},sprintf("%.3f",$rep/$count); #avg rep/post to dat +e } #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}, title => sprintf("%s %.3f)","Recent Avg. " . $plot{$key}{title} . "(currently",$data[$plot{$key}{col +umn}][-1]) ); $plot{$key}{PLOT} = $plot{$key}{GD} ->plot([$data[0],$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); for my $file (keys %plot) { $ftp->binary; $ftp->put("$file.png"); } $ftp->quit; __END__

In reply to 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":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.