3 This is part of the YARRG website. YARRG is a tool and website
4 for assisting players of Yohoho Puzzle Pirates.
6 Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7 Copyright (C) 2009 Clare Boothby
9 YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
10 The YARRG website is covered by the GNU Affero GPL v3 or later, which
11 basically means that every installation of the website will let you
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU Affero General Public License as
16 published by the Free Software Foundation, either version 3 of the
17 License, or (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU Affero General Public License for more details.
24 You should have received a copy of the GNU Affero General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
28 are used without permission. This program is not endorsed or
29 sponsored by Three Rings.
32 This Mason component generates the core of the `data age' query.
43 my $meta_prettyprint_age= sub {
44 my ($age,$floor,$plus) = @_;
46 $age < 60 ? 'less than a minute' :
47 $age < 60*2 ? '1 minute' :
48 $age < 3600*2 ? $floor ($age/60) $plus' minutes' :
49 $age < 86400*2 ? $floor ($age/3600) $plus ' hours' :
50 $floor ($age/86400) $plus ' days';
56 $prettyprint_age= sub {
58 '.$meta_prettyprint_age->('$age','floor','.').'
68 my $sth= $dbh->prepare("SELECT archipelago, islandid, islandname, timestamp
69 FROM uploads NATURAL JOIN islands
70 ORDER BY archipelago, islandid");
76 da_pageload= Date.now();
79 <h1>Market data age</h1>
89 % $da_ages{'id_loaded'}= 0;
90 % while ($row=$sth->fetchrow_hashref) {
91 % my $rowid= "id_$row->{'islandid'}";
92 % my $cellid= "c$rowid";
93 % my $age= $now - $row->{'timestamp'};
94 % $ts_sortkeys{'0'}{$rowid}= $row->{'archipelago'};
95 % $ts_sortkeys{'1'}{$rowid}= $row->{'islandname'};
96 % $da_ages{$rowid}= $age;
98 > <td><% $row->{'archipelago'} |h
99 %> <td><% $row->{'islandname'} |h
100 %> <td id="<% $cellid %>"><% $prettyprint_age->($age) %> </tr>
104 <& tabsort, table => 'ts_table', cols => [
108 SortKey => "da_ages[rowid]" }]
112 Time since this page loaded:
113 <span id="cid_loaded">(not known; times above not updating)</span>
115 <form action="lookup" method="get">
116 <input type=submit name=submit value="Reload">
117 <& "lookup:formhidden", ours => sub { 0; } &>
121 ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
122 da_ages= <% to_json_protecttags(\%da_ages) %>;
124 function da_Refresh() {
126 debug('updating now='+now);
127 for (var rowid in da_ages) {
128 var oldage= da_ages[rowid];
129 var cellid= 'c'+rowid;
130 var el= document.getElementById(cellid);
131 var age= oldage + (now - da_pageload) / 1000;
132 var newhtml= <% $meta_prettyprint_age->('age','Math.floor','+') %>;
133 % if ($ARGS{debug}) {
134 if (cellid == 'cid_loaded')
135 debug('element rowid='+rowid+' cellid='+cellid
136 +' oldage='+oldage+' age='+age+': '+newhtml);
138 el.innerHTML= newhtml;
142 function all_onload() {
143 ts_onload__ts_table();
146 window.onload= all_onload;
147 window.setInterval(da_Refresh, 10000);