3 archive_base="/meteo/archive";
4 current_base = "/meteo/graph";
6 var url = window.location.pathname;
8 if (url.startsWith(archive_base)) {
9 url = url.substr(archive_base.length);
12 var params = url.split('/');
15 var month = params[2];
17 var devid = params[4];
18 var sensor = params[5];
19 var param = params[6];
27 function composeUrl() {
28 url = window.location.protocol+"//"+window.location.host+archive_base+"/";
32 url = url + "/" + month;
34 url = url + "/" + day;
36 url = url + "/" + devid;
38 url = url + "/" + sensor;
40 url = url + "/" + param;
47 history.pushState({}, null, url);
50 function selectChange() {
51 new_year = document.getElementById("year").value;
52 new_month = document.getElementById("month").value;
53 new_day = document.getElementById("day").value;
54 sensor_id = document.getElementById("sensor").value.split(".");
55 new_devid = sensor_id[0];
56 new_sensor = sensor_id[1];
57 new_param = sensor_id[2];
58 if (year != new_year) {
61 } else if (month != new_month) {
64 } else if (day != new_day) {
67 } else if ((new_devid != devid) || (new_sensor != sensor) || (new_param != param)) {
76 function processDataset(dataset,devid,sensorname,paramname) {
77 var scale = properties["scale"][devid+"."+sensorname+"."+paramname]
80 for (idx in dataset) {
82 newRec.t = dataset[idx].t
83 newRec.y = dataset[idx].y * scale[0];
92 function drawGraph(graphData) {
94 document.getElementById("current").href = current_base+"/"+devid + "/" + sensor + "/" + param;
96 var div = document.getElementById("chartdiv");
97 var canvas = document.getElementById("chart");
99 canvas.width = div.style.width;
100 canvas.height = div.style.height;
102 var ctx = canvas.getContext('2d');
103 var color = Chart.helpers.color;
110 label: properties["names"][devid+"."+sensor+"."+param],
111 backgroundColor: color(properties["colors"][devid+"."+sensor+"."+param]).alpha(0.5).rgbString(),
112 borderColor: properties["colors"][devid+"."+sensor+"."+param],
113 data: processDataset(graphData,devid,sensor,param),
126 animationDuration: 0,
128 responsiveAnimationDuration: 0,
131 fontColor: properties["fonts"]["legend"]["color"],
132 fontSize: properties["fonts"]["legend"]["size"],
133 fontStyle: properties["fonts"]["legend"]["style"],
139 distribution: 'series',
141 fontColor: properties["fonts"]["axes"]["color"],
142 fontSize: properties["fonts"]["axes"]["size"],
143 fontStyle: properties["fonts"]["axes"]["style"],
149 labelString: properties["names"][sensor+"."+param],
150 fontColor: properties["fonts"]["axes"]["color"],
151 fontSize: properties["fonts"]["axes"]["size"],
152 fontStyle: properties["fonts"]["axes"]["style"],
159 var chart = new Chart(ctx, cfg);
162 function RefreshGraph() {
164 var req = new XMLHttpRequest();
166 req.onreadystatechange = function () {
167 if (this.readyState != 4) return;
168 if (this.status != 200) {
169 setTimeout(RefreshGraph,30000);
172 var graphData = JSON.parse(this.responseText);
173 drawGraph(graphData);
176 req.open("GET", urlbase+"get-archive/"+year+"/"+month+"/"+day+"/"+devid+"/"+sensor+"/"+param, true);
181 function GetProperties() {
182 var req = new XMLHttpRequest();
184 req.onreadystatechange = function () {
185 if (this.readyState != 4) return;
186 if (this.status != 200) {
187 setTimeout(GetProperties,30000);
190 properties = JSON.parse(this.responseText);
194 req.open("GET", urlbase+"props", true);
199 function fillSelector(id,data,value,nameFunc) {
201 var element = document.getElementById(id);
207 line = "<option value=\""+data[i]+"\">"+nameFunc(data[i])+"</option>"
209 line = "<option value=\""+data[i]+"\">"+data[i]+"</option>"
214 element.innerHTML = html;
216 element.value = value;
218 return element.value;
222 function GetYears() {
223 var req = new XMLHttpRequest();
225 req.onreadystatechange = function () {
226 if (this.readyState != 4) return;
227 if (this.status != 200) {
228 setTimeout(GetYears,30000);
231 years = JSON.parse(this.responseText);
232 year = fillSelector("year", years, year);
239 req.open("GET", urlbase+"years", true);
244 function GetMonths() {
245 var req = new XMLHttpRequest();
247 req.onreadystatechange = function () {
248 if (this.readyState != 4) return;
249 if (this.status != 200) {
250 setTimeout(GetMonths,30000);
253 months = JSON.parse(this.responseText);
254 month = fillSelector("month", months, month);
261 req.open("GET", urlbase+"months/"+year, true);
267 var req = new XMLHttpRequest();
269 req.onreadystatechange = function () {
270 if (this.readyState != 4) return;
271 if (this.status != 200) {
272 setTimeout(GetDays,30000);
275 days = JSON.parse(this.responseText);
276 day = fillSelector("day", days, day);
283 req.open("GET", urlbase+"days/"+year+"/"+month, true);
288 function SensorName(id) {
289 return properties["names"][id];
292 function GetSensors() {
293 var req = new XMLHttpRequest();
295 req.onreadystatechange = function () {
296 if (this.readyState != 4) return;
297 if (this.status != 200) {
298 setTimeout(GetSensors,30000);
301 sensors = JSON.parse(this.responseText);
302 if (devid && sensor && param) {
303 sensor_id = devid+"."+sensor+"."+param;
307 sensor_id = fillSelector("sensor", sensors, sensor_id, SensorName).split(".");
308 devid = sensor_id[0];
309 sensor = sensor_id[1];
310 param = sensor_id[2];
317 req.open("GET", urlbase+"sensors/"+year+"/"+month+"/"+day, true);
322 setTimeout(GetProperties,100);