browser: normalise score as percentage
[sheet.git] / browser.plp
index 7d78670255463e64223d93a4307474768c322f72..7e52a03bf07584a5129b5b05de7fe0a61c8aaf71 100644 (file)
@@ -43,7 +43,7 @@ my $caniuse = from_json($source, {
 
 my %CSTATS = (
        n => 'di-b',
-       y => 'di-a',
+       y => 'di-aa',
        a => 'di-d',
        j => 'di-prop',
        p => 'di-prop',
@@ -55,7 +55,7 @@ my %CSTATUS = (
        pr    => 'di-prop', # proposed
        cr    => 'di-d', # candidate
        rec   => 'di-a', # recommendation
-       ietf  => 'di-a', # standard
+       ietf  => 'di-aa', # standard
 );
 my @browsers = qw(trident gecko webkit_saf presto);
 my %versions;
@@ -80,12 +80,11 @@ print '<tr>';
 print '<td>' x $_ for 2, map { scalar @{ $versions{$_} } } @browsers;
 print "</thead>\n";
 
-sub featurerank {
+sub featurescore {
        # relative amount of support for given feature
        state $statspts = { y=>10, 'y x'=>9, a=>5, j=>2, p=>1 };
-       my ($id) = @_;
        my $rank = 0;
-       if (my $row = $caniuse->{data}->{$id}->{stats}) {
+       if (my $row = shift) {
                while (my ($browser, $vercols) = each %versions) {
                        my $div = 0;  # multiplier exponent (decreased to lower value)
                        my @vers = map { $row->{$browser}->{$_} } @$vercols;
@@ -105,7 +104,8 @@ sub featurerank {
 }
 
 for my $id (sort {
-       featurerank($b) <=> featurerank($a)
+           featurescore($caniuse->{data}->{$b}->{stats})
+       <=> featurescore($caniuse->{data}->{$a}->{stats})
 } keys %{ $caniuse->{data} }) {
        my $row = $caniuse->{data}->{$id};
        my $data = $row->{stats} or next;  # skip metadata [summary]
@@ -128,7 +128,10 @@ for my $id (sort {
                        $prev = $ver;
                }
        }
-       print '<td>', int featurerank($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 '</table>';
 
@@ -143,10 +146,11 @@ sub paddedver {
 
 <div class="legend">
        <table class="glyphs"><tr>
-       <td class="X di-a">yes
-       <td class="X di-d">almost
-       <td class="X di-prop">plugin or js
-       <td class="X di-b">no
+       <td class="X di-aa">supported
+       <td class="X di-a">prefixed
+       <td class="X di-d">partial
+       <td class="X di-prop">external (js/plugin)
+       <td class="X di-b">missing
        </table>
 
        <div class="right">