216 lines
6.1 KiB
JavaScript
216 lines
6.1 KiB
JavaScript
var urlParams = new URLSearchParams(window.location.search);
|
|
var deveui = urlParams.get('deveui');
|
|
var start = urlParams.get('start');
|
|
var stop = urlParams.get('stop');
|
|
var lon = urlParams.get('lon');
|
|
var lat = urlParams.get('lat');
|
|
var map;
|
|
|
|
if (start == null) {
|
|
var dstart = moment({hour: 0});
|
|
var start = dstart.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
|
}
|
|
|
|
if (stop == null) {
|
|
var dstop = moment();
|
|
var stop = dstop.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
|
}
|
|
|
|
var datapoints;
|
|
|
|
function refreshDatapoints(deveui, start, stop) {
|
|
range = ""
|
|
range = range + "&start=" + start;
|
|
range = range + "&stop=" + stop;
|
|
|
|
$.getJSON('https://wo-bisch.ch/metrics?deveui=' + deveui + range, function(mydata) {
|
|
if ("msg" in mydata) {
|
|
if (mydata.msg.includes("expired")) {
|
|
$('#chart').html(`<article class="message is-danger">
|
|
<div class="message-body">
|
|
Abo ist abgelaufen
|
|
</div>
|
|
</article>`);
|
|
} else if (mydata.msg.includes("error:")) {
|
|
$('#myselectors').hide();
|
|
$('#chart').html(`<article class="message is-danger">
|
|
<div class="message-body">
|
|
Fehler im Aufruf
|
|
</div>
|
|
</article>`);
|
|
} else {
|
|
location.reload(true);
|
|
}
|
|
return;
|
|
}
|
|
|
|
datapoints = mydata;
|
|
$('#datetimeslider').attr('max', mydata.length - 1);
|
|
$('#datetimeslider').val(mydata.length - 1);
|
|
var unix_timestamp = mydata[mydata.length - 1][0];
|
|
var date = new Date(unix_timestamp * 1000);
|
|
var myhtml = moment(date).format('DD.MM.YYYY HH:mm') + ' / ' + mydata[mydata.length - 1][3] + '% <i class="fa fa-battery-three-quarters"></i>';
|
|
$('#tooltiptext').html(myhtml);
|
|
});
|
|
}
|
|
|
|
function updateSlider(c)
|
|
{
|
|
if(c.value <= 50000)
|
|
{
|
|
if(c.step != 1)
|
|
c.step = 1;
|
|
//alert(c.value);
|
|
}
|
|
else
|
|
{
|
|
if(c.step != 3)
|
|
c.step = 3;
|
|
//alert(c.value);
|
|
}
|
|
}
|
|
|
|
|
|
$(document).ready(function() {
|
|
var position = ol.proj.fromLonLat([lon, lat], "EPSG:2056");
|
|
console.log("Document Ready Position:");
|
|
console.log(position);
|
|
|
|
var layer = ga.layer.create('ch.swisstopo.pixelkarte-farbe');
|
|
map = new ga.Map({
|
|
target: 'map',
|
|
layers: [layer],
|
|
view: new ol.View({
|
|
center: position,
|
|
resolution: 20
|
|
})
|
|
});
|
|
|
|
// Create the layer with the icon
|
|
var vectorLayer = new ol.layer.Vector({
|
|
source: new ol.source.Vector({
|
|
features: [new ol.Feature({
|
|
geometry: new ol.geom.Point(position)
|
|
})]
|
|
}),
|
|
style: new ol.style.Style({
|
|
image: new ol.style.Icon({
|
|
anchor: [0.5, 1],
|
|
anchorXUnits: 'fraction',
|
|
anchorYUnits: 'fraction',
|
|
src: '/static/images/marker.png'
|
|
})
|
|
})
|
|
});
|
|
map.addLayer(vectorLayer);
|
|
|
|
$('#reportrange span').html(moment(start).locale('de').format('D. MMM YYYY') + ' - ' + moment(stop).locale('de').format('D. MMM YYYY'));
|
|
|
|
refreshDatapoints(deveui,start,stop);
|
|
console.log("End of document ready...");
|
|
});
|
|
|
|
|
|
$(function() {
|
|
var start = moment({hour: 0});
|
|
var end = moment();
|
|
var s_start = start.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
|
var s_end = end.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
|
|
|
console.log("XXX: "+start.format());
|
|
|
|
function cb(start, end) {
|
|
$('#reportrange span').html(start.locale('de').format('D. MMM YYYY') + ' - ' + end.locale('de').format('D. MMM YYYY'));
|
|
console.log("A new date selection was made: " + start.format() + ' to ' + end.format());
|
|
s_start = start.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
|
s_end = end.utc().format('YYYY-MM-DDTHH:mm:ss[Z]');
|
|
console.log("Start: " + s_start + ' End: ' + s_end);
|
|
//drawGraph(deveui, alias, property, s_start,s_end, false);
|
|
refreshDatapoints(deveui, s_start, s_end);
|
|
}
|
|
|
|
$('#reportrange').daterangepicker({
|
|
startDate: start.local(),
|
|
endDate: end.local(),
|
|
regional: [ "de" ],
|
|
"locale": {
|
|
format: 'DD.MM.YYYY',
|
|
"separator": " - ",
|
|
"applyLabel": "Anwenden",
|
|
"cancelLabel": "Abbrechen",
|
|
"fromLabel": "Von",
|
|
"toLabel": "Bis",
|
|
customRangeLabel: 'Benutzerdefiniert',
|
|
"weekLabel": "W",
|
|
"daysOfWeek": [
|
|
"So",
|
|
"Mo",
|
|
"Di",
|
|
"Mi",
|
|
"Do",
|
|
"Fr",
|
|
"Sa"
|
|
],
|
|
"monthNames": [
|
|
"Jan",
|
|
"Feb",
|
|
"Mär",
|
|
"Apr",
|
|
"Mai",
|
|
"Jun",
|
|
"Jul",
|
|
"Aug",
|
|
"Sep",
|
|
"Okt",
|
|
"Nov",
|
|
"Dez"
|
|
],
|
|
"firstDay": 1
|
|
},
|
|
ranges: {
|
|
'Heute': [moment(), moment()],
|
|
'Gestern': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
|
'Letzte 7 Tage': [moment().subtract(6, 'days'), moment()],
|
|
'Letzte 30 Tage': [moment().subtract(29, 'days'), moment()],
|
|
'Diesen Monat': [moment().startOf('month'), moment().endOf('month')],
|
|
'Letzten Monat': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
|
|
}
|
|
}, cb);
|
|
|
|
//cb(start, end);
|
|
|
|
});
|
|
|
|
|
|
function updateSliderTooltip(c)
|
|
{
|
|
var unix_timestamp = datapoints[c.value][0];
|
|
var date = new Date(unix_timestamp * 1000);
|
|
var myhtml = moment(date).format('DD.MM.YYYY HH:mm') + ' / ' + datapoints[c.value][3] + '% <i class="fa fa-battery-three-quarters"></i>';
|
|
$('#tooltiptext').html(myhtml);
|
|
|
|
var position = ol.proj.fromLonLat([datapoints[c.value][2], datapoints[c.value][1]], "EPSG:2056");
|
|
|
|
console.log("updateSliderTooltip Position:");
|
|
console.log(position);
|
|
|
|
// Create the layer with the icon
|
|
var vectorLayer2 = new ol.layer.Vector({
|
|
source: new ol.source.Vector({
|
|
features: [new ol.Feature({
|
|
geometry: new ol.geom.Point(position)
|
|
})]
|
|
}),
|
|
style: new ol.style.Style({
|
|
image: new ol.style.Icon({
|
|
anchor: [0.5, 1],
|
|
anchorXUnits: 'fraction',
|
|
anchorYUnits: 'fraction',
|
|
src: '/static/images/marker.png'
|
|
})
|
|
})
|
|
});
|
|
map.addLayer(vectorLayer2);
|
|
|
|
}
|