browser: order features by user reach percentage
[sheet.git] / browser.plp
index 0f5b704d473a5e88a16387188b512ab37de10d3d..5afabaf08331ccb5046094d04aa3ec2f5db52aa4 100644 (file)
@@ -47,9 +47,11 @@ my $caniuse = from_json($source, {
 my %CSTATS = (
        n => 'di-b',
        y => 'di-aa',
-       a => 'di-d',
-       j => 'di-prop',
-       p => 'di-prop',
+       a     => 'di-d',
+       'a x' => 'di-d',
+       j     => 'di-prop',
+       p     => 'di-prop',
+       'p j' => 'di-prop',
        'y x' => 'di-a',
 );
 my %CSTATUS = (
@@ -68,10 +70,10 @@ if (my ($somerow) = values %{ $caniuse->{data} }) {
        }
 }
 
-my $canihas = do 'browser-usage.inc.pl';
-for ($! || $@ || ()) {
-       printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $_;
-}
+my $canihas = do 'browser-usage.inc.pl' or do {
+       printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $_
+               for $! || $@;
+};
 my $scorediv = (max(map { sum(values %$_) } values %$canihas) // 1) / 100;
 
 print '<table class="mapped">';
@@ -84,6 +86,7 @@ print '<th colspan="3">feature';
 printf '<th colspan="%d">%s',
        scalar @{ $versions{$_} }, $caniuse->{agents}->{$_}->{browser}
                for @browsers;
+print '<th>%';
 # preceding row without any colspan to work around gecko bug
 print '<tr>';
 print '<td>' x $_ for 3, (map { scalar @{ $versions{$_} } } @browsers), 1;
@@ -91,9 +94,18 @@ print "</thead>\n";
 
 sub featurescore {
        # relative amount of support for given feature
-       state $statspts = { y=>10, 'y x'=>9, a=>5, j=>2, p=>1 };
+       state $statspts = { y=>10, 'y x'=>9, a=>5, 'a x'=>5, j=>2, 'p j'=>2, p=>1 };
        my $rank = 0;
        if (my $row = shift) {
+               if ($canihas) {
+                       while (my ($browser, $versions) = each %$row) {
+                               while (my ($version, $_) = each %$versions) {
+                                       $rank += $canihas->{$browser}->{$version} * $statspts->{$_};
+                               }
+                       }
+                       return $rank;
+               }
+
                while (my ($browser, $vercols) = each %versions) {
                        my $div = 0;  # multiplier exponent (decreased to lower value)
                        my @vers = map { $row->{$browser}->{$_} } @$vercols;