comparison static/iwws.js @ 8:4b9d1b47ca17

Plot pressure. Switch from RH to dew point to save an axis for the above.
author Daniel O'Connor <darius@dons.net.au>
date Sun, 21 Aug 2011 15:47:52 +0930
parents 24e9b717722d
children 6edb93c20971
comparison
equal deleted inserted replaced
7:24e9b717722d 8:4b9d1b47ca17
34 startupScreen: 'img/startup.png' 34 startupScreen: 'img/startup.png'
35 }); 35 });
36 36
37 function draw_graph() { 37 function draw_graph() {
38 var temp_out = []; 38 var temp_out = [];
39 var hum_out = []; 39 var dewpt = [];
40 var wavg = []; 40 var wavg = [];
41 var wgust = []; 41 var wgust = [];
42 var rain = []; 42 var rain = [];
43 var pressure = [];
43 var i, mint = 5, maxt = 35; 44 var i, mint = 5, maxt = 35;
44 var l = datacache['idx'].length - 1; 45 var l = datacache['idx'].length - 1;
45 var d = new Date(); 46 var d = new Date();
46 var tzofs = d.getTimezoneOffset() * 60; 47 var tzofs = d.getTimezoneOffset() * 60;
47 for (i = 0; i < l; i++) { 48 for (i = 0; i < l; i++) {
50 if (datacache['temp_out'] < mint) 51 if (datacache['temp_out'] < mint)
51 mint = datacache['temp_out'] 52 mint = datacache['temp_out']
52 if (datacache['temp_out'] < maxt) 53 if (datacache['temp_out'] < maxt)
53 maxt = datacache['temp_out'] 54 maxt = datacache['temp_out']
54 temp_out.push([t * 1000.0, datacache['temp_out'][i]]); 55 temp_out.push([t * 1000.0, datacache['temp_out'][i]]);
55 hum_out.push([t * 1000.0, datacache['hum_out'][i]]); 56 if (datacache['hum_out'][i] != null && datacache['temp_out'][i] != null) {
57 dewpt.push([t * 1000.0, hum2dp(datacache['hum_out'][i], datacache['temp_out'][i])]);
58 }
56 wavg.push([t * 1000.0, datacache['wind_ave'][i], wind2angle(datacache['wind_dir'][i])]); 59 wavg.push([t * 1000.0, datacache['wind_ave'][i], wind2angle(datacache['wind_dir'][i])]);
57 wgust.push([t * 1000.0, datacache['wind_gust'][i], wind2angle(datacache['wind_dir'][i])]); 60 wgust.push([t * 1000.0, datacache['wind_gust'][i], wind2angle(datacache['wind_dir'][i])]);
61 pressure.push([t * 1000.0, datacache['abs_pressure'][i]]);
58 if (datacache['rain'][i] > 0) 62 if (datacache['rain'][i] > 0)
59 rain.push([t * 1000.0, datacache['rain'][i]]); 63 rain.push([t * 1000.0, datacache['rain'][i]]);
60 } 64 }
61 $.plot($("#graph1"), [ 65 $.plot($("#graph1"), [
62 { data : temp_out, label: "Temp.", yaxis : 1, points : { show : true }, lines : { show : true } }, 66 { data : pressure, label: "Baro", yaxis : 1, points : { show : true }, lines : { show : true } },
63 { data : hum_out, label: "RH", yaxis : 2, points : { show : true }, lines : { show : true } } 67 { data : temp_out, label: "Temp.", yaxis : 2, points : { show : true }, lines : { show : true } },
68 { data : dewpt, label: "Dew point", yaxis : 2, points : { show : true }, lines : { show : true } },
64 ], 69 ],
65 { xaxis : { mode : 'time' }, 70 { xaxis : { mode : 'time' },
66 legend : { backgroundOpacity : 0, position : 'nw' }, 71 legend : { backgroundOpacity : 0, position : 'nw' },
67 yaxis : { min : mint, max : maxt, tickFormatter : degCFormatter }, 72 yaxis : { min : 950, max : 1050, tickFormatter : baroFormatter },
68 y2axis : { min : 0, max : 100, tickFormatter : pctFormatter } 73 y2axis : { min : mint, max : maxt, tickFormatter : degCFormatter },
69 }); 74 });
70 $.plot($("#graph2"), [ 75 $.plot($("#graph2"), [
71 { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, 76 { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true },
72 { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, 77 { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true },
73 { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } } 78 { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } },
74 ], 79 ],
75 { xaxis : { mode : 'time' }, 80 { xaxis : { mode : 'time' },
76 legend : { backgroundOpacity : 0, position : 'nw' }, 81 legend : { backgroundOpacity : 0, position : 'nw' },
77 yaxis : { tickFormatter : spdFormatter }, 82 yaxis : { tickFormatter : spdFormatter },
78 y2axis : { min : 0, tickFormatter : mmFormatter } 83 y2axis : { min : 0, tickFormatter : mmFormatter }
80 } 85 }
81 86
82 function wind2angle(dir) { 87 function wind2angle(dir) {
83 var a = dir * (360.0 / 16.0); 88 var a = dir * (360.0 / 16.0);
84 return a; 89 return a;
90 }
91
92 // Formula from http://www.paroscientific.com/dewpoint.htm
93 function alpha(temp, rh, a, b) {
94 return (((a * temp) / (b + temp)) + Math.log(rh / 100.0));
95 }
96
97 function hum2dp(rh, temp) {
98 var a = 17.27;
99 var b = 237.7;
100 var Td = (b * alpha(temp, rh, a, b)) / (a - alpha(temp, rh, a, b));
101 return Td;
85 } 102 }
86 103
87 function degCFormatter(v, axis) { 104 function degCFormatter(v, axis) {
88 return v.toFixed(axis.tickDecimals) +"°C"; 105 return v.toFixed(axis.tickDecimals) +"°C";
89 } 106 }
96 return v.toFixed(axis.tickDecimals) + "kph"; 113 return v.toFixed(axis.tickDecimals) + "kph";
97 } 114 }
98 115
99 function mmFormatter(v, axis) { 116 function mmFormatter(v, axis) {
100 return v.toFixed(axis.tickDecimals) + "mm"; 117 return v.toFixed(axis.tickDecimals) + "mm";
118 }
119
120 function baroFormatter(v, axis) {
121 return v.toFixed(axis.tickDecimals) + "hPa";
101 } 122 }
102 123
103 function got_data(data, status) { 124 function got_data(data, status) {
104 if (status != "success") { 125 if (status != "success") {
105 $.log("Couldn't load data. status = " + status); 126 $.log("Couldn't load data. status = " + status);