annotate static/iwws.js @ 15:ebf411c89a3d

Fix bar width now we get data more frequently.
author Daniel O'Connor <darius@dons.net.au>
date Fri, 31 May 2013 13:35:56 +0930
parents 294e6a7fbb6e
children 5a9b33dcdb2c
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
7
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
29 var timer = null;
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
30 var datacache = null;
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
31
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 $.jQTouch({
14
294e6a7fbb6e Fix icon path.
Daniel O'Connor <darius@dons.net.au>
parents: 13
diff changeset
33 icon: 'static/icon.png',
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 startupScreen: 'img/startup.png'
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36
7
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
37 function draw_graph() {
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 var temp_out = [];
8
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
39 var dewpt = [];
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 var wavg = [];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 var wgust = [];
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 var rain = [];
8
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
43 var pressure = [];
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 var i, mint = 5, maxt = 35;
7
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
45 var l = datacache['idx'].length - 1;
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46 var d = new Date();
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 var tzofs = d.getTimezoneOffset() * 60;
13
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
48 var wavgtmp = 0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
49 var wgusttmp = 0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
50 var winddir = 0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
51 var windavgs = 0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
52 var windnavg = 4;
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 for (i = 0; i < l; i++) {
13
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
54 // Apply offset so Flot times look right (it always shows UTC)
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
55 t = (datacache['idx'][i] - tzofs) * 1000.0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
56
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
57 // Keep track of min/max temperature
9
6edb93c20971 Fix stretching the graph limits for temperature.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
58 if (datacache['temp_out'][i] < mint)
7
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
59 mint = datacache['temp_out']
9
6edb93c20971 Fix stretching the graph limits for temperature.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
60 if (datacache['temp_out'][i] > maxt)
6edb93c20971 Fix stretching the graph limits for temperature.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
61 maxt = datacache['temp_out'][i]
13
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
62
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
63 // Store outside temperature if valid
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
64 if (datacache['temp_out'][i] != null) {
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
65 temp_out.push([t, datacache['temp_out'][i]]);
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
66
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
67 // Calculate dewpoint if outside humidity is valid
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
68 if (datacache['hum_out'][i] != null) {
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
69 dewpt.push([t, hum2dp(datacache['hum_out'][i], datacache['temp_out'][i])]);
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
70 }
8
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
71 }
13
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
72
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
73 // Store baro
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
74 pressure.push([t, datacache['abs_pressure'][i]]);
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
75
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
76 // Store rain if there was any
7
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
77 if (datacache['rain'][i] > 0)
13
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
78 rain.push([t, datacache['rain'][i]]);
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
79
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
80 // Store wind (convert to km/r)
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
81 // Average the average wind speed
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
82 wavgtmp += datacache['wind_ave'][i] * 60.0 * 60.0 / 1000.0
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
83 // Pick highest speed gusts
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
84 var g = datacache['wind_gust'][i] * 60.0 * 60.0 / 1000.0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
85 if (g > wgusttmp) {
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
86 wgusttmp = g;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
87 }
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
88 // Accumulate speed/gust direction
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
89 winddir += wind2angle(datacache['wind_dir'][i]);
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
90 windavgs++;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
91 // Normalise
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
92 if (windavgs == windnavg) {
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
93 windavgs = 0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
94 wavgtmp /= windnavg;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
95 // Note: gust is peak, so nothing to do
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
96 winddir /= windnavg;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
97
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
98 // Store
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
99 wavg.push([t, wavgtmp, winddir]);
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
100 wgust.push([t, wgusttmp, winddir]);
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
101
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
102 // Reset accumulators
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
103 wavgtmp = 0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
104 wgusttmp = 0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
105 winddir = 0;
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
106 }
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
107 }
9
6edb93c20971 Fix stretching the graph limits for temperature.
Daniel O'Connor <darius@dons.net.au>
parents: 8
diff changeset
108
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
109 $.plot($("#graph1"), [
13
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
110 { data : pressure, label: "Baro", yaxis : 1, points : { show : true, radius : 0 }, lines : { show : true } },
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
111 { data : temp_out, label: "Temp.", yaxis : 2, points : { show : true, radius : 0 }, lines : { show : true } },
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
112 { data : dewpt, label: "Dew point", yaxis : 2, points : { show : true, radius : 0 }, lines : { show : true } },
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
113 ],
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
114 { xaxis : { mode : 'time' },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
115 legend : { backgroundOpacity : 0, position : 'nw' },
8
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
116 yaxis : { min : 950, max : 1050, tickFormatter : baroFormatter },
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
117 y2axis : { min : mint, max : maxt, tickFormatter : degCFormatter },
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
118 });
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
119 $.plot($("#graph2"), [
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
120 { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true },
13
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
121 { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true },
15
ebf411c89a3d Fix bar width now we get data more frequently.
Daniel O'Connor <darius@dons.net.au>
parents: 14
diff changeset
122 { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 5 * 60 * 1000, align : "centre" } },
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
123 ],
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
124 { xaxis : { mode : 'time' },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
125 legend : { backgroundOpacity : 0, position : 'nw' },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
126 yaxis : { tickFormatter : spdFormatter },
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
127 y2axis : { min : 0, tickFormatter : mmFormatter }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
128 });
13
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
129 // Reverse tzofs calculation as Date does local time
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
130 var dobj = new Date(datacache['lastdata'] * 1000.0);
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
131 $('#stamp').html(sprintf("Last data: %02d/%02d/%02d %02d:%02d:%02d", dobj.getFullYear(), dobj.getMonth() + 1, dobj.getDate(),
a0213f0e707b - Update for v12.10
Daniel O'Connor <darius@dons.net.au>
parents: 12
diff changeset
132 dobj.getHours(), dobj.getMinutes(), dobj.getSeconds()));
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
133 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
134
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
135 function wind2angle(dir) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
136 var a = dir * (360.0 / 16.0);
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
137 return a;
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
138 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
139
8
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
140 // Formula from http://www.paroscientific.com/dewpoint.htm
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
141 function alpha(temp, rh, a, b) {
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
142 return (((a * temp) / (b + temp)) + Math.log(rh / 100.0));
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
143 }
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
144
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
145 function hum2dp(rh, temp) {
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
146 var a = 17.27;
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
147 var b = 237.7;
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
148 var Td = (b * alpha(temp, rh, a, b)) / (a - alpha(temp, rh, a, b));
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
149 return Td;
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
150 }
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
151
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
152 function degCFormatter(v, axis) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
153 return v.toFixed(axis.tickDecimals) +"°C";
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
154 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
155
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
156 function pctFormatter(v, axis) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
157 return v.toFixed(axis.tickDecimals) +"%";
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
158 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
159
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
160 function spdFormatter(v, axis) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
161 return v.toFixed(axis.tickDecimals) + "kph";
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
162 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
163
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
164 function mmFormatter(v, axis) {
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
165 return v.toFixed(axis.tickDecimals) + "mm";
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
166 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
167
8
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
168 function baroFormatter(v, axis) {
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
169 return v.toFixed(axis.tickDecimals) + "hPa";
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
170 }
4b9d1b47ca17 Plot pressure.
Daniel O'Connor <darius@dons.net.au>
parents: 7
diff changeset
171
7
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
172 function got_data(data, status) {
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
173 if (status != "success") {
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
174 $.log("Couldn't load data. status = " + status);
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
175 return;
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
176 }
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
177
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
178 datacache = data;
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
179 draw_graph();
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
180 }
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
181
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
182 function update_data() {
7
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
183 /* Cancel any pending timeout (eg if the user pressed update) */
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
184 if (timer != null)
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
185 clearTimeout(timeout);
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
186 jQuery.getJSON('iwws/getdata.json', got_data);
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
187 /* Set to refresh in 10 minutes */
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
188 timeout = setTimeout(update_data, 10 * 60 * 60);
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
189 }
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
190
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
191 $(document).ready(function(){
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
192 update_data();
7
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
193
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
194 $('body').bind('turn', function(event, info) {
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
195 draw_graph();
24e9b717722d - Update every 10 minutes.
Daniel O'Connor <darius@dons.net.au>
parents: 0
diff changeset
196 });
0
2d9ee2b3ae82 Initial commit of iWWS.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
197 });