diff --git a/script.pl b/script.pl index a6aa4da..a40a9ed 100644 --- a/script.pl +++ b/script.pl @@ -6,11 +6,11 @@ use Data::Dumper; use Text::SimpleTable::AutoWidth; use WWW::Mechanize (); use List::AllUtils qw/ sum pairmap /; -use List::UtilsBy qw/ nsort_by /; +use List::UtilsBy qw/ nsort_by partition_by /; use experimental qw/ signatures /; -unless(caller) { +unless (caller) { my $ts = get_mersenne_results(); generate_output_table($ts)->draw; @@ -41,7 +41,7 @@ sub get_mersenne_results() { return extract_first_table($html_string); } -sub extract_first_table($html) { +sub extract_first_table ($html) { $html =~ s/\n//g; my $te = HTML::TableExtract->new( depth => 0, count => 2 ); @@ -54,36 +54,29 @@ sub extract_first_table($html) { 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 $days = $cell->[4] =~ s/\s//gr; - my $ghz_days = $cell->[6] =~ s/\s//gr; - - if ( $days > 0 ) { - my $perf = $ghz_days / $days; - push $list->{$machine}->@*, $perf; - } - } - } - - # create hash with each computer and its average GHz Days per day - my %ranks = pairmap { - $a => sprintf "%.0f", sum(@$b)/@$b; - } %$list; - - # sort hash by the average and print to screen my $tbl = Text::SimpleTable::AutoWidth->new( captions => [qw/ Computer GHZDaysPerDay /] ); - $tbl->row( @$_ ) for + # group GHZ Days results by computer, compute GHZ Days per Day (GHZ Days / Days) + $tbl->row(@$_) for reverse - nsort_by { $_->[1] } - pairmap { [$a,$b] } - %ranks; + nsort_by { $_->[1] } + pairmap { [ $a, $b ] } # group for the sorting + pairmap { $a => sprintf "%.0f", sum(@$b) / @$b } # take the mean + pairmap { + # calculate our stats + $a => [ map { $_->{ghz_days} / $_->{days} } @$b ] + } + partition_by { $_->{machine} } # group by machine + grep { $_->{days} > 0 } # skip entries with no days + map { # get the info + my $machine = $_->[0]; + my $days = $_->[4] =~ s/\s//gr; + my $ghz_days = $_->[6] =~ s/\s//gr; + + +{ days => $days, ghz_days => $ghz_days, machine => $machine } + } + $ts->rows; return $tbl; }