Permalink
Browse files

new leaderboard management module

  • Loading branch information...
1 parent cf42330 commit 5aac3d72273ba64e5875cdcb1892d638a9c7d638 @barbie committed Jun 30, 2012
View
@@ -2,6 +2,7 @@ Revision history for CPAN-Testers-WWW-Statistics
1.00 current
- moved _tester_name() into parent as tester().
+ - added Leaderboard management module.
0.99 22/04/2012
- META tests no longer require specific versions.
View
@@ -1,5 +1,6 @@
bin/addresses.pl
bin/cpanstats-writegraphs
+bin/cpanstats-leaderboard
bin/cpanstats-writepages
bin/getmailrc.pl
Changes
@@ -12,6 +13,7 @@ examples/example-settings.ini
examples/reset.sh
lib/CPAN/Testers/WWW/Statistics.pm
lib/CPAN/Testers/WWW/Statistics/Graphs.pm
+lib/CPAN/Testers/WWW/Statistics/Leaderboard.pm
lib/CPAN/Testers/WWW/Statistics/Pages.pm
Makefile.PL
MANIFEST
@@ -21,6 +23,7 @@ README
t/01base.t
t/05setup_db-cpanstats.t
t/05setup_db-ixlatest.t
+t/05setup_db-leaderboard.t
t/05setup_db-osname.t
t/05setup_db-release_summary.t
t/05setup_db-uploads.t
@@ -30,6 +33,7 @@ t/50logging.ini
t/50logging.t
t/51init.t
t/52methods-graphs.t
+t/52methods-leaderboard.t
t/52methods-pages.t
t/52methods-stats.t
t/56writes-update.txt
View
4 README
@@ -36,6 +36,10 @@ SCRIPTS
Selects all the tester email addresses and attempts to guess the mapping of
any addresses not mapped to known people in the address.txt file.
+* cpanstats-leaderboard
+
+Data table management script. Generates all the leaderboard entries.
+
* cpanstats-writepages
Web page creation script. Generates all the HTML files.
View
@@ -0,0 +1,128 @@
+#!/usr/bin/perl
+use strict;
+$|++;
+
+my $VERSION = '0.01';
+
+#----------------------------------------------------------------------------
+
+
+# -------------------------------------
+# Library Modules
+
+use CPAN::Testers::WWW::Statistics;
+use Getopt::Long;
+
+# -------------------------------------
+# Variables
+
+my (%options);
+
+# -------------------------------------
+# Program
+
+init_options();
+
+my $ctws = CPAN::Testers::WWW::Statistics->new();
+my $data = $ctws->leaderboard( %options );
+
+check( $data ) if($options{check});
+
+# -------------------------------------
+# Subroutines
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item check
+
+Display check results.
+
+=item init_options
+
+Prepare command line options.
+
+=item help
+
+Help screen.
+
+=back
+
+=cut
+
+sub check {
+ my $data = shift;
+
+ for my $date (sort keys %$data) {
+ print "$date,$data{$date}->{cpanstats},$data{$date}->{leaderboard}\n";
+ }
+}
+
+sub init_options {
+ GetOptions( \%options,
+ 'config=s',
+ 'logfile=s',
+ 'logclean=i',
+
+ 'renew',
+ 'update',
+ 'check',
+ 'postdate=s',
+
+ 'help|h',
+ 'version|v'
+ ) or help(1);
+
+ help(1) if($options{help});
+ help(0) if($options{version});
+
+ $options{update} = 1 unless($options{renew} || $options{update} || $options{check} || $options{postdate});
+}
+
+sub help {
+ my $full = shift;
+
+ if($full) {
+ print "\n";
+ print "Usage:$0 --config=<file> \\\n";
+ print " [--logfile=<file> [--logclean=<1|0>]] \\\n";
+ print " [--renew] [--update] \\\n";
+ print " [--help|h] [--version|v] \n\n";
+
+# 12345678901234567890123456789012345678901234567890123456789012345678901234567890
+ print "This program builds the CPAN Testers Statistics website.\n";
+
+ print "\nFunctional Options:\n";
+ print " [--config=<file>] # path to config file [required]\n";
+ print " [--logfile=<file>] # path to logfile\n";
+ print " [--logclean] # overwrite log if specified\n";
+
+ print "\nRun Mode Options:\n";
+ print " [--renew] # renew leaderboard\n";
+ print " [--update] # update leaderboard\n";
+
+ print "\nOther Options:\n";
+ print " [--version] # program version\n";
+ print " [--help] # this screen\n";
+
+ print "\nFor further information type 'perldoc $0'\n";
+ }
+
+ print "$0 v$VERSION\n";
+ exit(0);
+}
+
+__END__
+
+DROP TABLE IF EXISTS leaderboard;
+CREATE TABLE leaderboard (
+ postdate varchar(8) NOT NULL,
+ osname varchar(255) NOT NULL,
+ tester varchar(255) NOT NULL,
+ score int(10) DEFAULT 0,
+ PRIMARY KEY (postdate,osname,tester),
+ KEY IXOS (osname),
+ KEY IXTEST (tester)
+);
+
@@ -1,6 +1,5 @@
[MASTER]
mainstore=cpanstats.json
-leadstore=leaderboard.json
monthstore=cpanstats-%s.json
directory=/var/www/cpanstats
@@ -33,6 +33,7 @@ use HTML::Entities;
use IO::File;
use Regexp::Assemble;
+use CPAN::Testers::WWW::Statistics::Leaderboard;
use CPAN::Testers::WWW::Statistics::Pages;
use CPAN::Testers::WWW::Statistics::Graphs;
@@ -168,6 +169,10 @@ sub new {
=over 4
+=item * leaderboard
+
+Maintain the leaderboard table as requested.
+
=item * make_pages
Method to manage the data update and creation of all the statistics web pages.
@@ -217,6 +222,19 @@ __PACKAGE__->mk_accessors(
builder missing mailrc logfile logclean copyright noreports tocopy
tolink osnames known_t known_s ));
+sub leaderboard {
+ my ($self,%options) = @_;
+
+ my $lb = CPAN::Testers::WWW::Statistics::Leaderboard->new(parent => $self);
+
+ return $lb->results( $options{results} ) if($options{results});
+ return $lb->check() if($options{check});
+ return $lb->renew() if($options{renew});
+
+ $lb->update() if($options{update});
+ $lb->postdate( $options{postdate} ) if($options{postdate});
+}
+
sub make_pages {
my $self = shift;
$self->_check_files();
@@ -407,6 +425,6 @@ F<http://wiki.cpantesters.org/>
Copyright (C) 2005-2012 Barbie for Miss Barbell Productions.
This module is free software; you can redistribute it and/or
- modify it under the same terms as Perl itself.
+ modify it under the Artistic Licence v2.
=cut
@@ -397,6 +397,6 @@ F<http://wiki.cpantesters.org/>
Copyright (C) 2005-2012 Barbie for Miss Barbell Productions.
This module is free software; you can redistribute it and/or
- modify it under the same terms as Perl itself.
+ modify it under the Artistic Licence v2.
=cut
Oops, something went wrong.

0 comments on commit 5aac3d7

Please sign in to comment.