comparison static/iwws.js @ 0:2d9ee2b3ae82

Initial commit of iWWS.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 15 Aug 2011 17:44:56 +0930
parents
children 24e9b717722d
comparison
equal deleted inserted replaced
-1:000000000000 0:2d9ee2b3ae82
1 /*
2 * Copyright 2011 Daniel O'Connor <darius@dons.net.au>
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
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
26 * or implied, of Daniel O'Connor.
27 */
28
29 $.jQTouch({
30 icon: 'icon.png',
31 startupScreen: 'img/startup.png'
32 });
33
34 function draw_graph(data, status) {
35 if (status != "success") {
36 $.log("Couldn't load data. status = %s", status);
37 return;
38 }
39
40 var temp_out = [];
41 var hum_out = [];
42 var wavg = [];
43 var wgust = [];
44 var rain = [];
45 var i, mint = 5, maxt = 35;
46 var l = data['idx'].length - 1;
47 var d = new Date();
48 var tzofs = d.getTimezoneOffset() * 60;
49 for (i = 0; i < l; i++) {
50 // Convert time from UTC to browser LT
51 t = data['idx'][i] - tzofs;
52 if (data['temp_out'] < mint)
53 mint = data['temp_out']
54 if (data['temp_out'] < maxt)
55 maxt = data['temp_out']
56 temp_out.push([t * 1000.0, data['temp_out'][i]]);
57 hum_out.push([t * 1000.0, data['hum_out'][i]]);
58 wavg.push([t * 1000.0, data['wind_ave'][i], wind2angle(data['wind_dir'][i])]);
59 wgust.push([t * 1000.0, data['wind_gust'][i], wind2angle(data['wind_dir'][i])]);
60 if (data['rain'][i] > 0)
61 rain.push([t * 1000.0, data['rain'][i]]);
62 }
63 $.plot($("#graph1"), [
64 { 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 } }
66 ],
67 { xaxis : { mode : 'time' },
68 legend : { backgroundOpacity : 0, position : 'nw' },
69 yaxis : { min : mint, max : maxt, tickFormatter : degCFormatter },
70 y2axis : { min : 0, max : 100, tickFormatter : pctFormatter }
71 });
72 $.plot($("#graph2"), [
73 { data : wavg, label: "Wind (Avg)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true },
74 { data : wgust, label: "Wind (Gust)", yaxis : 1, points : { show : true }, lines : { show : true }, direction : true },
75 { data : rain, label: "Rain", yaxis : 2, bars : { show : true, barWidth : 0.5 * 60 * 60 * 1000, align : "centre" } }
76 ],
77 { xaxis : { mode : 'time' },
78 legend : { backgroundOpacity : 0, position : 'nw' },
79 yaxis : { tickFormatter : spdFormatter },
80 y2axis : { min : 0, tickFormatter : mmFormatter }
81 });
82 }
83
84 function wind2angle(dir) {
85 var a = dir * (360.0 / 16.0);
86 return a;
87 }
88
89 function degCFormatter(v, axis) {
90 return v.toFixed(axis.tickDecimals) +"°C";
91 }
92
93 function pctFormatter(v, axis) {
94 return v.toFixed(axis.tickDecimals) +"%";
95 }
96
97 function spdFormatter(v, axis) {
98 return v.toFixed(axis.tickDecimals) + "kph";
99 }
100
101 function mmFormatter(v, axis) {
102 return v.toFixed(axis.tickDecimals) + "mm";
103 }
104
105 function update_data() {
106 jQuery.getJSON('iwws/getdata.json', draw_graph);
107 }
108
109 $(document).ready(function(){
110 update_data();
111 });