diff 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
line wrap: on
line diff
--- a/static/iwws.js	Wed Jun 20 12:57:30 2012 +0930
+++ b/static/iwws.js	Thu Jan 10 16:38:36 2013 +1030
@@ -45,28 +45,71 @@
     var l = datacache['idx'].length - 1;
     var d = new Date();
     var tzofs = d.getTimezoneOffset() * 60;
+    var wavgtmp = 0;
+    var wgusttmp = 0;
+    var winddir = 0;
+    var windavgs = 0;
+    var windnavg = 4;
     for (i = 0; i < l; i++) {
-	// Convert time from UTC to browser LT
-	t = datacache['idx'][i] - tzofs;
+	// Apply offset so Flot times look right (it always shows UTC)
+	t = (datacache['idx'][i] - tzofs) * 1000.0;
+
+	// Keep track of min/max temperature
 	if (datacache['temp_out'][i] < mint)
 	    mint = datacache['temp_out']
 	if (datacache['temp_out'][i] > maxt)
 	    maxt = datacache['temp_out'][i]
-	temp_out.push([t * 1000.0, datacache['temp_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])]);
+
+	// Store outside temperature if valid
+	if (datacache['temp_out'][i] != null) {
+	    temp_out.push([t, datacache['temp_out'][i]]);
+
+	    // Calculate dewpoint if outside humidity is valid
+	    if (datacache['hum_out'][i] != null) {
+		dewpt.push([t, hum2dp(datacache['hum_out'][i], datacache['temp_out'][i])]);
+	    }
 	}
-	wavg.push([t * 1000.0, datacache['wind_ave'][i] * 60.0 * 60.0 / 1000.0, wind2angle(datacache['wind_dir'][i])]);
-	wgust.push([t * 1000.0, datacache['wind_gust'][i] * 60.0 * 60.0 / 1000.0, wind2angle(datacache['wind_dir'][i])]);
-	pressure.push([t * 1000.0, datacache['abs_pressure'][i]]);
+
+	// Store baro
+	pressure.push([t, datacache['abs_pressure'][i]]);
+
+	// Store rain if there was any
 	if (datacache['rain'][i] > 0)
-	    rain.push([t * 1000.0, datacache['rain'][i]]);
+	    rain.push([t, datacache['rain'][i]]);
+
+	// Store wind (convert to km/r)
+	// Average the average wind speed
+	wavgtmp += datacache['wind_ave'][i] * 60.0 * 60.0 / 1000.0
+	// Pick highest speed gusts
+	var g = datacache['wind_gust'][i] * 60.0 * 60.0 / 1000.0;
+	if (g > wgusttmp) {
+	    wgusttmp = g;
+	}
+	// Accumulate speed/gust direction
+	winddir += wind2angle(datacache['wind_dir'][i]);
+	windavgs++;
+	// Normalise
+	if (windavgs == windnavg) {
+	    windavgs = 0;
+	    wavgtmp /= windnavg;
+	    // Note: gust is peak, so nothing to do
+	    winddir /= windnavg;
+
+	    // Store
+	    wavg.push([t, wavgtmp, winddir]);
+	    wgust.push([t, wgusttmp, winddir]);
+
+	    // Reset accumulators
+	    wavgtmp = 0;
+	    wgusttmp = 0;
+	    winddir = 0;
+	}
     }
 
     $.plot($("#graph1"), [
-	{ 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 } },
+	{ data : pressure, label: "Baro", yaxis : 1, points : { show : true, radius : 0 }, lines : { show : true } },
+	{ data : temp_out, label: "Temp.", yaxis : 2, points : { show : true, radius : 0 }, lines : { show : true } },
+	{ data : dewpt, label: "Dew point", yaxis : 2, points : { show : true, radius : 0 }, lines : { show : true } },
     ],
 	   { xaxis : { mode : 'time' },
 	     legend : { backgroundOpacity : 0, position : 'nw' },
@@ -75,7 +118,7 @@
 	   });
     $.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 : 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" } },
     ],
 	   { xaxis : { mode : 'time' },
@@ -83,6 +126,10 @@
 	     yaxis : { tickFormatter : spdFormatter },
 	     y2axis : { min : 0, tickFormatter : mmFormatter }
 	   });
+    // Reverse tzofs calculation as Date does local time
+    var dobj = new Date(datacache['lastdata'] * 1000.0);
+    $('#stamp').html(sprintf("Last data: %02d/%02d/%02d %02d:%02d:%02d", dobj.getFullYear(), dobj.getMonth() + 1, dobj.getDate(),
+			     dobj.getHours(), dobj.getMinutes(), dobj.getSeconds()));
 }
 
 function wind2angle(dir) {