chiark / gitweb /
Fix up search too long error message - put maxcpu back!
[ypp-sc-tools.db-live.git] / yarrg / web / query_age
1 <%doc>
2
3  This is part of the YARRG website.  YARRG is a tool and website
4  for assisting players of Yohoho Puzzle Pirates.
5
6  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
7  Copyright (C) 2009 Clare Boothby
8
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
12    download the source.
13
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.
18
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.
23
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/>.
26
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.
30
31
32  This Mason component generates the core of the `data age' query.
33
34
35 </%doc>
36
37 <%args>
38 $quri
39 $dbh
40 </%args>
41
42 <%once>
43
44 </%once>
45
46 <%perl>
47 my $now= time;
48
49 my $sth= $dbh->prepare("SELECT archipelago, islandid, islandname, timestamp
50                                 FROM uploads NATURAL JOIN islands
51                                 ORDER BY archipelago, islandname");
52 $sth->execute();
53
54 </%perl>
55 <div class="results">
56
57 <& SELF:pageload &>
58 <%method pageload>
59 <&| script &>
60   da_pageload= Date.now();
61 </&script>
62 </%method>
63
64 <h1>Market data age</h1>
65
66 <& SELF:agestable, now => $now, fetchrow => sub { $sth->fetchrow_hashref } &>
67
68 <%method agestable>
69 <%args>
70   $now
71   $fetchrow
72 </%args>
73 <table class="data" id="ts_table" rules="groups">
74 <tr>
75 <th>Archipelago
76 <th>Island
77 <th>Age
78 % my $row;
79 % my %da_ages;
80 % my %ts_sortkeys;
81 % $da_ages{'id_loaded'}= 0;
82 % my $rowix= 0;
83 % while ($row= $fetchrow->()) {
84 %       my $rowid= "id_$row->{'islandid'}";
85 %       my $cellid= "c$rowid";
86 %       my $age= $now - $row->{'timestamp'};
87 %       $ts_sortkeys{'0'}{$rowid}= $row->{'archipelago'};
88 %       $ts_sortkeys{'1'}{$rowid}= $row->{'islandname'};
89 %       $da_ages{$rowid}= $age;
90 <tr id=<% $rowid %> class="<% 'datarow'.($rowix & 1) %>"
91    > <td><% $row->{'archipelago'} |h
92   %> <td><% $row->{'islandname'} |h
93   %> <td id="<% $cellid %>" align=right><% prettyprint_age($age) %> </tr>
94 %       $rowix++;
95 % }
96 </table>
97 <& SELF:dataages, id2age => \%da_ages,
98         jsprefix => 'dat_', elemidprefix => "'c'+" &>
99
100 <&| tabsort, table => 'ts_table', rowclass => 'datarow', cols => [
101         {}, {},
102         { DoReverse => 1,
103           Numeric => 1,
104           SortKey => "dat_ages[rowid]" }]
105   &>
106   ts_sortkeys= <% to_json_protecttags(\%ts_sortkeys) %>;
107 </&tabsort>
108 <p>
109 % print $m->content();
110 Time since this page loaded:
111 <span id="cid_loaded">(not known; times above not updating)</span>
112
113 </%method>
114
115 <%method dataages>
116 <%args>
117   $id2age
118   $elemidprefix => ''
119   $jsprefix => 'da_'
120 </%args>
121 <&| script &>
122   function <% $jsprefix %>Refresh() {
123     var now= Date.now();
124     debug('updating now='+now);
125     for (var ageid in <% $jsprefix %>ages) {
126       if (!<% $jsprefix %>ages.hasOwnProperty(ageid)) continue;
127       var oldage= <% $jsprefix %>ages[ageid];
128       var el= document.getElementById(<% $elemidprefix %>ageid);
129       var age= oldage + (now - da_pageload) / 1000;
130       var newhtml= <% meta_prettyprint_age('age','Math.floor','+') %>;
131       el.innerHTML= newhtml;
132     }
133   }
134   <% $jsprefix %>ages= <% to_json_protecttags($id2age) %>;
135   window.setInterval(<% $jsprefix %>Refresh, 10000);
136   register_onload(<% $jsprefix %>Refresh);
137 </&>
138 </%method>
139
140 <form action="lookup" method="get">
141 <input type=submit name=submit value="Reload">
142 <& "lookup:formhidden", ours => sub { 0; } &>
143 </form>
144
145 </div>
146 <%init>
147 use POSIX;
148 use CommodsWeb;
149 </%init>