annotate static/iwws.js @ 3:942d4cfc2538

Add static alias. Correct typos in demo paths.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 15 Aug 2011 19:05:23 +0930
parents 2d9ee2b3ae82
children 24e9b717722d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 /*
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 * Copyright 2011 Daniel O'Connor <darius@dons.net.au>
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 *
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 * Redistribution and use in source and binary forms, with or without modification, are
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 * permitted provided that the following conditions are met:
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 *
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 * conditions and the following disclaimer.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 *
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 * of conditions and the following disclaimer in the documentation and/or other materials
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 * provided with the distribution.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 *
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 *
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 * The views and conclusions contained in the software and documentation are those of the
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25 * authors and should not be interpreted as representing official policies, either expressed
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 * or implied, of Daniel O'Connor.
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 */
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 $.jQTouch({
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 icon: 'icon.png',
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 startupScreen: 'img/startup.png'
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 function draw_graph(data, status) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 if (status != "success") {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 $.log("Couldn't load data. status = %s", status);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 return;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 var temp_out = [];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 var hum_out = [];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 var wavg = [];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 var wgust = [];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 var rain = [];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 var i, mint = 5, maxt = 35;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 var l = data['idx'].length - 1;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 var d = new Date();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 var tzofs = d.getTimezoneOffset() * 60;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 for (i = 0; i < l; i++) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 // Convert time from UTC to browser LT
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 t = data['idx'][i] - tzofs;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 if (data['temp_out'] < mint)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 mint = data['temp_out']
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
54 if (data['temp_out'] < maxt)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
55 maxt = data['temp_out']
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
56 temp_out.push([t * 1000.0, data['temp_out'][i]]);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
57 hum_out.push([t * 1000.0, data['hum_out'][i]]);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
58 wavg.push([t * 1000.0, data['wind_ave'][i], wind2angle(data['wind_dir'][i])]);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
59 wgust.push([t * 1000.0, data['wind_gust'][i], wind2angle(data['wind_dir'][i])]);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
60 if (data['rain'][i] > 0)
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
61 rain.push([t * 1000.0, data['rain'][i]]);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
62 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
63 $.plot($("#graph1"), [
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
64 { data : temp_out, label: "Temp.", yaxis : 1, points : { show : true }, lines : { show : true } },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
65 { data : hum_out, label: "RH", yaxis : 2, points : { show : true }, lines : { show : true } }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
66 ],
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
67 { xaxis : { mode : 'time' },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
68 legend : { backgroundOpacity : 0, position : 'nw' },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
69 yaxis : { min : mint, max : maxt, tickFormatter : degCFormatter },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
70 y2axis : { min : 0, max : 100, tickFormatter : pctFormatter }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
71 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
72 $.plot($("#graph2"), [
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
73 { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
74 { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
75 { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
76 ],
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
77 { xaxis : { mode : 'time' },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
78 legend : { backgroundOpacity : 0, position : 'nw' },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
79 yaxis : { tickFormatter : spdFormatter },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
80 y2axis : { min : 0, tickFormatter : mmFormatter }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
81 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
82 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
83
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
84 function wind2angle(dir) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
85 var a = dir * (360.0 / 16.0);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
86 return a;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
87 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
88
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
89 function degCFormatter(v, axis) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
90 return v.toFixed(axis.tickDecimals) +"°C";
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
91 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
92
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
93 function pctFormatter(v, axis) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
94 return v.toFixed(axis.tickDecimals) +"%";
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
95 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
96
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
97 function spdFormatter(v, axis) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
98 return v.toFixed(axis.tickDecimals) + "kph";
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
99 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
100
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
101 function mmFormatter(v, axis) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
102 return v.toFixed(axis.tickDecimals) + "mm";
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
103 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
104
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
105 function update_data() {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
106 jQuery.getJSON('iwws/getdata.json', draw_graph);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
108
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 $(document).ready(function(){
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
110 update_data();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
111 });