using nsort_by
This commit is contained in:
parent
890f6be36b
commit
58de849fa2
21
script.pl
21
script.pl
@ -3,9 +3,10 @@ use v5.32;
|
||||
use HTML::TableExtract;
|
||||
use File::Slurp;
|
||||
use Data::Dumper;
|
||||
use List::Util qw(sum);
|
||||
use Text::SimpleTable::AutoWidth;
|
||||
use WWW::Mechanize ();
|
||||
use List::AllUtils qw/ sum pairmap /;
|
||||
use List::UtilsBy qw/ nsort_by /;
|
||||
|
||||
use experimental qw/ signatures /;
|
||||
|
||||
@ -70,21 +71,21 @@ sub generate_output_table ($ts) {
|
||||
}
|
||||
|
||||
# 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 %ranks = pairmap {
|
||||
my $mean = sum( @$b ) / @$b;
|
||||
my $rounded = int( $mean + 0.5 );
|
||||
$ranks{$key} = $rounded;
|
||||
}
|
||||
$a => $rounded;
|
||||
} %$list;
|
||||
|
||||
# sort hash by the average and print to screen
|
||||
my $tbl = Text::SimpleTable::AutoWidth->new(
|
||||
captions => [qw/ Computer GHZDaysPerDay /] );
|
||||
|
||||
foreach
|
||||
my $key ( reverse sort { $ranks{$a} <=> $ranks{$b} } keys(%ranks) ) {
|
||||
$tbl->row( $key, $ranks{$key} );
|
||||
}
|
||||
$tbl->row( @$_ ) for
|
||||
reverse
|
||||
nsort_by { $_->[1] }
|
||||
pairmap { [$a,$b] }
|
||||
%ranks;
|
||||
|
||||
return $tbl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user