<h1>Market data age</h1>
-<table>
+<table id="ts_table">
<tr>
<th>Archipelago
<th>Island
<th>Age
</tr>
% my %da_ages;
-% $da_ages{'daid_loaded'}= 0;
+% my %ts_sortkeys;
+% $da_ages{'id_loaded'}= 0;
% while ($row=$sth->fetchrow_hashref) {
-% my $elid= "daid_$row->{'islandid'}";
+% my $rowid= "id_$row->{'islandid'}";
+% my $cellid= "c$rowid";
% my $age= $now - $row->{'timestamp'};
-% $da_ages{$elid}= $age;
-<tr> <td><% $row->{'archipelago'} |h
- %> <td><% $row->{'islandname'} |h
- %> <td id="<% $elid %>"><% $prettyprint_age->($age) %> </tr>
+% $ts_sortkeys{'0'}{$rowid}= $row->{'archipelago'};
+% $ts_sortkeys{'1'}{$rowid}= $row->{'islandname'};
+% $da_ages{$rowid}= $age;
+<tr id=<% $rowid %>
+ > <td><% $row->{'archipelago'} |h
+ %> <td><% $row->{'islandname'} |h
+ %> <td id="<% $cellid %>"><% $prettyprint_age->($age) %> </tr>
% }
</table>
+<& tabsort, table => 'ts_table', cols => [
+ {}, {},
+ { DoReverse => 1,
+ Numeric => 1,
+ SortKey => "da_ages[rowid]" }]
+ &>
+
<p>
Time since this page loaded:
-<span id="daid_loaded">(not known; times above not updating)</span>
+<span id="cid_loaded">(not known; times above not updating)</span>
<form action="lookup" method="get">
<input type=submit name=submit value="Reload">
</form>
<&| script &>
+ ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
da_ages= <% to_json_protecttags(\%da_ages) %>;
function da_Refresh() {
var now= Date.now();
debug('updating now='+now);
- for (var elid in da_ages) {
- var el= document.getElementById(elid);
- var oldage= da_ages[elid];
+ for (var rowid in da_ages) {
+ var oldage= da_ages[rowid];
+ var cellid= 'c'+rowid;
+ var el= document.getElementById(cellid);
var age= oldage + (now - da_pageload) / 1000;
- var newhtml= <% $meta_prettyprint_age->('age','Math.floor','+') %>
+ var newhtml= <% $meta_prettyprint_age->('age','Math.floor','+') %>;
% if ($ARGS{debug}) {
- if (elid == 'daid_loaded')
- debug('element elid='+elid+' oldage='+oldage+' age='+age+': '+newhtml);
+ if (cellid == 'cid_loaded')
+ debug('element rowid='+rowid+' cellid='+cellid
+ +' oldage='+oldage+' age='+age+': '+newhtml);
% }
el.innerHTML= newhtml;
}
}
- window.onload= da_Refresh;
+ function all_onload() {
+ ts_onload__ts_table();
+ da_Refresh();
+ }
+ window.onload= all_onload;
window.setInterval(da_Refresh, 10000);
</&script>