browser: source metadata in usage include
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 5 Dec 2010 18:25:22 +0000 (19:25 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 6 Dec 2010 00:04:46 +0000 (01:04 +0100)
browser.plp
tools/convert-stats-wikimedia.pl

index a4af5348dda1d039fae696f7b1d9b18bc79b3873..2de845858d4db807566c8270fde517c0fb5e346a 100644 (file)
@@ -17,8 +17,18 @@ Html({
 <h1>Browser compatibility</h1>
 
 <p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> page
 <h1>Browser compatibility</h1>
 
 <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>
+<:
+my $canihas = do 'browser-usage.inc.pl'
+       or printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $! || $@;
+
+print "with $_ browser usage statistics." for map {
+       my $ref = $_->{-source} || 'unknown';
+       $ref = sprintf '<a href="%s">%s</a>', $_, $ref for $_->{-url} || ();
+       $ref .= " $_" for $_->{-date} || ();
+       $ref
+} $canihas || ();
+:>
+</p>
 
 <div id="browser">
 <:
 
 <div id="browser">
 <:
@@ -52,24 +62,20 @@ if (my ($somerow) = values %{ $caniuse->{data} }) {
 my @browsers = grep { $versions{$_} }
        qw(trident gecko webkit_saf ios_saf webkit_chr android presto op_mob op_mini);
 
 my @browsers = grep { $versions{$_} }
        qw(trident gecko webkit_saf ios_saf webkit_chr android presto op_mob op_mini);
 
-my $canihas = do 'browser-usage.inc.pl' || do {
-       printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $_
-               for $! || $@;
-       +{
-               map {
-                       $_ => +{
-                               map {
-                                       ($_->[4] =>  0 ), # future
-                                       ($_->[3] =>  .5), # next
-                                       ($_->[0] =>  5 ), # past
-                                       ($_->[1] => 10 ), # previous
-                                       ($_->[2] => 30 ), # current
-                               } $caniuse->{agents}->{$_}->{versions}
-                       }
-               } @browsers
-       }; # fallback hash based on release semantics
-};
-my $scorediv = (max(map { sum(values %$_) } values %$canihas) // 1) / 100;
+$canihas ||= {
+       map {
+               $_ => +{
+                       map {
+                               ($_->[4] =>  0 ), # future
+                               ($_->[3] =>  .5), # next
+                               ($_->[0] =>  5 ), # past
+                               ($_->[1] => 10 ), # previous
+                               ($_->[2] => 30 ), # current
+                       } $caniuse->{agents}->{$_}->{versions}
+               }
+       } @browsers
+}; # fallback hash based on release semantics
+my $scorediv = (max(map { ref $_ eq 'HASH' && sum(values %$_) } values %$canihas) // 1) / 100;
 
 print '<table class="mapped">';
 print '<col>' x 3;
 
 print '<table class="mapped">';
 print '<col>' x 3;
index 42faf2099cc16640becb925799efffb412d08a75..5ee59ca8671df131e2ab03f8063179673b97a9ce 100644 (file)
@@ -3,6 +3,13 @@ use 5.010; use strict; use warnings;
 our %count;
 our $mobile;
 
 our %count;
 our $mobile;
 
+if (m{<td class=hl>} .. m{</?td>}) {
+       $count{-url} = 'http://stats.wikimedia.org/archive/squid_reports/';
+       $count{-source} = 'Wikimedia';
+       $count{-date} = $1 if m{ period: (?:\d+ )?(\w+ \d+) };
+       next;
+}
+
 # select relevant columns
 />Browser versions(.*)/ ... m{</table>} && last or next;
 my ($tr, $id, $count2, $count) = split /(?:<[^>]*>)+/;
 # select relevant columns
 />Browser versions(.*)/ ... m{</table>} && last or next;
 my ($tr, $id, $count2, $count) = split /(?:<[^>]*>)+/;