browser: precalculate row usage values
[sheet.git] / browser.plp
index a53f0457bc6e27688ff7c7c9637087d2b3ed6b47..a101d741e4fb2071e0499b9cd65b9c85601cae90 100644 (file)
@@ -196,13 +196,14 @@ $canihas ||= {
                }
        } @browsers
 }; # fallback hash based on release semantics
-my $usagemax = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100;
 
 my $usagepct = 1;  # score multiplier for 0..100 result
 # normalise usage percentage to only include shown browsers
 $usagepct = 100.01 / featurescore({  # yes for every possible version
        map { $_ => { map {$_ => 'y'} map { @{$_} } @{$versions{$_}} } } keys %versions
 });
+$_->{usage} = featurescore($_->{stats}) * $usagepct
+       for values %{ $caniuse->{data} };
 
 print '<table class="mapped">';
 print '<col span="3">';  # should match first thead row
@@ -415,7 +416,6 @@ sub saybrowsercols {
                                                sprintf('p%01d', $usage * ($usagepct - .0001) / 10),
                                                sprintf('p%02d', $usage * ($usagepct - .0001)),
                                        ),
-                                       sprintf('pp%02d', $usage / $usagemax),
                                ),
                                scalar @span,
                                $title,
@@ -431,13 +431,12 @@ sub saybrowsercols {
 
 sub sayusagecol {
        my ($id) = @_;
-       print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) * $usagepct;
+       print '<td>', int $caniuse->{data}->{$id}->{usage};
 }
 
 say '<tbody>';
 for my $id (sort {
-           featurescore($caniuse->{data}->{$b}->{stats})
-       <=> featurescore($caniuse->{data}->{$a}->{stats})
+       $caniuse->{data}->{$b}->{usage} <=> $caniuse->{data}->{$a}->{usage}
 } keys %{ $caniuse->{data} }) {
        $caniuse->{data}->{$id}->{stats} or next;  # skip metadata [summary]
        printf '<tr id="%s">', $id;