caniuse: recognise missing support combinations
[sheet.git] / browser.plp
index bbf2d6bb9288b0e98d0fb0af8cb1cc2c13830e95..e82e69e4130f4a9228589e48133761fc86782e72 100644 (file)
@@ -1,5 +1,6 @@
 <(common.inc.plp)><:
 use 5.010;
+use List::Util qw(sum max);
 
 Html({
        title => 'browser compatibility cheat sheet',
@@ -14,7 +15,9 @@ Html({
 :>
 <h1>Browser compatibility</h1>
 
-<p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> site.</p>
+<p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> page
+with <a href="http://stats.wikimedia.org/archive/squid_reports/">Wikimedia</a>
+browser usage statistics.</p>
 
 <:
 use JSON;
@@ -44,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 = (
@@ -65,6 +70,12 @@ if (my ($somerow) = values %{ $caniuse->{data} }) {
        }
 }
 
+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">';
 print '<col>' x 3;
 printf '<colgroup span="%d">', scalar @{ $versions{$_} } for @browsers;
@@ -82,7 +93,7 @@ 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) {
                while (my ($browser, $vercols) = each %versions) {
@@ -126,9 +137,14 @@ for my $id (sort {
                for my $ver (@{ $versions{$browser} }, undef) {
                        unless (!defined $prev
                        or $data->{$browser}->{$prev} ~~ $data->{$browser}->{$ver}) {
-                               printf '<td class="%s" colspan="%d">%s',
-                                       $CSTATS{ $data->{$browser}->{$prev} },
+                               my $usage = sum(map { $canihas->{$browser}->{$_} } @span);
+                               printf '<td class="%s" colspan="%d" title="%.1f%%">%s',
+                                       join(' ',
+                                               $CSTATS{ $data->{$browser}->{$prev} },
+                                               sprintf('opacity%.0f', $usage / $scorediv),
+                                       ),
                                        scalar @span,
+                                       $usage,
                                        showversions(\@span),
                                undef $prev;
                                @span = ();