source: subversion/applications/rendering/history/index.cgi @ 34655

Last change on this file since 34655 was 3500, checked in by frederik, 12 years ago

add loop

  • Property svn:executable set to *
File size: 10.9 KB
Line 
1#!/usr/bin/perl
2
3use CGI qw(escapeHTML);
4use URI::Escape;
5use DBI;
6use strict;
7
8
9my $cgi = CGI->new();
10my $values = 'label,user,minlat,minlon,maxlat,maxlon,projection,bgimage,width,height,pixel,color,fromdate,todate,frequency,delay,loopflag';
11
12
13print <<EOF;
14Content-type: text/html
15
16<html><head><title>OSM History</title></head><body>
17EOF
18
19my $bg="#cccccc";
20
21if ((!defined($cgi->param("label")) && !defined($cgi->param("show")) && !defined($cgi->param("retry"))) || defined($cgi->param("form")))
22{
23print <<EOF;
24<h1>OSM History</h1>
25
26<strong>Displaying Historic OpenStreetMap Coverage</strong>
27<p>
28The history service creates animated GIF images that depict how OSM coverage of an area
29has changed over time. It does so by painting a dot on a map for each node, using old planet
30files for past data. (It doesn't draw lines for segments and ways, which means that zoomed-in
31inner city views look a bit thin sometimes.) You can control some aspects of image generation,
32like the background image to be used or what time range you want depicted.
33</p>
34<p>
35Computation is too time-consuming to offer this as a live service, but you can request images
36to be created and then view or download them once they are ready (the list below should give
37an indication how many requests are waiting and also how long other requests took to complete).
38</p>
39<p>
40You can browse past results below. If you request a new image, it will show up in the list
41after some time. This service is mainly intended for people to generate images, then
42download and use them e.g. in presentations. I will probably delete old images from this
43server from time to time.
44</p>
45
46<form method="post">
47<table>
48<tr valign="top">
49<td bgcolor="$bg" colspan="3">
50<b>Fill out this form to request an animated GIF image to be rendered:</b><br />&nbsp;
51</td>
52</tr>
53
54<tr valign="top">
55<td bgcolor="$bg">Identification</td>
56<td>&nbsp;</td>
57<td><table cellspacing="0" cellpadding="0">
58    <tr><td>Your Name:&nbsp;</td><td>
59EOF
60    print $cgi->textfield("user", "", 21, 20);
61    print "</td></tr><tr><td>Image Name:&nbsp;</td><td>";
62    print $cgi->textfield("label", "", 51, 50);
63
64print <<EOF;
65    </td></tr></table>
66    <font size="-1"><em>This is just so that you (and others) can recognize the image later. You can
67    put any user name, it is not checked against a list.</em></font>
68</td></tr>
69
70<tr valign="top">
71<td bgcolor="$bg">Bounding Box</td>
72<td>&nbsp;</td>
73<td><table border="0" cellpadding="0" cellspacing="0">
74<tr>
75EOF
76    print $cgi->td("min. lat &nbsp;").$cgi->td($cgi->textfield("minlat", "", 10, 11));
77    print $cgi->td("min. lon &nbsp;").$cgi->td($cgi->textfield("minlon", "", 10, 11));
78    print "</tr><tr>";
79    print $cgi->td("max. lat &nbsp;").$cgi->td($cgi->textfield("maxlat", "", 10, 11));
80    print $cgi->td("max. lon &nbsp;").$cgi->td($cgi->textfield("maxlon", "", 10, 11));
81print <<EOF;
82    </table>
83</td></tr>
84
85<tr valign="top">
86<td bgcolor="$bg">Projection</td>
87<td>&nbsp;</td>
88<td>
89EOF
90
91print $cgi->popup_menu(
92    "projection", 
93    [1, 2], 
94    1, 
95    { 1=> "lat/lon (EPSG:4326)", 2=>"Mercator" }
96);
97
98print <<EOF;
99    <br />
100    <font size="-1"><em>(using Mercator for large areas doesn't work well with background images)</em></font>
101</td></tr>
102
103<tr valign="top">
104<td bgcolor="$bg">Background</td>
105<td>&nbsp;</td>
106<td>
107EOF
108
109print $cgi->popup_menu(
110    "bgimage", 
111    [0, 1, 2], 
112    2, 
113    { 0 => "empty", 1 => "Metacarta vmap0", 2 => "Landsat" }
114);
115
116print <<EOF;
117</td></tr>
118
119<tr valign="top">
120<td bgcolor="$bg">GIF size</td>
121<td>&nbsp;</td>
122<td>width:
123EOF
124
125print $cgi->textfield("width", "640", 6, 5);
126print " OR height: ";
127print $cgi->textfield("height", "", 6, 5);
128
129print <<EOF;
130    <br />
131    <font size="-1"><em>(other dimension results from bounding box and projection data)</em></font>
132</td></tr>
133
134<tr valign="top">
135<td bgcolor="$bg">OSM Nodes</td>
136<td>&nbsp;</td>
137<td>
138EOF
139print $cgi->popup_menu(
140    "pixel", 
141    [0, 1, 2, 3], 
142    1, 
143    { 0 => "drawn as pixels", 1 => "drawn as 2x2 rectangles", 2 => "drawn as 3x3 rectangles", 3 => "drawn as 5x5 circles" }
144);
145
146print $cgi->popup_menu(
147    "color", 
148    [0, 1, 2, 3], 
149    0, 
150    { 0 => "in red", 1 => "in yellow", 2 => "in white", 3 => "in blue" }
151);
152
153print <<EOF;
154</td></tr>
155
156<tr valign="top">
157<td bgcolor="$bg">Date Range</td>
158<td>&nbsp;</td>
159<td>from
160EOF
161
162print $cgi->popup_menu(
163    "fromdate", 
164    [0, 60701, 70101, 70701],
165    0, 
166    { 0 => "earliest", 60701=> "2006-07", 70101=>"2007-01",70701=>"2007-07" }
167);
168
169print " to ";
170
171print $cgi->popup_menu(
172    "todate", 
173    [999999, 60630, 61231, 70630],
174    0, 
175    { 999999 => "latest", 60630=>"2006-06", 61231=>"2006-12",70630=>"2007-06" }
176);
177print <<EOF;
178    <br />
179    <font size="-1"><em>(actual resolution depends on available historic data)</em></font>
180</td></tr>
181
182<tr valign="top">
183<td bgcolor="$bg">Frame Rate</td>
184<td>&nbsp;</td>
185<td>
186EOF
187
188print $cgi->popup_menu(
189    "frequency", 
190    [0, 10, 14, 30, 61, 91, 9999],
191    30, 
192    { 0 => "one frame for every planet file available", 10 => "one frame per 10 days", 
193    14 => "one frame per fortnight", 30 => "one frame per month", 61 => "one frame for every two months",
194    91 => "one frame per quarter", 9999 => "only one frame altogehter" }
195);
196
197print " displayed at ";
198
199print $cgi->popup_menu(
200    "delay", 
201    [50, 100, 200, 500], 
202    100, 
203    { 50 => "2 frames per second", 100 => "1 frame per second", 
204    200 => "2 seconds per frame", 500 => "5 seconds per frame" }
205);
206
207print $cgi->checkbox(
208    "loopflag",
209    0,
210    "1",
211    "loop"
212);
213
214print <<EOF;
215</td></tr>
216
217<tr valign="top">
218<td bgcolor="$bg" colspan="3" align="right">
219<input type="button" name="Clear" value="Clear" onClick="document.location.href='.'" /> &nbsp; &nbsp; &nbsp;
220<input type="submit" value="Submit" name="Submit" />
221</td>
222</tr>
223</table>
224</form>
225
226<h2>Request Queue and log</h2>
227EOF
228
229    if (my $lastShown = showRequests(undef, 10))
230    {
231        printf "<p><a href=\"?show=%d\">next page (older requests)</a>", $lastShown-1;
232    }
233}
234elsif (defined($cgi->param("show")))
235{
236    print "<h2>Request Queue and log</h2>";
237    if (my $lastShown = showRequests($cgi->param("show"), 25))
238    {
239        printf "<p><a href=\"?show=%d\">next page (older requests)</a>", $lastShown-1;
240    }
241    print "<p><a href=\"".$cgi->url()."\">Return</a>";
242}
243
244else
245{
246    my $dsn="DBI:mysql:host=localhost:database=osmhistory";
247    my $dbh = DBI->connect($dsn);
248    if (!defined($dbh))
249    { 
250        print "Database error - cannot connect: ".escapeHTML($DBI::errstr)."</body></html>"; 
251        exit; 
252    }
253
254    my $query;
255    if (defined($cgi->param("retry")))
256    {
257        $query=sprintf("update jobs set status='waiting' where id=%d", $cgi->param("retry"));
258        $cgi->delete("retry");
259    }
260    else
261    {
262        my $q;
263
264        foreach my $v (split(/,/, $values))
265        {
266            my $p = $cgi->param($v);
267            $q .= defined($p) ? $dbh->quote($p) : "null";
268            $q .= ",";
269        }
270
271        $query = "insert into jobs ($values,date_entered,status) values ($q".time().",'waiting')";
272    }
273
274    if ($dbh->do($query))
275    {
276        print "Your query has been inserted into the queue.";
277        print "<p><a href=\"".$cgi->url(-query=>1)."&form=1\">Return</a>";
278    }
279    else
280    {
281        print "<font color='red'><b>Could not insert query:</b></font><p>";
282        print escapeHTML($dbh->errstr);
283        print "<p><a href=\"".$cgi->url(-query=>1)."&form=1\">Return</a>";
284    }
285}
286
287print <<EOF;
288<hr>
289<em>Scripts written in Perl by Frederik Ramm &lt;frederik\@remote.org&gt;, Public Domain, source available in OSM SVN (applications/rendering/history).<br>
290All images use OpenStreetMap data which is licensed under <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA 2.0</a>.</em>
291</body></html>
292EOF
293
294sub mytime
295{
296     my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(shift);
297     return sprintf "%04d-%02d-%02d %02d:%02d", 
298        $year+1900,$mon+1,$mday,$hour,$min;
299}
300
301sub showRequests
302{
303    my ($starting, $howmany) = @_;
304
305    my $dsn="DBI:mysql:host=localhost:database=osmhistory";
306    my $dbh = DBI->connect($dsn);
307    if (!defined($dbh))
308    { 
309        print "Database error - cannot connect: ".escapeHTML($DBI::errstr)."</body></html>"; 
310        exit; 
311    }
312    my $query = "select * from jobs ";
313    if (defined($starting))
314    {
315        $query.="where id<=$starting ";
316    }
317    $howmany++;
318    my $last_shown;
319    $query .= "order by id desc limit $howmany";
320    my $sth = $dbh->prepare($query);
321    $sth->execute();
322    print "<table>";
323    while(my $row=$sth->fetchrow_hashref())
324    {
325        $howmany--;
326        last if ($howmany == 0);
327        $last_shown = $row->{"id"};
328        if ($row->{"status"} eq "finished")
329        {
330            print "<tr valign=top><td><a href='images/$row->{id}.gif'><img border=0 src='thumbnails/$row->{id}.gif'></a></td>";
331            print "<td><b>".escapeHTML($row->{"label"})."</b><br>";
332            printf "requested by: ".escapeHTML($row->{"user"}).", id: ".$row->{"id"}."<br>";
333            printf "Image size: %d kB (%d by %d pixels, %d animation frames)<br>", 
334                $row->{"filesize"}/1024, 
335                $row->{"width"}, 
336                $row->{"height"},
337                $row->{"num_frames"};
338            printf "requested %s, processed %s (took %d seconds)<br>", 
339                mytime($row->{"date_entered"}), 
340                mytime($row->{"date_finished"}), 
341                $row->{"date_finished"}-$row->{"date_started"};
342        }
343        else
344        {
345            print "<tr valign=top><td>(no thumbnail)</td>";
346            print "<td><b>".escapeHTML($row->{"label"})."</b><br>";
347            printf "requested by: ".escapeHTML($row->{"user"}).", id: ".$row->{"id"}."<br>";
348            printf "Status: ".$row->{"status"};
349            print "<br>".$row->{"errmsg"} if ($row->{"errmsg"} ne "");
350            printf "<br>requested %s<br>", mytime($row->{"date_entered"});
351        }
352        printf "bbox: %.4f,%.4f,%.4f,%.4f, date range: ",
353            $row->{"minlat"},$row->{"minlon"},$row->{"maxlat"},$row->{"maxlon"};
354        if ($row->{"fromdate"} == 0)
355        {
356            print "earliest to ";
357        }
358        else
359        {
360            printf "20%02d-%02d-%02d to ",
361            $row->{"fromdate"}/10000,
362            $row->{"fromdate"}%10000/100,
363            $row->{"fromdate"}%100;
364        }
365        if ($row->{"todate"} == 999999)
366        {
367            print "latest";
368        }
369        else
370        {
371            printf "20%02d-%02d-%02d",
372            $row->{"todate"}/10000,
373            $row->{"todate"}%10000/100,
374            $row->{"todate"}%100;
375        }
376        print "<br><a href=\"?";
377        foreach my $v (split(/,/, $values))
378        {
379            next if ($v eq "height");
380            print $v."=".uri_escape($row->{$v})."&";
381        }
382        print "form=1\">new request based on these parameters</a>";
383
384        if ($row->{"status"} eq "failed")
385        {
386            printf "&nbsp;/&nbsp;<a href=\"?retry=%d\">re-try this request</a>", $row->{"id"};
387        }
388        print "</td></tr>\n";
389    }
390    print "</table>";
391    return ($howmany==0) ? $last_shown : undef;
392}
Note: See TracBrowser for help on using the repository browser.