Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

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

Here's a patch that will give you histogram output like so:

User: larryl Total articles: 23 Total reputation: 186 Min reputation: -4 Max reputation: 22 Average reputation: 8.09 Reputation Article Count ------------- ------------------------------------------------------ -5 .. -1 [ 1] # 0 .. 4 [ 7] ####### 5 .. 9 [ 4] #### 10 .. 14 [ 7] ####### 15 .. 19 [ 3] ### 20 .. 24 [ 1] #

The patch:

rcsdiff -c -r1.1 -r1.2 statswhore.pl =================================================================== RCS file: RCS/statswhore.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** /tmp/T0fIaia5 Sat Mar 17 15:21:09 2001 --- /tmp/T1gIaia5 Sat Mar 17 15:21:09 2001 *************** *** 1,7 **** #!/usr/local/bin/perl -w # ! # Invoke with './statswhore.pl [-u username] [-p password]' # # Alternatively, username and/or password can be embedded into the +script, if you don't want # command line arguments. --- 1,9 ---- #!/usr/local/bin/perl -w + use strict; # ! # Invoke with ! # './statswhore.pl [-u username] [-p password] [-b histogram_bi +nsize]' # # Alternatively, username and/or password can be embedded into the +script, if you don't want # command line arguments. *************** *** 27,55 **** use strict; use LWP::Simple; use Getopt::Std; my $def_username = ""; # Set this to your user name if you don't wa +nt to use the -u option my $def_password = ""; # Set this to your pass word if you don't wa +nt to use the -p option my $pmsite = "http://www.perlmonks.org/index.pl"; { my %args = (); ! getopts ('u:p:', \%args); my $username = $args{u} || $def_username; my $password = $args{p} || $def_password; die "No password and/or username. Program terminated.\n" if (!$u +sername || !$password); ! show_reps ($username, $password); } sub show_reps { ! @_ == 2 or die "Incorrect number of parameters"; ! my ($username, $password) = @_; my $total = 0; my $rarticles = get_article_list ($username, $password); --- 29,60 ---- use strict; use LWP::Simple; use Getopt::Std; + use POSIX qw(ceil floor); my $def_username = ""; # Set this to your user name if you don't wa +nt to use the -u option my $def_password = ""; # Set this to your pass word if you don't wa +nt to use the -p option + my $def_binsize = 5; # bin size for reputations my $pmsite = "http://www.perlmonks.org/index.pl"; { my %args = (); ! getopts ('u:p:b:', \%args); my $username = $args{u} || $def_username; my $password = $args{p} || $def_password; + my $binsize = $args{b} || $def_binsize; die "No password and/or username. Program terminated.\n" if (!$u +sername || !$password); ! show_reps ($username, $password, $binsize); } sub show_reps { ! @_ == 3 or die "Incorrect number of parameters"; ! my ($username, $password, $binsize) = @_; my $total = 0; my $rarticles = get_article_list ($username, $password); *************** *** 67,72 **** --- 72,79 ---- print sprintf (" Max reputation: %d\n", @$rarticles [-1]->[ +1]); print sprintf ("Average reputation: %3.2f\n", $total / ($#$rartic +les + 1)); print "\n"; + show_histogram($binsize, $total, $rarticles); + print "\n"; } sub get_article_list *************** *** 121,126 **** --- 128,176 ---- return ($rowcnt); } + sub show_histogram + { + my ($binsize, $total, $rarticles) = @_; + + # Divide articles into bins based on reputation: + my %bins = (); + for ( @$rarticles ) { + my $rep = @$_[1]; + $bins{floor(($rep+.5)/$binsize)}++; + } + + my @bins = sort {$a<=>$b} keys %bins; + my $bin = $bins[0]; # lowest reputation bin + my $maxbin = $bins[-1]; # highest reputation bin + + # Try to keep histogram on one page: + my $width = 50; + my $scale = 1; + my $maxrep = @$rarticles [-1]->[1]; + if ( $maxrep > $width && $maxrep <= ($width*5) ) { + $scale = 5; + } + elsif ( $maxrep > ($width*5) ) { + while ( ($maxrep/$scale) > $width ) { + $scale *= 10; + } + } + + my $start = $bin * $binsize; + my $end = $start + $binsize - 1; + print " Reputation Article Count\n"; + print "------------- -------", "-" x 50, "\n"; + do { + my $count = $bins{$bin} || 0; + my $extra = ( $count % $scale ) ? '.' : ''; + printf "%4d .. %4d \[%4d\] %s$extra\n", + $start, $end, $count, '#' x ceil($count/$scale); + $start += $binsize; + $end += $binsize; + } while ( $bin++ < $maxbin ); + print "\n Scale: #=$scale\n" if $scale > 1; + } + BEGIN { #


In reply to Re: statswhore.pl by larryl
in thread statswhore.pl by jcwren

Title:
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!
  • 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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (9)
    As of 2015-07-04 14:43 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (60 votes), past polls