CPAN-Testers-WWW-Statistics
view release on metacpan or search on metacpan
lib/CPAN/Testers/WWW/Statistics/Leaderboard.pm view on Meta::CPAN
my %hash = @_;
die "Must specify the parent statistics object\n" unless(defined $hash{parent});
my $self = {parent => $hash{parent}};
bless $self, $class;
return $self;
}
=head2 Public Methods
=over 4
=item * renew
Renew all OS counts for all month entries.
=item * update
Update all OS counts for the last 3 months.
=item * postdate
Update all OS counts for the specified month.
=item * check
Verify monthy counts with source table to ensure all OS counts have been
appropriately applied.
=item * results
Provides the data as a hash for the required months, with the OS and tester
names as subsidary keys.
Note that month '999999' is a special case, and is an accumulation of all other
months, from those requested. Thus if only '999999' is requested the top level
hash return will only consist of one date, and will be a sum of all months.
=back
=cut
sub renew {
my $self = shift;
$self->{parent}->_log("START renew");
$self->_update( 'SELECT distinct(postdate) as postdate FROM cpanstats' );
$self->{parent}->_log("STOP renew");
}
sub postdate {
my ($self,$date) = @_;
$self->{parent}->_log("START postdate = $date");
$self->_update( "SELECT '$date' as postdate" );
$self->{parent}->_log("STOP postdate");
}
sub update {
my $self = shift;
$self->{parent}->_log("START update");
$self->_update( 'SELECT distinct(postdate) as postdate FROM cpanstats ORDER BY postdate DESC LIMIT 3' );
$self->{parent}->_log("STOP update");
}
sub check {
my $self = shift;
my $sql1 =
'SELECT postdate,COUNT(id) AS qty FROM cpanstats '.
'WHERE type=2 '.
'GROUP BY postdate';
my $sql2 =
'SELECT postdate,SUM(score) AS qty FROM leaderboard '.
'GROUP BY postdate '.
'ORDER BY postdate';
my %hash;
my @rows = $self->{parent}->{CPANSTATS}->get_query('hash',$sql1);
for my $row (@rows) {
$hash{ $row->{postdate} } = $row->{qty};
}
my %data;
@rows = $self->{parent}->{CPANSTATS}->get_query('hash',$sql2);
for my $row (@rows) {
next if($hash{ $row->{postdate} } == $row->{qty});
my $str = sprintf "%s, %d, %d", $row->{postdate}, $hash{ $row->{postdate} }, $row->{qty};
$self->{parent}->_log($str);
$data{$row->{postdate}}{cpanstats} = $hash{ $row->{postdate} };
$data{$row->{postdate}}{leaderboard} = $row->{qty};
}
return \%data;
}
sub results {
my $self = shift;
my %dates = map {$_ => 1} @{ shift() };
my $sql1 = q{SELECT * FROM leaderboard ORDER BY postdate,osname};
# my $sql1 = q{
# SELECT l.*, p.name, p.pause
# FROM leaderboard l
# LEFT JOIN testers.profile p ON p.testerid=l.testerid
# ORDER BY postdate,osname
# };
my %hash;
my @rows = $self->{parent}->{CPANSTATS}->get_query('hash',$sql1);
for my $row (@rows) {
my $tester = $self->{parent}->tester_lookup($row->{addressid},$row->{testerid});
$tester ||= $row->{tester};
if($dates{ $row->{postdate} }) {
$hash{ $row->{postdate} }{$row->{osname}}{$tester} = $row->{score};
} elsif($dates{ '999999' }) {
( run in 0.679 second using v1.01-cache-2.11-cpan-5735350b133 )