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
{
#