comparison static/iwws.js @ 7:24e9b717722d

- Update every 10 minutes. - Redraw the graph on orientation change.
author Daniel O'Connor <darius@dons.net.au>
date Tue, 16 Aug 2011 22:34:30 +0930
parents 2d9ee2b3ae82
children 4b9d1b47ca17
comparison
equal deleted inserted replaced
6:74215b8e16f4 7:24e9b717722d
24 * The views and conclusions contained in the software and documentation are those of the 24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed 25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of Daniel O'Connor. 26 * or implied, of Daniel O'Connor.
27 */ 27 */
28 28
29 var timer = null;
30 var datacache = null;
31
29 $.jQTouch({ 32 $.jQTouch({
30 icon: 'icon.png', 33 icon: 'icon.png',
31 startupScreen: 'img/startup.png' 34 startupScreen: 'img/startup.png'
32 }); 35 });
33 36
34 function draw_graph(data, status) { 37 function draw_graph() {
35 if (status != "success") {
36 $.log("Couldn't load data. status = %s", status);
37 return;
38 }
39
40 var temp_out = []; 38 var temp_out = [];
41 var hum_out = []; 39 var hum_out = [];
42 var wavg = []; 40 var wavg = [];
43 var wgust = []; 41 var wgust = [];
44 var rain = []; 42 var rain = [];
45 var i, mint = 5, maxt = 35; 43 var i, mint = 5, maxt = 35;
46 var l = data['idx'].length - 1; 44 var l = datacache['idx'].length - 1;
47 var d = new Date(); 45 var d = new Date();
48 var tzofs = d.getTimezoneOffset() * 60; 46 var tzofs = d.getTimezoneOffset() * 60;
49 for (i = 0; i < l; i++) { 47 for (i = 0; i < l; i++) {
50 // Convert time from UTC to browser LT 48 // Convert time from UTC to browser LT
51 t = data['idx'][i] - tzofs; 49 t = datacache['idx'][i] - tzofs;
52 if (data['temp_out'] < mint) 50 if (datacache['temp_out'] < mint)
53 mint = data['temp_out'] 51 mint = datacache['temp_out']
54 if (data['temp_out'] < maxt) 52 if (datacache['temp_out'] < maxt)
55 maxt = data['temp_out'] 53 maxt = datacache['temp_out']
56 temp_out.push([t * 1000.0, data['temp_out'][i]]); 54 temp_out.push([t * 1000.0, datacache['temp_out'][i]]);
57 hum_out.push([t * 1000.0, data['hum_out'][i]]); 55 hum_out.push([t * 1000.0, datacache['hum_out'][i]]);
58 wavg.push([t * 1000.0, data['wind_ave'][i], wind2angle(data['wind_dir'][i])]); 56 wavg.push([t * 1000.0, datacache['wind_ave'][i], wind2angle(datacache['wind_dir'][i])]);
59 wgust.push([t * 1000.0, data['wind_gust'][i], wind2angle(data['wind_dir'][i])]); 57 wgust.push([t * 1000.0, datacache['wind_gust'][i], wind2angle(datacache['wind_dir'][i])]);
60 if (data['rain'][i] > 0) 58 if (datacache['rain'][i] > 0)
61 rain.push([t * 1000.0, data['rain'][i]]); 59 rain.push([t * 1000.0, datacache['rain'][i]]);
62 } 60 }
63 $.plot($("#graph1"), [ 61 $.plot($("#graph1"), [
64 { data : temp_out, label: "Temp.", yaxis : 1, points : { show : true }, lines : { show : true } }, 62 { data : temp_out, label: "Temp.", yaxis : 1, points : { show : true }, lines : { show : true } },
65 { data : hum_out, label: "RH", yaxis : 2, points : { show : true }, lines : { show : true } } 63 { data : hum_out, label: "RH", yaxis : 2, points : { show : true }, lines : { show : true } }
66 ], 64 ],
100 98
101 function mmFormatter(v, axis) { 99 function mmFormatter(v, axis) {
102 return v.toFixed(axis.tickDecimals) + "mm"; 100 return v.toFixed(axis.tickDecimals) + "mm";
103 } 101 }
104 102
103 function got_data(data, status) {
104 if (status != "success") {
105 $.log("Couldn't load data. status = " + status);
106 return;
107 }
108
109 datacache = data;
110 draw_graph();
111 }
112
105 function update_data() { 113 function update_data() {
106 jQuery.getJSON('iwws/getdata.json', draw_graph); 114 /* Cancel any pending timeout (eg if the user pressed update) */
115 if (timer != null)
116 clearTimeout(timeout);
117 jQuery.getJSON('iwws/getdata.json', got_data);
118 /* Set to refresh in 10 minutes */
119 timeout = setTimeout(update_data, 10 * 60 * 60);
107 } 120 }
108 121
109 $(document).ready(function(){ 122 $(document).ready(function(){
110 update_data(); 123 update_data();
124
125 $('body').bind('turn', function(event, info) {
126 draw_graph();
127 });
111 }); 128 });