weather.js
4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
[data_[0].fields :
cloud: null
global_status: "OK"
humidity: 0
pressure: null
rain: 0
temperature: 7
updated: "2019-01-09T09:44:04.702"
wind: 1.44
wind_dir: "193.00"
*/
var sync_plots = {
humidity_plot : new PlotterClas("humidity", "humidity_plot", [0,80]),
pressure_plot : new PlotterClas("pressure", "pressure_plot", []),
rain_plot : new PlotterClas("rain", "rain_plot", []),
temperature_plot : new PlotterClas("temperature", "temperature_plot", []),
wind_plot : new PlotterClas("wind", "wind_plot", [0,80]),
wind_dir_plot : new PlotterClas("wind_dir", "wind_dir_plot", []),
}
var sync_weather = {
//
set_data: function(data_) {
//See data_: http://127.0.0.1:5030/eicdata/ajax/?&action=data_state&id=2016-12-01
//if (data_.ACK) {
var res = sync_weather.tuned_state(data_, ' ');
document.getElementById('plc').innerHTML = res;
var res = sync_weather.tuned_weather(data_, ' ');
document.getElementById('global').innerHTML = res;
//var res = sync_weather.object_to_tree(data_, ' ');
//document.getElementById('refresh').innerHTML = res;
sync_plots.humidity_plot.refresh_list([data_[0].fields.updated , data_[0].fields.humidity]);
sync_plots.pressure_plot.refresh_list([data_[0].fields.updated , data_[0].fields.pressure]);
sync_plots.rain_plot.refresh_list([data_[0].fields.updated , data_[0].fields.rain]);
sync_plots.temperature_plot.refresh_list([data_[0].fields.updated , data_[0].fields.temperature]);
sync_plots.wind_plot.refresh_list([data_[0].fields.updated , data_[0].fields.wind]);
sync_plots.wind_dir_plot.refresh_list([data_[0].fields.updated , data_[0].fields.wind_dir]);
//}
},
tuned_state: function(data) {
data = data[0];
res ='<h4>PLC</h4>'
res +='<table>';
if (data.is_safe == true) {
res += sync_weather.get_success("is_safe", data.is_safe);
} else {
res += sync_weather.get_warning("is_safe", data.is_safe);
}
res += sync_weather.get_success("plc_mode", data.plc_mode);
res += sync_weather.get_success("plc_timeout", data.plc_timeout);
res += "</table>";
return res
},
tuned_weather: function(data) {
data = data[0].fields;
res ='<h4>Weather</h4>'
res +='<table>';
if (data.global_status == "OK") {
res += sync_weather.get_success("global_status", data.global_status);
} else {
res += sync_weather.get_warning("global_status", data.global_status);
}
res += sync_weather.get_success("updated", data.updated);
res += sync_weather.get_success("humidity", data.humidity);
res += sync_weather.get_success("pressure", data.pressure);
res += sync_weather.get_success("rain", data.rain);
res += sync_weather.get_success("temperature", data.temperature);
res += sync_weather.get_success("wind", data.wind);
res += sync_weather.get_success("wind_dir", data.wind_dir);
res += "</table>";
return res
},
// alert alert-success
get_success: function(name, value) {return '<tr class="alert alert-info"><th scope="row">'+name+': </th><td>'+value+'</td></tr>';},
get_warning: function(name, value) {return '<tr class="alert alert-warning"><th scope="row">'+name+': </th><td>'+value+'</td></tr>';},
setTimeout:function(){
//alert("change");
Async.status.timeout = document.getElementById('timer_select').value * 1000;
},
object_to_tree: function(argObject, level) {
var msg = '';
for (var propertyName in argObject) {
if (typeof argObject[propertyName] == 'object'){
msg += '<p>' + level + propertyName + ': (' + typeof argObject[propertyName] + ')</p>';
msg += this.object_to_tree(argObject[propertyName], level + '-- ');
} else if (typeof argObject[propertyName] == 'function'){
msg += '<p>' + level + propertyName + ': (' + typeof argObject[propertyName] + ')</p>';
} else {
msg += '<p>' + level + propertyName + ': (' + typeof argObject[propertyName] + ') <span class=\"fld\">' + argObject[propertyName] + '</span></p>';
}
}
return msg
}
}