Mercurial > ~darius > hgwebdir.cgi > iwws
comparison static/iwws.js @ 13:a0213f0e707b
- Update for v12.10
- Plot raw data to show more up to date data
- Average/peak winds so they don't spam the display.
- Display the time of the most recent data.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 10 Jan 2013 16:38:36 +1030 |
parents | bfe6ed563ffc |
children | 294e6a7fbb6e |
comparison
equal
deleted
inserted
replaced
12:bfe6ed563ffc | 13:a0213f0e707b |
---|---|
43 var pressure = []; | 43 var pressure = []; |
44 var i, mint = 5, maxt = 35; | 44 var i, mint = 5, maxt = 35; |
45 var l = datacache['idx'].length - 1; | 45 var l = datacache['idx'].length - 1; |
46 var d = new Date(); | 46 var d = new Date(); |
47 var tzofs = d.getTimezoneOffset() * 60; | 47 var tzofs = d.getTimezoneOffset() * 60; |
48 var wavgtmp = 0; | |
49 var wgusttmp = 0; | |
50 var winddir = 0; | |
51 var windavgs = 0; | |
52 var windnavg = 4; | |
48 for (i = 0; i < l; i++) { | 53 for (i = 0; i < l; i++) { |
49 // Convert time from UTC to browser LT | 54 // Apply offset so Flot times look right (it always shows UTC) |
50 t = datacache['idx'][i] - tzofs; | 55 t = (datacache['idx'][i] - tzofs) * 1000.0; |
56 | |
57 // Keep track of min/max temperature | |
51 if (datacache['temp_out'][i] < mint) | 58 if (datacache['temp_out'][i] < mint) |
52 mint = datacache['temp_out'] | 59 mint = datacache['temp_out'] |
53 if (datacache['temp_out'][i] > maxt) | 60 if (datacache['temp_out'][i] > maxt) |
54 maxt = datacache['temp_out'][i] | 61 maxt = datacache['temp_out'][i] |
55 temp_out.push([t * 1000.0, datacache['temp_out'][i]]); | 62 |
56 if (datacache['hum_out'][i] != null && datacache['temp_out'][i] != null) { | 63 // Store outside temperature if valid |
57 dewpt.push([t * 1000.0, hum2dp(datacache['hum_out'][i], datacache['temp_out'][i])]); | 64 if (datacache['temp_out'][i] != null) { |
65 temp_out.push([t, datacache['temp_out'][i]]); | |
66 | |
67 // Calculate dewpoint if outside humidity is valid | |
68 if (datacache['hum_out'][i] != null) { | |
69 dewpt.push([t, hum2dp(datacache['hum_out'][i], datacache['temp_out'][i])]); | |
70 } | |
58 } | 71 } |
59 wavg.push([t * 1000.0, datacache['wind_ave'][i] * 60.0 * 60.0 / 1000.0, wind2angle(datacache['wind_dir'][i])]); | 72 |
60 wgust.push([t * 1000.0, datacache['wind_gust'][i] * 60.0 * 60.0 / 1000.0, wind2angle(datacache['wind_dir'][i])]); | 73 // Store baro |
61 pressure.push([t * 1000.0, datacache['abs_pressure'][i]]); | 74 pressure.push([t, datacache['abs_pressure'][i]]); |
75 | |
76 // Store rain if there was any | |
62 if (datacache['rain'][i] > 0) | 77 if (datacache['rain'][i] > 0) |
63 rain.push([t * 1000.0, datacache['rain'][i]]); | 78 rain.push([t, datacache['rain'][i]]); |
79 | |
80 // Store wind (convert to km/r) | |
81 // Average the average wind speed | |
82 wavgtmp += datacache['wind_ave'][i] * 60.0 * 60.0 / 1000.0 | |
83 // Pick highest speed gusts | |
84 var g = datacache['wind_gust'][i] * 60.0 * 60.0 / 1000.0; | |
85 if (g > wgusttmp) { | |
86 wgusttmp = g; | |
87 } | |
88 // Accumulate speed/gust direction | |
89 winddir += wind2angle(datacache['wind_dir'][i]); | |
90 windavgs++; | |
91 // Normalise | |
92 if (windavgs == windnavg) { | |
93 windavgs = 0; | |
94 wavgtmp /= windnavg; | |
95 // Note: gust is peak, so nothing to do | |
96 winddir /= windnavg; | |
97 | |
98 // Store | |
99 wavg.push([t, wavgtmp, winddir]); | |
100 wgust.push([t, wgusttmp, winddir]); | |
101 | |
102 // Reset accumulators | |
103 wavgtmp = 0; | |
104 wgusttmp = 0; | |
105 winddir = 0; | |
106 } | |
64 } | 107 } |
65 | 108 |
66 $.plot($("#graph1"), [ | 109 $.plot($("#graph1"), [ |
67 { data : pressure, label: "Baro", yaxis : 1, points : { show : true }, lines : { show : true } }, | 110 { data : pressure, label: "Baro", yaxis : 1, points : { show : true, radius : 0 }, lines : { show : true } }, |
68 { data : temp_out, label: "Temp.", yaxis : 2, points : { show : true }, lines : { show : true } }, | 111 { data : temp_out, label: "Temp.", yaxis : 2, points : { show : true, radius : 0 }, lines : { show : true } }, |
69 { data : dewpt, label: "Dew point", yaxis : 2, points : { show : true }, lines : { show : true } }, | 112 { data : dewpt, label: "Dew point", yaxis : 2, points : { show : true, radius : 0 }, lines : { show : true } }, |
70 ], | 113 ], |
71 { xaxis : { mode : 'time' }, | 114 { xaxis : { mode : 'time' }, |
72 legend : { backgroundOpacity : 0, position : 'nw' }, | 115 legend : { backgroundOpacity : 0, position : 'nw' }, |
73 yaxis : { min : 950, max : 1050, tickFormatter : baroFormatter }, | 116 yaxis : { min : 950, max : 1050, tickFormatter : baroFormatter }, |
74 y2axis : { min : mint, max : maxt, tickFormatter : degCFormatter }, | 117 y2axis : { min : mint, max : maxt, tickFormatter : degCFormatter }, |
75 }); | 118 }); |
76 $.plot($("#graph2"), [ | 119 $.plot($("#graph2"), [ |
77 { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, | 120 { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, |
78 { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, | 121 { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, |
79 { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } }, | 122 { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } }, |
80 ], | 123 ], |
81 { xaxis : { mode : 'time' }, | 124 { xaxis : { mode : 'time' }, |
82 legend : { backgroundOpacity : 0, position : 'nw' }, | 125 legend : { backgroundOpacity : 0, position : 'nw' }, |
83 yaxis : { tickFormatter : spdFormatter }, | 126 yaxis : { tickFormatter : spdFormatter }, |
84 y2axis : { min : 0, tickFormatter : mmFormatter } | 127 y2axis : { min : 0, tickFormatter : mmFormatter } |
85 }); | 128 }); |
129 // Reverse tzofs calculation as Date does local time | |
130 var dobj = new Date(datacache['lastdata'] * 1000.0); | |
131 $('#stamp').html(sprintf("Last data: %02d/%02d/%02d %02d:%02d:%02d", dobj.getFullYear(), dobj.getMonth() + 1, dobj.getDate(), | |
132 dobj.getHours(), dobj.getMinutes(), dobj.getSeconds())); | |
86 } | 133 } |
87 | 134 |
88 function wind2angle(dir) { | 135 function wind2angle(dir) { |
89 var a = dir * (360.0 / 16.0); | 136 var a = dir * (360.0 / 16.0); |
90 return a; | 137 return a; |