2023-08-26 14:16:48 +00:00
|
|
|
use v5.32;
|
2023-08-26 14:20:14 +00:00
|
|
|
|
2023-08-26 14:16:48 +00:00
|
|
|
use HTML::TableExtract;
|
|
|
|
use File::Slurp;
|
|
|
|
use Data::Dumper;
|
|
|
|
use List::Util qw(sum);
|
|
|
|
use Text::SimpleTable::AutoWidth;
|
2023-08-26 14:20:14 +00:00
|
|
|
use WWW::Mechanize ();
|
2023-08-26 14:16:48 +00:00
|
|
|
|
2023-08-26 14:28:29 +00:00
|
|
|
use experimental qw/ signatures /;
|
|
|
|
|
2023-08-26 14:29:15 +00:00
|
|
|
unless(caller) {
|
|
|
|
my $ts = get_mersenne_results();
|
|
|
|
|
|
|
|
generate_output_table($ts)->draw;
|
|
|
|
}
|
|
|
|
|
2023-08-26 14:24:39 +00:00
|
|
|
sub get_mersenne_results() {
|
2023-08-26 14:28:29 +00:00
|
|
|
|
2023-08-26 14:24:39 +00:00
|
|
|
# log in to Mersenne.org and get results for the last year
|
|
|
|
# excluding everything but PHP and DD results
|
|
|
|
|
|
|
|
my $mech = WWW::Mechanize->new;
|
|
|
|
|
|
|
|
my $url =
|
2023-08-26 14:28:29 +00:00
|
|
|
'https://www.mersenne.org/results/?extf=1&exp1=1&execm=1&excert=1&exp_lo=2&exp_hi=&limit=10000';
|
2023-08-26 14:24:39 +00:00
|
|
|
|
|
|
|
$mech->get($url);
|
|
|
|
|
|
|
|
$mech->submit_form(
|
|
|
|
form_number => 1,
|
|
|
|
fields => {
|
|
|
|
user_login => $ENV{'MERSENNE_USER'},
|
|
|
|
user_password => $ENV{'MERSENNE_PASSWORD'},
|
|
|
|
} );
|
|
|
|
|
|
|
|
# load the results into a table object
|
|
|
|
my $html_string = $mech->content;
|
|
|
|
|
2023-08-26 16:50:17 +00:00
|
|
|
return extract_first_table($html_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub extract_first_table($html) {
|
|
|
|
$html =~ s/\n//g;
|
2023-08-26 14:24:39 +00:00
|
|
|
|
|
|
|
my $te = HTML::TableExtract->new( depth => 0, count => 2 );
|
|
|
|
|
2023-08-26 16:50:17 +00:00
|
|
|
$te->parse($html);
|
2023-08-26 14:24:39 +00:00
|
|
|
|
|
|
|
return $te->first_table_found;
|
2023-08-26 16:50:17 +00:00
|
|
|
|
2023-08-26 14:24:39 +00:00
|
|
|
}
|
|
|
|
|
2023-08-26 14:28:29 +00:00
|
|
|
sub generate_output_table ($ts) {
|
|
|
|
|
2023-08-26 14:16:48 +00:00
|
|
|
# group GHZ Days results by computer, compute GHZ Days per Day (GHZ Days / Days)
|
2023-08-26 14:28:29 +00:00
|
|
|
my $list;
|
|
|
|
|
|
|
|
foreach my $row ( $ts->rows ) {
|
|
|
|
foreach my $cell ($row) {
|
|
|
|
my $machine = @$cell[0];
|
|
|
|
my $ghz_days = @$cell[6];
|
|
|
|
$ghz_days =~ s/\s//g;
|
|
|
|
my $days = @$cell[4];
|
|
|
|
$days =~ s/\s//g;
|
|
|
|
|
|
|
|
if ( $days > 0 ) {
|
|
|
|
my $perf = $ghz_days / $days;
|
|
|
|
push( @{ $list->{$machine} }, $perf );
|
|
|
|
}
|
2023-08-26 14:19:48 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-26 14:16:48 +00:00
|
|
|
|
2023-08-26 14:28:29 +00:00
|
|
|
# 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;
|
|
|
|
}
|
2023-08-26 14:16:48 +00:00
|
|
|
|
2023-08-26 14:28:29 +00:00
|
|
|
# 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) ) {
|
|
|
|
$tbl->row( $key, $ranks{$key} );
|
|
|
|
}
|
2023-08-26 14:16:48 +00:00
|
|
|
}
|