From 7d058f41993c955a19f1123b76938e292eee319e Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Wed, 8 Dec 2010 23:21:23 +0100 Subject: [PATCH] browser: normalise all usage percentages --- browser.plp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/browser.plp b/browser.plp index 8319624..19011ab 100644 --- a/browser.plp +++ b/browser.plp @@ -123,7 +123,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 ''; print ''; # should match first thead row @@ -141,7 +147,7 @@ my $header = join('', $_, @{ $caniuse->{agents}->{$_} }{'prefix', 'type'}, ), join(' ', - sprintf('%.1f%%', sum(values %{ $canihas->{$_} })), + sprintf('%.1f%%', sum(values %{ $canihas->{$_} }) * $usagepct), $name, ), do { @@ -159,7 +165,7 @@ print '', $header, ''; 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 +264,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 +287,7 @@ sub saybrowsercols { sub sayusagecol { my ($id) = @_; - state $maxscore = featurescore({ # yes for every possible version - map { $_ => { map {$_ => 'y'} @{$versions{$_}} } } keys %versions - }); - print ''; -- 2.30.0
' x 3; for my $browser (@browsers) { printf('%s', join(' ', - sprintf('%.1f%%', $canihas->{$browser}->{$_}), + sprintf('%.1f%%', $canihas->{$browser}->{$_} * $usagepct), "version $_", ), (map { @@ -174,7 +180,7 @@ say '
', int featurescore($caniuse->{data}->{$id}->{stats}) / $maxscore * 100; + print '', int featurescore($caniuse->{data}->{$id}->{stats}) * $usagepct; } say '