using nsort_by

This commit is contained in:
Yanick Champoux 2023-08-26 11:22:19 -04:00
parent 890f6be36b
commit 58de849fa2

View File

@ -3,9 +3,10 @@ use v5.32;
use HTML::TableExtract; use HTML::TableExtract;
use File::Slurp; use File::Slurp;
use Data::Dumper; use Data::Dumper;
use List::Util qw(sum);
use Text::SimpleTable::AutoWidth; use Text::SimpleTable::AutoWidth;
use WWW::Mechanize (); use WWW::Mechanize ();
use List::AllUtils qw/ sum pairmap /;
use List::UtilsBy qw/ nsort_by /;
use experimental qw/ signatures /; 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 # create hash with each comptuer and its average GHz Days per day
my %ranks; my %ranks = pairmap {
foreach my $key ( keys %$list ) { my $mean = sum( @$b ) / @$b;
my $mean = sum( @{ $list->{$key} } ) / @{ $list->{$key} };
my $rounded = int( $mean + 0.5 ); my $rounded = int( $mean + 0.5 );
$ranks{$key} = $rounded; $a => $rounded;
} } %$list;
# sort hash by the average and print to screen # sort hash by the average and print to screen
my $tbl = Text::SimpleTable::AutoWidth->new( my $tbl = Text::SimpleTable::AutoWidth->new(
captions => [qw/ Computer GHZDaysPerDay /] ); captions => [qw/ Computer GHZDaysPerDay /] );
foreach $tbl->row( @$_ ) for
my $key ( reverse sort { $ranks{$a} <=> $ranks{$b} } keys(%ranks) ) { reverse
$tbl->row( $key, $ranks{$key} ); nsort_by { $_->[1] }
} pairmap { [$a,$b] }
%ranks;
return $tbl; return $tbl;
} }