index: list latest git commits
[sheet.git] / browser.plp
index 831962492a300d14ea3982ac67e31028d0bb42ca..aaafa038cafb70129c858b60ab5f4f819ce43186 100644 (file)
@@ -99,9 +99,10 @@ if ($usage) {
                $row->{$_} //= undef for @$verlist;  # ensure stable keys during iteration
                while (my ($version, $usage) = each %$row) {
                        next if defined $supported{$version};
-                       $_ = paddedver($_) for $version;
-                       my $next = first { paddedver($_) ge $version } @$verlist; # or next
+                       my $next = first { paddedver($_) ge paddedver($version) } @$verlist
+                               or warn("No fallback found for $browser v$version; $usage% ignored"), next;
                        $row->{$next} += $usage;
+                       $row->{$version} = 0;  # balance browser total
                }
        }
 }
@@ -123,7 +124,13 @@ $canihas ||= {
                }
        } @browsers
 }; # fallback hash based on release semantics
-my $scorediv = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100;
+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 / featurescore({  # yes for every possible version
+       map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
+});
 
 print '<table class="mapped">';
 print '<col span="3">';  # should match first thead row
@@ -141,7 +148,7 @@ my $header = join('',
                                $_, @{ $caniuse->{agents}->{$_} }{'prefix', 'type'},
                        ),
                        join(' ',
-                               sprintf('%.1f%%', sum(values %{ $canihas->{$_} })),
+                               sprintf('%.1f%%', sum(values %{ $canihas->{$_} }) * $usagepct),
                                $name,
                        ),
                        do {
@@ -157,16 +164,19 @@ print '<thead>', $header;
 print "\n<tr>";
 print '<td>' x 3;
 for my $browser (@browsers) {
-       printf('<td title="%s"%s>%s',
-               join(' ',
-                       sprintf('%.1f%%', $canihas->{$browser}->{$_}),
-                       "version $_",
-               ),
-               (map {
-                       defined $_ && !$_ && ' class="ex"'
-               } $caniuse->{agents}->{$browser}->{verrelease}->{$_}),
-               showversions($_),
-       ) for @{ $versions{$browser} };
+       for my $_ (@{ $versions{$browser} }) {
+               my $release = $caniuse->{agents}->{$browser}->{verrelease}->{$_};
+               my $future = defined $release;
+               printf('<td title="%s"%s>%s',
+                       join(' ',
+                               sprintf('%.1f%%', $canihas->{$browser}->{$_} * $usagepct),
+                               $future ? 'development' : (),
+                               "version $_",
+                       ),
+                       $future && ' class="ex"',
+                       showversions($_),
+               );
+       }
 }
 print '<td>' x 1;
 say '</thead>';
@@ -174,7 +184,7 @@ say '<tfoot>', $header, '</tfoot>';
 
 sub featurescore {
        # relative amount of support for given feature
-       state $statspts = { y=>10, 'y x'=>10, a=>5, 'a x'=>5, j=>2, 'p j'=>2, 'p p'=>2, p=>1 };
+       state $statspts = { y=>1, 'y x'=>1, a=>.5, 'a x'=>.5, j=>.2, 'p j'=>.2, 'p p'=>.2, p=>.1 };
        my $rank = 0;
        if (my $row = shift) {
                if ($canihas) {
@@ -258,13 +268,13 @@ sub saybrowsercols {
                                join(' ',
                                        X => $CSTATS{ ref $data eq 'HASH' && $data->{$prev} || 'u' },
                                        !$usage ? ('p0') : ('p',
-                                               sprintf('p%01d', $usage / 10),
-                                               sprintf('p%02d', $usage),
+                                               sprintf('p%01d', $usage * ($usagepct - .0001) / 10),
+                                               sprintf('p%02d', $usage * ($usagepct - .0001)),
                                        ),
-                                       sprintf('pp%02d', $usage / $scorediv),
+                                       sprintf('pp%02d', $usage / $usagemax),
                                ),
                                scalar @span,
-                               sprintf('%.1f%% %s', $usage, join(', ',
+                               sprintf('%.1f%% %s', $usage * $usagepct, join(', ',
                                        map { ref $_ eq 'CODE' ? $_->($browser) : $_ }
                                        map { $DSTATS{$_} // () }
                                        map { split / /, $_ }
@@ -281,10 +291,7 @@ sub saybrowsercols {
 
 sub sayusagecol {
        my ($id) = @_;
-       state $maxscore = featurescore({  # yes for every possible version
-               map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions
-       });
-       print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100;
+       print '<td>', int featurescore($caniuse->{data}->{$id}->{stats}) * $usagepct;
 }
 
 say '<tbody>';
@@ -322,10 +329,11 @@ sub paddedver {
 
 sub showversions {
        my @span = ($_[0], @_>1 ? $_[-1] : ());
+       s/-.*// for $span[0];
        for (@span) {
                s/^\./0./;
                s/x$/.*/;
-               s/-.*//;
+               s/.*-//;
        }
        return join('‒', @span);
 }