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

Last change on this file since 3494 was 3494, checked in by frederik, 13 years ago

new

  • Property svn:executable set to *
File size: 10.8 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';
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 <<EOF;
208</td></tr>
209
210<tr valign="top">
211<td bgcolor="$bg" colspan="3" align="right">
212<input type="button" name="Clear" value="Clear" onClick="document.location.href='.'" /> &nbsp; &nbsp; &nbsp;
213<input type="submit" value="Submit" name="Submit" />
214</td>
215</tr>
216</table>
217</form>
218
219<h2>Request Queue and log</h2>
220EOF
221
222    if (my $lastShown = showRequests(undef, 10))
223    {
224        printf "<p><a href=\"?show=%d\">next page (older requests)</a>", $lastShown-1;
225    }
226}
227elsif (defined($cgi->param("show")))
228{
229    print "<h2>Request Queue and log</h2>";
230    if (my $lastShown = showRequests($cgi->param("show"), 25))
231    {
232        printf "<p><a href=\"?show=%d\">next page (older requests)</a>", $lastShown-1;
233    }
234    print "<p><a href=\"".$cgi->url()."\">Return</a>";
235}
236
237else
238{
239    my $dsn="DBI:mysql:host=localhost:database=osmhistory";
240    my $dbh = DBI->connect($dsn);
241    if (!defined($dbh))
242    { 
243        print "Database error - cannot connect: ".escapeHTML($DBI::errstr)."</body></html>"; 
244        exit; 
245    }
246
247    my $query;
248    if (defined($cgi->param("retry")))
249    {
250        $query=sprintf("update jobs set status='waiting' where id=%d", $cgi->param("retry"));
251        $cgi->delete("retry");
252    }
253    else
254    {
255        my $q;
256
257        foreach my $v (split(/,/, $values))
258        {
259            my $p = $cgi->param($v);
260            $q .= defined($p) ? $dbh->quote($p) : "null";
261            $q .= ",";
262        }
263
264        $query = "insert into jobs ($values,date_entered,status) values ($q".time().",'waiting')";
265    }
266
267    if ($dbh->do($query))
268    {
269        print "Your query has been inserted into the queue.";
270        print "<p><a href=\"".$cgi->url(-query=>1)."&form=1\">Return</a>";
271    }
272    else
273    {
274        print "<font color='red'><b>Could not insert query:</b></font><p>";
275        print escapeHTML($dbh->errstr);
276        print "<p><a href=\"".$cgi->url(-query=>1)."&form=1\">Return</a>";
277    }
278}
279
280print <<EOF;
281<hr>
282<em>Scripts written in Perl by Frederik Ramm &lt;frederik\@remote.org&gt;, Public Domain, source available on request.<br>
283All 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>
284</body></html>
285EOF
286
287sub mytime
288{
289     my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(shift);
290     return sprintf "%04d-%02d-%02d %02d:%02d", 
291        $year+1900,$mon+1,$mday,$hour,$min;
292}
293
294sub showRequests
295{
296    my ($starting, $howmany) = @_;
297
298    my $dsn="DBI:mysql:host=localhost:database=osmhistory";
299    my $dbh = DBI->connect($dsn);
300    if (!defined($dbh))
301    { 
302        print "Database error - cannot connect: ".escapeHTML($DBI::errstr)."</body></html>"; 
303        exit; 
304    }
305    my $query = "select * from jobs ";
306    if (defined($starting))
307    {
308        $query.="where id<=$starting ";
309    }
310    $howmany++;
311    my $last_shown;
312    $query .= "order by id desc limit $howmany";
313    my $sth = $dbh->prepare($query);
314    $sth->execute();
315    print "<table>";
316    while(my $row=$sth->fetchrow_hashref())
317    {
318        $howmany--;
319        last if ($howmany == 0);
320        $last_shown = $row->{"id"};
321        if ($row->{"status"} eq "finished")
322        {
323            print "<tr valign=top><td><a href='images/$row->{id}.gif'><img border=0 src='thumbnails/$row->{id}.gif'></a></td>";
324            print "<td><b>".escapeHTML($row->{"label"})."</b><br>";
325            printf "requested by: ".escapeHTML($row->{"user"}).", id: ".$row->{"id"}."<br>";
326            printf "Image size: %d kB (%d by %d pixels, %d animation frames)<br>", 
327                $row->{"filesize"}/1024, 
328                $row->{"width"}, 
329                $row->{"height"},
330                $row->{"num_frames"};
331            printf "requested %s, processed %s (took %d seconds)<br>", 
332                mytime($row->{"date_entered"}), 
333                mytime($row->{"date_finished"}), 
334                $row->{"date_finished"}-$row->{"date_started"};
335        }
336        else
337        {
338            print "<tr valign=top><td>(no thumbnail)</td>";
339            print "<td><b>".escapeHTML($row->{"label"})."</b><br>";
340            printf "requested by: ".escapeHTML($row->{"user"}).", id: ".$row->{"id"}."<br>";
341            printf "Status: ".$row->{"status"};
342            print "<br>".$row->{"errmsg"} if ($row->{"errmsg"} ne "");
343            printf "<br>requested %s<br>", mytime($row->{"date_entered"});
344        }
345        printf "bbox: %.4f,%.4f,%.4f,%.4f, date range: ",
346            $row->{"minlat"},$row->{"minlon"},$row->{"maxlat"},$row->{"maxlon"};
347        if ($row->{"fromdate"} == 0)
348        {
349            print "earliest to ";
350        }
351        else
352        {
353            printf "20%02d-%02d-%02d to ",
354            $row->{"fromdate"}/10000,
355            $row->{"fromdate"}%10000/100,
356            $row->{"fromdate"}%100;
357        }
358        if ($row->{"todate"} == 999999)
359        {
360            print "latest";
361        }
362        else
363        {
364            printf "20%02d-%02d-%02d",
365            $row->{"todate"}/10000,
366            $row->{"todate"}%10000/100,
367            $row->{"todate"}%100;
368        }
369        print "<br><a href=\"?";
370        foreach my $v (split(/,/, $values))
371        {
372            next if ($v eq "height");
373            print $v."=".uri_escape($row->{$v})."&";
374        }
375        print "form=1\">new request based on these parameters</a>";
376
377        if ($row->{"status"} eq "failed")
378        {
379            printf "&nbsp;/&nbsp;<a href=\"?retry=%d\">re-try this request</a>", $row->{"id"};
380        }
381        print "</td></tr>\n";
382    }
383    print "</table>";
384    return ($howmany==0) ? $last_shown : undef;
385}
Note: See TracBrowser for help on using the repository browser.