From 43048e68161e209ffc25b252f3cbdd048597c438 Mon Sep 17 00:00:00 2001 From: Barbie Date: Sat, 2 Jul 2011 18:23:16 +0100 Subject: [PATCH] storage => mainstore, added leadstore --- Changes | 2 ++ lib/CPAN/Testers/WWW/Statistics.pm | 17 +++++++++++----- lib/CPAN/Testers/WWW/Statistics/Pages.pm | 25 ++++++++++++++---------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Changes b/Changes index ee6235a..fad6aeb 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,8 @@ Revision history for CPAN-Testers-WWW-Statistics - reorganised links and names to be consistent across pages. - restructured Pages.pm, to allow process to be called in stages. - added terms & conditions page. + - changed storage method to mainstore and added leadstore for JSON data + storage files. 0.88 31/10/2010 - added further timestamp test pattern. diff --git a/lib/CPAN/Testers/WWW/Statistics.pm b/lib/CPAN/Testers/WWW/Statistics.pm index 1553fa2..6571cf2 100644 --- a/lib/CPAN/Testers/WWW/Statistics.pm +++ b/lib/CPAN/Testers/WWW/Statistics.pm @@ -55,7 +55,8 @@ keys. config => path to configuration file [required] directory => path to output directory - storage => path to data storage file + mainstore => path to main data storage file + leadstore => path to leaderboard data storage file templates => path to templates directory database => path to SQLite database file address => path to address file @@ -112,7 +113,8 @@ sub new { my @TOCOPY = split("\n", $cfg->val('TOCOPY','LIST')); $self->tocopy(\@TOCOPY); - $self->storage( _defined_or( $hash{storage}, $cfg->val('MASTER','storage' ) )); + $self->mainstore(_defined_or( $hash{mainstore}, $cfg->val('MASTER','mainstore') )); + $self->leadstore(_defined_or( $hash{leadstore}, $cfg->val('MASTER','leadstore') )); $self->templates(_defined_or( $hash{templates}, $cfg->val('MASTER','templates') )); $self->database( _defined_or( $hash{database}, $cfg->val('MASTER','database' ) )); $self->address( _defined_or( $hash{address}, $cfg->val('MASTER','address' ) )); @@ -122,7 +124,8 @@ sub new { $self->copyright( $cfg->val('MASTER','copyright') ); $self->builder( _defined_or( $hash{builder}, $cfg->val('MASTER','builder' ) )); - $self->_log("storage =".($self->storage || '')); + $self->_log("mainstore=".($self->mainstore || '')); + $self->_log("leadstore=".($self->leadstore || '')); $self->_log("templates=".($self->templates || '')); $self->_log("database =".($self->database || '')); $self->_log("address =".($self->address || '')); @@ -164,6 +167,10 @@ Method to manage the creation of the matrix style statistics web pages. Method to manage the creation of the tabular style statistics web pages. +=item * make_leaders + +Method to manage the creation of the OS leaderboard web pages. + =item * make_graphs Method to manage the creation of all the statistics graphs. @@ -182,8 +189,8 @@ Returns the print form of a recorded OS name. =cut __PACKAGE__->mk_accessors( - qw( directory storage templates database address builder logfile logclean - copyright tocopy osnames)); + qw( directory mainstore leadstore templates database address builder + logfile logclean copyright tocopy osnames)); sub make_pages { my $self = shift; diff --git a/lib/CPAN/Testers/WWW/Statistics/Pages.pm b/lib/CPAN/Testers/WWW/Statistics/Pages.pm index 685f6b0..4706129 100644 --- a/lib/CPAN/Testers/WWW/Statistics/Pages.pm +++ b/lib/CPAN/Testers/WWW/Statistics/Pages.pm @@ -145,6 +145,10 @@ Create the matrices pages and distribution list pages. Create all other statistical pages; monthly tables, interesting stats, etc. +=item * build_leaders + +Create all OS Leaderboards. + =back =cut @@ -200,6 +204,7 @@ sub update_full { $self->build_data(); $self->build_matrices(); $self->build_stats(); + $self->build_leaders(); $self->{parent}->_log("finish update_full"); } @@ -227,7 +232,7 @@ sub build_matrices { my $self = shift; $self->{parent}->_log("start build_matrices"); - my $storage = $self->{parent}->storage(); + my $storage = $self->{parent}->mainstore(); if($storage && -f $storage) { $self->{parent}->_log("building dist hash from storage"); $self->storage_read($storage); @@ -251,7 +256,7 @@ sub build_stats { $self->_build_monthly_stats(); $self->{parent}->_log("stats start"); - my $storage = $self->{parent}->storage(); + my $storage = $self->{parent}->mainstore(); if($storage && -f $storage) { $self->{parent}->_log("building dist hash from storage"); $self->storage_read($storage); @@ -319,7 +324,7 @@ sub build_data { my $testers = {}; my $lastid = 0; - my $storage = $self->{parent}->storage(); + my $storage = $self->{parent}->mainstore(); if($storage && -f $storage) { $self->{parent}->_log("building dist hash from storage"); ($testers,$lastid) = $self->storage_read($storage); @@ -1213,9 +1218,9 @@ sub _build_osname_leaderboards { $self->{parent}->_log("building osname leaderboards"); # load data - my $file = 'leaderboard.json'; - if(-f $file) { - $json = read_file($file); + my $storage = $self->{parent}->leadstore(); + if($storage && -f $storage) { + $json = read_file($storage); $data = decode_json($json); } @@ -1273,10 +1278,10 @@ sub _build_osname_leaderboards { } # save data - $json = encode_json($data); - write_file($file,$json); - - $self->{parent}->_log("1.save json"); + if($storage) { + $json = encode_json($data); + write_file($storage,$json); + } # reorganise data my %hash;