Mercurial > ~darius > hgwebdir.cgi > iwws
diff 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 |
line wrap: on
line diff
--- a/static/iwws.js Tue Aug 16 22:34:30 2011 +0930 +++ b/static/iwws.js Sun Aug 21 15:47:52 2011 +0930 @@ -36,10 +36,11 @@ function draw_graph() { var temp_out = []; - var hum_out = []; + var dewpt = []; var wavg = []; var wgust = []; var rain = []; + var pressure = []; var i, mint = 5, maxt = 35; var l = datacache['idx'].length - 1; var d = new Date(); @@ -52,25 +53,29 @@ if (datacache['temp_out'] < maxt) maxt = datacache['temp_out'] temp_out.push([t * 1000.0, datacache['temp_out'][i]]); - hum_out.push([t * 1000.0, datacache['hum_out'][i]]); + if (datacache['hum_out'][i] != null && datacache['temp_out'][i] != null) { + dewpt.push([t * 1000.0, hum2dp(datacache['hum_out'][i], datacache['temp_out'][i])]); + } wavg.push([t * 1000.0, datacache['wind_ave'][i], wind2angle(datacache['wind_dir'][i])]); wgust.push([t * 1000.0, datacache['wind_gust'][i], wind2angle(datacache['wind_dir'][i])]); + pressure.push([t * 1000.0, datacache['abs_pressure'][i]]); if (datacache['rain'][i] > 0) rain.push([t * 1000.0, datacache['rain'][i]]); } $.plot($("#graph1"), [ - { data : temp_out, label: "Temp.", yaxis : 1, points : { show : true }, lines : { show : true } }, - { data : hum_out, label: "RH", yaxis : 2, points : { show : true }, lines : { show : true } } + { data : pressure, label: "Baro", yaxis : 1, points : { show : true }, lines : { show : true } }, + { data : temp_out, label: "Temp.", yaxis : 2, points : { show : true }, lines : { show : true } }, + { data : dewpt, label: "Dew point", yaxis : 2, points : { show : true }, lines : { show : true } }, ], { xaxis : { mode : 'time' }, legend : { backgroundOpacity : 0, position : 'nw' }, - yaxis : { min : mint, max : maxt, tickFormatter : degCFormatter }, - y2axis : { min : 0, max : 100, tickFormatter : pctFormatter } + yaxis : { min : 950, max : 1050, tickFormatter : baroFormatter }, + y2axis : { min : mint, max : maxt, tickFormatter : degCFormatter }, }); $.plot($("#graph2"), [ { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true }, - { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } } + { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } }, ], { xaxis : { mode : 'time' }, legend : { backgroundOpacity : 0, position : 'nw' }, @@ -84,6 +89,18 @@ return a; } +// Formula from http://www.paroscientific.com/dewpoint.htm +function alpha(temp, rh, a, b) { + return (((a * temp) / (b + temp)) + Math.log(rh / 100.0)); +} + +function hum2dp(rh, temp) { + var a = 17.27; + var b = 237.7; + var Td = (b * alpha(temp, rh, a, b)) / (a - alpha(temp, rh, a, b)); + return Td; +} + function degCFormatter(v, axis) { return v.toFixed(axis.tickDecimals) +"°C"; } @@ -100,6 +117,10 @@ return v.toFixed(axis.tickDecimals) + "mm"; } +function baroFormatter(v, axis) { + return v.toFixed(axis.tickDecimals) + "hPa"; +} + function got_data(data, status) { if (status != "success") { $.log("Couldn't load data. status = " + status);