chiark / gitweb /
routetrade: include data age summary
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 18 Oct 2009 15:29:33 +0000 (16:29 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 18 Oct 2009 15:29:33 +0000 (16:29 +0100)
yarrg/web/query_age
yarrg/web/routetrade

index d9b234dd559e074353641f7c1ccd5fae7f9b4916..f9466d385f0fd5198135ef4a8e2aa7fac51c000a 100644 (file)
@@ -46,31 +46,42 @@ $dbh
 <%perl>
 my $now= time;
 
-my $row;
 my $sth= $dbh->prepare("SELECT archipelago, islandid, islandname, timestamp
                                FROM uploads NATURAL JOIN islands
-                               ORDER BY archipelago, islandid");
+                               ORDER BY archipelago, islandname");
 $sth->execute();
 
 </%perl>
 
+<& SELF:pageload &>
+<%method pageload>
 <&| script &>
   da_pageload= Date.now();
 </&script>
+</%method>
 
 <h1>Market data age</h1>
 
+<& SELF:agestable, now => $now, fetchrow => sub { $sth->fetchrow_hashref } &>
+
+<%method agestable>
+<%args>
+  $now
+  $fetchrow
+</%args>
 <table id="ts_table">
 <tr>
 <th>Archipelago
 <th>Island
 <th>Age
 </tr>
+% my $row;
 % my %da_ages;
 % my %ts_sortkeys;
 % $da_ages{'id_loaded'}= 0;
 % my $rowix= 0;
-% while ($row=$sth->fetchrow_hashref) {
+% while ($row= $fetchrow->()) {
+%      print STDERR "$row\n";
 %      my $rowid= "id_$row->{'islandid'}";
 %      my $cellid= "c$rowid";
 %      my $age= $now - $row->{'timestamp'};
@@ -84,44 +95,48 @@ $sth->execute();
 %      $rowix++;
 % }
 </table>
+<& SELF:dataages, id2age => \%da_ages,
+       jsprefix => 'dat_', elemidprefix => "'c'+" &>
+
+<&| tabsort, table => 'ts_table', rowclass => 'datarow', cols => [
+       {}, {},
+       { DoReverse => 1,
+         Numeric => 1,
+         SortKey => "da_ages[rowid]" }]
+  &>
+  ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
+</&tabsort>
+<p>
+% print $m->content();
+Time since this page loaded:
+<span id="cid_loaded">(not known; times above not updating)</span>
+
+</%method>
 
-<& SELF:dataages, id2age => \%da_ages, elemidprefix => "'c'+" &>
 <%method dataages>
 <%args>
   $id2age
   $elemidprefix => ''
+  $jsprefix => 'da_'
 </%args>
 <&| script &>
-  function da_Refresh() {
+  function <% $jsprefix %>Refresh() {
     var now= Date.now();
     debug('updating now='+now);
-    for (var ageid in da_ages) {
-      var oldage= da_ages[ageid];
+    for (var ageid in <% $jsprefix %>ages) {
+      var oldage= <% $jsprefix %>ages[ageid];
       var el= document.getElementById(<% $elemidprefix %>ageid);
       var age= oldage + (now - da_pageload) / 1000;
       var newhtml= <% meta_prettyprint_age('age','Math.floor','+') %>;
       el.innerHTML= newhtml;
     }
   }
-  da_ages= <% to_json_protecttags($id2age) %>;
-  window.setInterval(da_Refresh, 10000);
-  register_onload(da_Refresh);
+  <% $jsprefix %>ages= <% to_json_protecttags($id2age) %>;
+  window.setInterval(<% $jsprefix %>Refresh, 10000);
+  register_onload(<% $jsprefix %>Refresh);
 </&>
 </%method>
 
-<&| tabsort, table => 'ts_table', rowclass => 'datarow', cols => [
-       {}, {},
-       { DoReverse => 1,
-         Numeric => 1,
-         SortKey => "da_ages[rowid]" }]
-  &>
-  ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
-</&tabsort>
-
-<p>
-Time since this page loaded:
-<span id="cid_loaded">(not known; times above not updating)</span>
-
 <form action="lookup" method="get">
 <input type=submit name=submit value="Reload">
 <& "lookup:formhidden", ours => sub { 0; } &>
index 61484391130a9341b3b90d099c4b2889f27d0619..c6ed408d80fe9d779e54de724856c6abf02ab673 100644 (file)
@@ -40,9 +40,7 @@ $dbh
 $qa
 $routeparams
 </%args>
-<&| script &>
-  da_pageload= Date.now();
-</&script>
+<& query_age:pageload &>
 
 <%perl>
 
@@ -595,6 +593,7 @@ $addcols->({ Total => 0, DoReverse => 1, TotalSubflows => 1 }, qw(
    <li><a href="#summary">Summary statistics</a>
   </ul>
 % }
+ <li><a href="#dataage">Data age summary</a>
  <li><a href="#trades">Relevant trades</a>
 </ul>
 
@@ -782,6 +781,52 @@ Expected average profit:
 %
 % } # ========== TRADING PLAN ==========
 
+% {
+<h2><a name="dataage">Data age summary</a></h2>
+<%perl>
+       my $sth_i= $dbh->prepare(<<END);
+               SELECT archipelago, islandid, islandname, timestamp
+                       FROM uploads NATURAL JOIN islands
+                       WHERE islandid = ?
+END
+       my $sth_a= $dbh->prepare(<<END);
+               SELECT archipelago, islandid, islandname, timestamp
+                       FROM uploads NATURAL JOIN islands
+                       WHERE archipelago = ?
+                       ORDER BY islandname
+END
+       my $ix=$#islandids;
+       my $sth_current;
+       my %idone;
+       my $fetchrow= sub {
+               for (;;) {
+                       if ($sth_current) {
+                               my $row= $sth_current->fetchrow_hashref();
+                               if ($row) {
+                                       next if $idone{$row->{'islandid'}}++;
+                                       return $row;
+                               }
+                       }
+                       return undef if $ix < 0;
+                       my $iid= $islandids[$ix];
+                       if (defined $iid) {
+                               $sth_i->execute($iid);
+                               $sth_current= $sth_i;
+                       } else {
+                               my $arch= $archipelagoes[$ix];
+                               die unless defined $arch && length $arch;
+                               $sth_a->execute($arch);
+                               $sth_current= $sth_a;
+                       }
+                       $ix--;
+               }
+       };
+</%perl>
+<&| query_age:agestable, now => $now, fetchrow => $fetchrow &>
+Islands shown in reverse order of visits.<br>
+</&>
+% }
+
 % my %ts_sortkeys;
 % {
 %      my $cdspan= $qa->{ShowStalls} ? ' colspan=2' : '';