encapsulate reporting in its how function too

This commit is contained in:
Yanick Champoux 2023-08-26 10:28:29 -04:00
parent 0c3f6949fa
commit 40407e9604

View File

@ -7,7 +7,10 @@ use List::Util qw(sum);
use Text::SimpleTable::AutoWidth;
use WWW::Mechanize ();
use experimental qw/ signatures /;
sub get_mersenne_results() {
# log in to Mersenne.org and get results for the last year
# excluding everything but PHP and DD results
@ -39,10 +42,14 @@ sub get_mersenne_results() {
my $ts = get_mersenne_results();
# group GHZ Days results by computer, compute GHZ Days per Day (GHZ Days / Days)
my $list;
generate_output_table($ts)->draw;
foreach my $row ( $ts->rows ) {
sub generate_output_table ($ts) {
# group GHZ Days results by computer, compute GHZ Days per Day (GHZ Days / Days)
my $list;
foreach my $row ( $ts->rows ) {
foreach my $cell ($row) {
my $machine = @$cell[0];
my $ghz_days = @$cell[6];
@ -55,22 +62,21 @@ foreach my $row ( $ts->rows ) {
push( @{ $list->{$machine} }, $perf );
}
}
}
}
# create hash with each comptuer and its average GHz Days per day
my %ranks;
foreach my $key ( keys %$list ) {
# create hash with each comptuer and its average GHz Days per day
my %ranks;
foreach my $key ( keys %$list ) {
my $mean = sum( @{ $list->{$key} } ) / @{ $list->{$key} };
my $rounded = int( $mean + 0.5 );
$ranks{$key} = $rounded;
}
}
# sort hash by the average and print to screen
my $tbl =
Text::SimpleTable::AutoWidth->new(
# sort hash by the average and print to screen
return Text::SimpleTable::AutoWidth->new(
captions => [qw/ Computer GHZDaysPerDay /] );
foreach my $key ( reverse sort { $ranks{$a} <=> $ranks{$b} } keys(%ranks) ) {
foreach
my $key ( reverse sort { $ranks{$a} <=> $ranks{$b} } keys(%ranks) ) {
$tbl->row( $key, $ranks{$key} );
}
}
say $tbl->draw();