";
} else {
return v;
}
}
},
},
legend: {
enabled: false,
layout: 'horizontal',
// verticalAlign: 'top',
borderWidth: 1,
align: 'center',
},
plotOptions: {
series: {
animation: false,
turboThreshold: 0,
marker: {
enabled: false,
}
},
},
// tooltip: {
// backgroundColor: "rgba(255,255,255,1)"
// }
};
return globObject;
}
/******************************************************
* calcWeekends
*
* Calulate the weekends. They are marked in the plot as
* lightgreen bands
* params:
* data array of dates
* isyear true, if data is year average
* return:
* object to be plotted
*******************************************************/
function calcWeekends(data, isyear) {
var weekend = [];
var oldDay = 8;
for (var i = 0; i < data.length; i++) {
let mom = moment(data[i]._id)
var day = mom.day();
var st = mom.startOf('day');
if (day != oldDay) {
if (day == 6) {
weekend.push({
color: 'rgba(169,235,158,0.4)',
from: st.valueOf(),
to: st.add(1, 'days').valueOf(),
zIndex: 0
})
} else if (day == 0) {
weekend.push({
color: 'rgba(169,235,158,0.4)',
from: st.valueOf(),
to: st.add(1, 'days').valueOf(),
zIndex: 0
})
}
oldDay = day;
}
}
return weekend;
}
/******************************************************
* calcDays
*
* Calulate the day borders. In week plot every day
* border is shown es darker gray vertical line
* params:
* data array of dates
* isyear true, if data is year average
* return:
* object to be plotted
*******************************************************/
function calcDays(data, isyear) {
var days = [];
if (data.length == 0) {
return days
}
let oldday = moment(data[0]._id).day();
for (var i = 0; i < data.length; i++) {
var m = moment(data[i]._id);
var tag = m.day()
if (tag != oldday) {
m.startOf('day');
days.push({color: 'lightgray', value: m.valueOf(), width: 1, zIndex: 2});
oldday = tag;
}
}
return days;
};
/******************************************************
* addSensorID2chart
*
* Plot the sensor number an name in the top center of
* chart
* params:
* chart chart, where to plot
* sensor whos number is to plot
* return:
* none
*******************************************************/
function addSensorID2chart(chart, sensor) {
let sn = (sensor.name.startsWith("Radiation")) ? sensor.name.substring(10) : sensor.name;
var sens = chart.renderer.label(
'Sensor: ' + sensor.sid + ' - ' + sn,
400, 55,
'text', 0, 0, true)
.css({
fontSize: '12pt',
'font-weight': 'bold',
})
.attr({
zIndex: 5,
}).add();
}
var noDataTafel1 = '' +
'Für heute liegen leider keine Daten vor!
Bitte den Sensor überprüfen!\'
' +
'
';
var noDataTafel2 = '' +
'Für den Zeitraum liegen leider keine Daten vor!
Bitte den Sensor überprüfen!\'
' +
'
';
/******************************************************
* calcMaxY
*
* Calculate the max of the data array. Return the
* value for max at yAxis (is max of data + 2/2 * max of data)
*
* params:
* values array with data
* return:
* object wih max of values and max for yAxis
*******************************************************/
function calcMaxY(values) {
let maxval = Math.max.apply(null, values);
return {maxY: maxval*2, maxVal: maxval};
}
/******************************************************
* PlotMonth_Geiger
*
* Plot the geiger values für the last 31 days
*
* params:
* datas object with the data to plot#
* live true => live-data
* return:
* none
*******************************************************/
function PlotMonth_Geiger(datas, live) {
let series1 = [];
let series2 = [];
let series3 = [];
let series4 = [];
var mx1 = [];
let data = datas.radiation.values;
let sensor = {sid: datas.radiation.sid, name: datas.radiation.sname};
if(data.length != 0) {
// data = data.slice(-32); // nur einen Monat auswählen
$.each(data, function (i) {
var dat = new Date(this._id).getTime(); // retrieve the date
series1.push([dat, this.uSvphAvg])
mx1.push(this.uSvphAvg);
});
txtMeldung = false;
} else {
txtMeldung = true;
}
let maxima = calcMaxY(mx1);
var options = createGlobObtions();
var dlt = moment(); // retrieve the date
dlt.subtract(31, 'd');
var localOptions = {
chart: {
type: 'column'
},
xAxis: {
plotBands: calcWeekends(data, true),
plotLines: calcDays(data, true),
max: moment().startOf('day').subtract(1, 'd').valueOf(),
min: dlt.valueOf(),
title: {
text: 'Datum',
},
minTickInterval: moment.duration(1, 'day').asMilliseconds(),
labels: {
formatter: function () {
return this.axis.defaultLabelFormatter.call(this);
}
},
},
tooltip: {
valueDecimals: 1,
backgroundColor: 0,
borderWidth: 0,
borderRadius: 0,
useHTML: true,
formatter: function () {
return '' +
moment(this.x).format("DD.MMM") + '
' +
'● ' +
this.series.name + ': ' +
Highcharts.numberFormat(this.y, 3) +
'
≙ Impulse pro Minute: ' + Highcharts.numberFormat(this.y*60/faktor, 0) + '
';
}
},
series: [
{
name: 'uSvph',
data: series1,
color: COLOR_30DAY,
},
],
plotOptions: {
series:
{
animation: false,
groupPadding: 0.1,
},
column: {
pointPadding: 0,
}
},
title: {
text: "Strahlung Tagesmittelwerte",
},
subtitle: {
text: 'Tagesmittelwerte jeweils von 0h00 bis 23h59'
},
}
let yAxis = [{
title: {
text: 'µSv/h',
style: {
color: 'red'
}
},
max: maxima.maxY,
min: 0,
gridLineColor: 'lightgray',
plotLines: [
{
color: 'blue', // Color value
value: maxima.maxVal, // Value of where the line will appear
width: 1, // Width of the line
label: {
useHTML: true,
text: 'max. Wert : ' + maxima.maxVal.toFixed(3) + ' µSv/h',
y: -10,
align: 'center',
style: {color: 'blue'},
},
zIndex: 8,
}],
},{
title: {
text: 'Impulse pro Minute',
useHTML: true,
},
opposite: true,
linkedTo: 0,
useHTML: true,
labels: {
formatter: function () {
let v = this.axis.defaultLabelFormatter.call(this);
let w = parseFloat(v);
let s = Math.round(w * 60 / faktor);
return s;
}
},
}
];
options.chart.zoomType = 'x';
options.yAxis=[];
options.yAxis[0] = yAxis[0];
if (faktor != 0) {
options.yAxis[1] = yAxis[1];
}
$.extend(true, options, localOptions);
// Do the PLOT
var ch = Highcharts.chart($('#placeholderFS_1')[0], options, function (chart) {
addSensorID2chart(chart, sensor);
if (txtMeldung == true) {
var labeText = "";
var errtext = chart.renderer.label(
noDataTafel2,
80,
120, 'rect', 0, 0, true)
.css({
fontSize: '18pt',
color: 'red'
})
.attr({
zIndex: 1000,
stroke: 'black',
'stroke-width': 2,
fill: 'white',
padding: 10,
}).add();
}
});
// ch.renderer.text("Sensor-Nr 141", 10, 10).add();
$('#loading').hide();
}
/******************************************************
* PlotDayWeek_Geiger
*
* Plot the geiger values für the last 31 days
*
* params:
* what 'oneday' or 'week'
* datas object with the data to plot#
* start starttime
* live true => live-data
* return:
* none
*******************************************************/
function PlotDayWeek_Geiger(what, datas, start, live) {
var series1 = [];
var series2 = [];
var series3 = [];
let mx = [];
// Arrays for Berechnung der Min, Max und Mittewerte über die kompletten 24h
var aktVal = {};
let dau = ' Minuten';
let avt = what == 'oneday' ? avgTimeD : avgTimeW;
if (avt >= 60) {
dau = (avt == 60) ? ' Stunde' : ' Stunden';
avt /= 60;
}
// Put values into the arrays
var cnt = 0;
let data1 = null;
var data = datas.radiation.values;
let avg48 = datas.radiation.avg48 == null ? null : datas.radiation.avg48.uSvphAvg;
let sensor = {sid:datas.radiation.sid, name:datas.radiation.sname}
if (datas.radiation1 != undefined) {
data1 = datas.radiation1.values;
}
if (data.length != 0) {
$.each(data, function (i) {
var dat = new Date(this._id).getTime();
series2.push([dat, this.uSvphAvg])
mx.push(this.uSvphAvg);
});
if ((data1 != null) && (data1.length != 0)) {
$.each(data1, function (i) {
var dat = new Date(this._id).getTime();
series1.push([dat, this.uSvphAvg])
});
}
if (what == 'oneday') {
// Aktuelle Werte speichern
aktVal['cpm'] = data[data.length - 1].cpmAvg;
aktVal['uSvph'] = data[data.length - 1].uSvphAvg;
// InfoTafel füllen
var infoTafel =
'' +
'| Aktuelle Werte | ' +
'
' +
'| cpm | ' + (aktVal.cpm).toFixed(0) + ' | ' +
'
' +
'| µSv/h | ' + (aktVal.uSvph).toFixed(2) + ' | ';
'
' +
'';
}
txtMeldung = false;
} else {
txtMeldung = true;
}
// Plot-Options
var options = createGlobObtions();
var series_mavg = {
name: `${movingAVG ? 'gleit. ' : ''}Mittelwert über ${avt} ${dau}`,
type: ((what == 'oneweek') && !movingAVG) ? 'column' : 'line',
data: series2,
color: (what == 'oneweek') ? COLOR_7DAY : COLOR_24H_MAVG,
yAxis: 0,
zIndex: 1,
marker: {
enabled: false,
symbol: 'circle',
},
visible: true,
};
var series_uSvph = {
name: 'alle Werte',
type: 'line',
data: series1,
color: COLOR_24H_LIVE,
yAxis: 0,
zIndex: 1,
marker: {
enabled: false,
radius: 2,
symbol: 'circle',
},
visible: true,
// zones: avg48 != null ? [{
// value: avg48-(avg48*(bandgaprange/100)),
// color: COLOR_OUTOFBAND
// },{
// value: avg48+(avg48*(bandgaprange/100)),
// color: COLOR_24H_LIVE
// },{
// color: COLOR_OUTOFBAND
// }] : [],
};
let maxy = calcMaxY(mx);
var yAxis_cpm = [{ // 1
title: {
text: 'µSv/h',
style: {
color: 'red'
}
},
plotLines: avg48 != null ? [
{
color: COLOR_48HMEAN, // Color value
value: avg48, // Value of where the line will appear
width: 2, // Width of the line
label: {
useHTML: true,
text: `Mittelwert der letzten ${bandgapvalue}h ab jetzt ( ${avg48.toFixed(3)} µSv/h)`,
y: -10,
align: 'center',
style: {color: COLOR_48HMEAN},
},
zIndex: 8,
},{
color: COLOR_BANDGAP, // Color value
value: avg48+(avg48*(bandgaprange/100)), // Value of where the line will appear
width: 1, // Width of the line
label: {
useHTML: true,
text: `+${bandgaprange}%`,
y: -10,
align: 'center',
style: {color: COLOR_BANDGAP},
},
zIndex: 8,
},{
color: COLOR_BANDGAP, // Color value
value: avg48-(avg48*(bandgaprange/100)), // Value of where the line will appear
width: 1, // Width of the line
label: {
useHTML: true,
text: `-${bandgaprange}%`,
y: +15,
align: 'center',
style: {color: COLOR_BANDGAP},
},
zIndex: 8,
}] : [],
// min: 0,
// max: maxy.maxval,
// tickAmount: 11,
useHTML: true,
},{
title: {
text: 'Impulse pro Minute',
style: {
color: 'red'
}
},
linkedTo: 0,
useHTML: true,
opposite: true,
labels: {
formatter: function () {
let v = this.axis.defaultLabelFormatter.call(this);
let w = parseFloat(v);
let s = Math.round(w * 60 / faktor);
return s;
}
},
}];
options.tooltip =
{
valueDecimals: 1,
backgroundColor: 0,
borderWidth: 0,
borderRadius: 0,
useHTML: true,
formatter: function () {
return '' +
moment(this.x).format("DD.MMM, HH:mm") + ' Uhr
' +
'● ' +
this.series.name + ': ' +
Highcharts.numberFormat(this.y, 3) +
'
≙ Impulse pro Minute: ' + Highcharts.numberFormat(this.y*60/faktor, 0) + '
';
}
};
options.series = [];
options.yAxis = [];
if (what == 'oneday') {
options.series[0] = series_uSvph;
options.series[1] = series_mavg;
} else {
options.series[0] = series_mavg;
}
options.title.text = 'Strahlung über einen Tag';
options.subtitle.text = 'Impulse pro Minute (bzw. µSv pro Stunde)';
options.yAxis[0] = yAxis_cpm[0];
if (faktor != 0) {
options.yAxis[1] = yAxis_cpm[1];
}
options.chart.zoomType = 'x';
if (what == 'oneweek') {
options.plotOptions = {
column: {
pointPadding: 0.1,
borderWidth: 0,
groupPadding: 0,
shadow: false
}
};
options.title.text = 'Strahlung über eine Woche';
options.subtitle.text = `${movingAVG ? 'Gleitender ' : ''}Mittelwert über ${avt} ${dau}`;
options.xAxis.tickInterval = 3600 * 6 * 1000;
options.xAxis.plotBands = calcWeekends(data, false);
options.xAxis.plotLines = calcDays(data, false);
var dlt = start.clone();
options.xAxis.max = dlt.valueOf();
dlt.subtract(7, 'd');
options.xAxis.min = dlt.valueOf();
options.yAxis[0].plotLines = [];
// options.series[0].zones = [];
} else {
options.legend = {
enabled: true,
layout: 'horizontal',
borderWidth: 1,
align: 'center',
};
if (!showbandgap) {
options.yAxis[0].plotLines = [];
// options.series[0].zones = [];
}
dlt = start.clone();
if (live) {
options.xAxis.max = dlt.valueOf();
dlt.subtract(1, 'd');
options.xAxis.min = dlt.valueOf();
} else {
if (specialDate == 'silvester17') {
dlt = moment("2017-12-31T11:00:00Z");
} else if (specialDate == 'silvester18') {
dlt = moment("2018-12-31T11:00:00Z");
}
options.xAxis.min = dlt.valueOf();
dlt.add(1, 'd');
options.xAxis.max = dlt.valueOf();
}
}
let infoOffset = OSName == "Macintosh" ? 74 : OSName == "Windows" ? 80 : OSName == "iOS" ? 75 : 74;
let navx = gbreit-300;
let navy = 20;
let navbreit = 55;
let chr;
if (what == 'oneweek') {
let navtxt = ['-7d', '-3d', 'live', '+3d', '+7d'];
let navtime = [-7 * 24, -3 * 24, 0, 3 * 24, 7 * 24];
chr = Highcharts.chart($('#placeholderFS_1')[0], options, function (chart) {
addSensorID2chart(chart, sensor);
for (let i = 0; i < navtxt.length; i++) {
renderPfeil(i, chart, navx + (i * navbreit), navy, navtxt[i], navtime[i]);
}
if (txtMeldung == true) {
var labeText = "";
var errtext = chart.renderer.label(
noDataTafel2,
80,
120, 'rect', 0, 0, true)
.css({
fontSize: '18pt',
color: 'red'
})
.attr({
zIndex: 1000,
stroke: 'black',
'stroke-width': 2,
fill: 'white',
padding: 10,
}).add();
}
});
} else {
let navtxt = ['-24h', '-12h', 'live', '+12h', '+24h'];
let navtime = [-24, -12, 0, 12, 24];
chr = Highcharts.chart($('#placeholderFS_1')[0], options, function (chart) {
addSensorID2chart(chart, sensor);
console.log(`ChartHeigt: ${chart.chartHeight}`);
chart.renderer.label(
infoTafel,
7,
chart.chartHeight-infoOffset, 'rect', 0, 0, true, false)
.css({
fontSize: '10pt',
color: 'green'
})
.attr({
zIndex: 5,
}).add();
for (let i = 0; i < navtxt.length; i++) {
renderPfeil(i, chart, navx + (i * navbreit), navy, navtxt[i], navtime[i]);
}
if (txtMeldung == true) {
var labeText = "";
var errtext = chart.renderer.label(
noDataTafel1,
80,
120, 'rect', 0, 0, true)
.css({
fontSize: '18pt',
color: 'red'
})
.attr({
zIndex: 1000,
stroke: 'black',
'stroke-width': 2,
fill: 'white',
padding: 10,
}).add();
}
});
}
$('#loading').hide();
}
// ************************************************************
// Plot BME280
function PlotDayWeek_BME280(what, datas, start, live) {
let series1 = [];
let series2 = [];
let series3 = [];
let mx1 = [];
let mx3 = [];
// Arrays for Berechnung der Min, Max und Mittewerte über die kompletten 24h
var aktVal = {};
// Put values into the arrays
var cnt = 0;
var data = datas.climate.values;
let sensor = {sid:datas.climate.sid, name:datas.climate.sname}
if (data.length != 0) {
$.each(data, function (i) {
var dat = new Date(this._id).getTime();
series1.push([dat, this.tempAvg])
mx1.push(this.tempAvg);
series2.push([dat, this.humiAvg])
if(this.pressSeaAvg != null) {
series3.push([dat, this.pressSeaAvg/100])
mx3.push(this.pressSeaAvg/100);
}
});
if (what == 'oneday') {
// Aktuelle Werte speichern
aktVal['temperature'] = data[data.length - 1].tempAvg;
aktVal['humidity'] = data[data.length - 1].humiAvg;
aktVal['pressure'] = data[data.length - 1].pressSeaAvg/100;
// InfoTafel füllen
var infoTafel =
'' +
'| Aktuelle Werte | ' +
'
' +
'| Temperatur | ' + (aktVal.temperature).toFixed(1) + ' | ' + '°C | ' +
'
' +
'| Feuchte | ' + (aktVal.humidity).toFixed(0) + ' | ' + '% | ' +
'
' +
'| Luftdruck | ' + (aktVal.pressure).toFixed(0) + ' | ' + 'hPa | ' +
'
' +
'';
}
txtMeldung = false;
} else {
txtMeldung = true;
}
// Plot-Options
var options = createGlobObtions();
var series_temp = {
name: 'Temperatur',
type: 'line',
// type: ((what == 'oneweek') && !movingAVG) ? 'column' : 'spline',
data: series1,
color: 'red',
// color: (what == 'oneweek') ? 'green' : 'red',
yAxis: 0,
zIndex: 1,
marker: {
enabled: false,
// enabled: what == 'oneweek' ? false : true,
symbol: 'circle',
},
visible: true,
};
var series_humi = {
name: 'Feuchte',
type: 'line',
// type: ((what == 'oneweek') && !movingAVG) ? 'column' : 'spline',
data: series2,
color: '#946CBD',
// color: (what == 'oneweek') ? 'green' : 'red',
yAxis: 1,
zIndex: 1,
marker: {
enabled: false,
// enabled: what == 'oneweek' ? false : true,
symbol: 'circle',
},
visible: true,
};
var series_press = {
name: 'Luftdruck (normiert auf NN)',
type: 'line',
// type: ((what == 'oneweek') && !movingAVG) ? 'column' : 'spline',
data: series3,
color: '#DA9E24',
// color: (what == 'oneweek') ? 'green' : 'red',
yAxis: 2,
zIndex: 1,
marker: {
enabled: false,
// enabled: what == 'oneweek' ? false : true,
symbol: 'circle',
},
visible: true,
};
// Check min/max of temp to arrange y-axis
let tmi = Math.min(...mx1);
let tma = Math.max(...mx1);
let loty = tmi - 2;
let hity = tma + 2;
var yAxis_temp = { // 1
title: {
text: 'T °C',
style: {
color: 'red'
},
align: 'high',
offset: 0,
rotation: 0,
y: -15
},
min: loty,
max: hity,
opposite: true,
tickAmount: 11,
useHTML: true,
};
var yAxis_hum = {
title: { // 2
text: 'F %',
style: {
color: '#946CBD',
},
align: 'high',
offset: 10,
rotation: 0,
y: -15,
},
min: 0,
max: 100,
gridLineColor: 'lightgray',
opposite: true,
tickAmount: 11,
};
// Check min/max of press to arrange y-axis
let pmi = Math.min(...mx3);
let pma = Math.max(...mx3);
let mid = (pmi+pma) / 2;
let lopy = mid - 30;
let hipy = mid + 30;
var yAxis_press = { // 3
title: {
text: 'D hPa',
style: {
color: '#DA9E24',
},
align: 'high',
offset: 10,
rotation: 0,
y: -15,
},
gridLineColor: 'lightgray',
min: lopy,
max: hipy,
opposite: true,
tickAmount: 11,
};
options.tooltip =
{
valueDecimals: 1,
backgroundColor: 0,
borderWidth: 0,
borderRadius: 0,
useHTML: true,
formatter: function () {
return '' +
moment(this.x).format("DD.MMM, HH:mm") + ' Uhr
' +
'● ' +
this.series.name + ': ' +
Highcharts.numberFormat(this.y, 3) +
'
';
}
};
options.series = [];
options.yAxis = [];
options.series[0] = series_temp;
options.series[1] = series_humi;
options.series[2] = series_press;
options.title.text = 'Temperatur / Feuchte / Luftdruck über 1 Tag';
options.subtitle.text = 'Mittelwerte über jeweils 10min';
// options.series[2] = series_LAMax;
// options.yAxis[2] = yAxis_LAMin;
options.yAxis[0] = yAxis_temp;
options.yAxis[1] = yAxis_hum;
options.yAxis[2] = yAxis_press;
options.chart.zoomType = 'x';
options.chart.spacingBottom = 40;
options.legend = {
enabled: true,
layout: 'horizontal',
borderWidth: 1,
align: 'center',
};
if (what == 'oneweek') {
options.plotOptions = {
column: {
pointPadding: 0.1,
borderWidth: 0,
groupPadding: 0,
shadow: false
}
};
options.title.text = 'Temperatur / Feuchte / Luftdruck über 1 Woche';
options.subtitle.text = 'Mittelwerte über jeweils 10min';
options.xAxis.tickInterval = 3600 * 6 * 1000;
options.xAxis.plotBands = calcWeekends(data, false);
options.xAxis.plotLines = calcDays(data, false);
var dlt = start.clone();
options.xAxis.max = dlt.valueOf();
dlt.subtract(7, 'd');
options.xAxis.min = dlt.valueOf();
} else {
dlt = start.clone();
if (live) {
options.xAxis.max = dlt.valueOf();
dlt.subtract(1, 'd');
options.xAxis.min = dlt.valueOf();
} else {
if (specialDate == 'silvester17') {
dlt = moment("2017-12-31T11:00:00Z");
} else if (specialDate == 'silvester18') {
dlt = moment("2018-12-31T11:00:00Z");
}
options.xAxis.min = dlt.valueOf();
dlt.add(1, 'd');
options.xAxis.max = dlt.valueOf();
}
}
let navx = gbreit-300;
let navy = 20;
let navbreit = 55;
let chr;
if (what == 'oneweek') {
chr = Highcharts.chart($('#placeholderBME')[0], options, function (chart) {
addSensorID2chart(chart, sensor);
if (txtMeldung == true) {
var labeText = "";
var errtext = chart.renderer.label(
noDataTafel2,
80,
120, 'rect', 0, 0, true)
.css({
fontSize: '18pt',
color: 'red'
})
.attr({
zIndex: 1000,
stroke: 'black',
'stroke-width': 2,
fill: 'white',
padding: 10,
}).add();
}
});
} else {
chr = Highcharts.chart($('#placeholderBME')[0], options, function (chart) {
addSensorID2chart(chart, sensor);
chart.renderer.label(
infoTafel,
7,
chart.chartHeight-94, 'rect', 0, 0, true)
.css({
fontSize: '8pt',
color: 'green'
})
.attr({
zIndex: 5,
}).add();
if (txtMeldung == true) {
var labeText = "";
var errtext = chart.renderer.label(
noDataTafel1,
80,
120, 'rect', 0, 0, true)
.css({
fontSize: '18pt',
color: 'red'
})
.attr({
zIndex: 1000,
stroke: 'black',
'stroke-width': 2,
fill: 'white',
padding: 10,
}).add();
}
});
}
$('#loading').hide();
}
function renderPfeil(n, chart, x, y, txt, time) {
chart.renderer.button(txt, x, y, null, butOpts[0], butOpts[1], butOpts[2], butOpts[3])
.attr({
id: 'button' + n,
zIndex: 3,
width: 30,
})
.on('click', function () {
prevHour(time);
})
.add();
}
function prevHour(hours) {
console.log("Zurück um ", hours, "Stunden");
let start;
if (startDay == "") {
start = moment();
start.subtract(24, 'h');
} else {
start = moment(startDay);
}
let mrk = moment();
mrk.subtract(24, 'h');
startDay = "";
if (hours < 0) {
start.subtract(Math.abs(hours), 'h');
startDay = start.format("YYYY-MM-DDTHH:mm:ssZ");
} else if (hours > 0) {
start.add(hours, 'h');
if (!start.isAfter(mrk)) {
startDay = start.format("YYYY-MM-DDTHH:mm:ssZ");
}
}
doPlot(active, startDay, properties);
}
// Umrechnung Koordinaten auf Adresse
function geocodeLatLng(latlon) {
geocod.geocode({'location': latlon}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
for (var i = 0; i < results.length; i++) {
console.log(results[i].formatted_address)
}
console.log("DAS ist GUT:", results[2].formatted_address);
} else {
window.alert('Geocoder failed due to: ' + status);
}
});
}
async function getCoords(city) {
return $.getJSON('/mapdata/getcoord', {city: city})
.fail((jqxhr, textStatus, error) => null)
.done(docs => docs);
}
// Map auf Stadt setzen
async function setCenter(adr) {
try {
let data = await getCoords(adr);
map.setView([parseFloat(data.lat), parseFloat(data.lon)]);
console.log(data);
return true;
} catch (e) {
showError(4,"Town not found",adr);
console.log(e);
return false;
}
}
// Aktuelle Daten vom Server holen
function fetchAktualData(box) {
let bnds = null;
if (box != null) {
bnds = [
[box.getWest(), box.getSouth()],
[box.getEast(), box.getNorth()]
];
}
return $.getJSON('/mapdata/getaktdata', {box: bnds})
.fail((jqxhr, textStatus, error) => {
// alert("fetchAktualData: Fehler " + error); // if error, show it
return [];
})
.done(docs => docs);
}
// Aktuelle Daten vom Server holen
function fetchAKWData(box) {
let bnds = null;
if (box != null) {
bnds = [
[box.getWest(), box.getSouth()],
[box.getEast(), box.getNorth()]
];
}
return $.getJSON('/mapdata/getakwdata', {box: bnds})
.fail((jqxhr, textStatus, error) => {
// alert("fetchAKWData: Fehler " + error); // if error, show it
return [];
})
.done(docs => docs);
}
function fetchStuttgartBounds() {
let points = [];
$.ajax({
type: "GET",
url: "/mapdata/getStuttgart",
dataType: "xml",
success: function (xml) {
$(xml).find("rtept").each(function () {
var lat = parseFloat($(this).attr("lat"));
var lon = parseFloat($(this).attr("lon"));
var p = [lat, lon];
points.push(p);
});
L.polyline(points).addTo(map);
}
});
}
// Mit dem Array 'mongoPoints' aus der properties-Datenbank ALLe Sensor-IDs holen,
// die innerhalb (d.h. in Stuttgart) liegen.
function findStuttgartSensors() {
let mp = JSON.stringify(mongoPoints);
$.get('/mapdata/regionSensors', {points: mp}, function (data1, err) { // JSON-Daten vom Server holen
if (err != 'success') {
alert("Fehler
" + err); // ggf. fehler melden
} else {
console.log('Stuttgarter Sensoren:', data1);
let se = JSON.stringify(data1);
$.get('/mapdata/storeSensors', {sensors: se}, function (d, e) {
if (e != 'success') {
alert("Fehler beim Speichern der Region-Sensoren");
} else {
console.log("Sensoren gespeichert");
}
});
}
});
}
// fetch coordinates for selected sensor
// use the API
function getSensorKoords(csens) {
let p = new Promise(function (resolve, reject) {
// let url = 'https://feinstaub.rexfue.de/api/getprops?sensorid='+csens;
let url = '/api/getprops?sensorid=' + csens;
$.get(url, (data, err) => {
if (err != 'success') {
resolve({err: 'not found', lat: 48.784373, lng: 9.182});
} else {
// console.log(data);
if ((data.values.length == 0) || ((data.values[0].lat==0) && (data.values[0].lon==0))){
resolve({err: 'not found', lat: 48.780045, lng: 9.182646});
} else {
if (!data.values[0].typ.startsWith("Radiation")) {
resolve({err: 'wrong type', lat: 48.780045, lng: 9.182646});
} else {
resolve({err: null, lat: data.values[0].lat, lng: data.values[0].lon});
}
}
}
});
});
return p;
}
function showGrafik(sid) {
active = 'oneday';
$.getJSON('fsdata/getfs/korr', {sensorid: sid}, function (data, err) { // AJAX Call
if (err != 'success') {
alert("Fehler
" + err); // if error, show it
} else {
if ((data == null) || (data.length == 0)) {
showError(2, "No property data for ", sid);
return -1;
} else {
if (!data.name.startsWith('Radia')) {
showError(3, "This is no Radiation-Sensor", aktsensorid);
return -1;
}
}
properties = data;
// save coordinates in localStorage
localStorage.setItem('geiger_curcoord', JSON.stringify(data.location[0].loc.coordinates));
let breit = $(window).width();
gbreit = breit * 0.8;
let marg = (breit-gbreit)/2;
$('#overlay').css('width', gbreit);
$('#overlay').css('margin-left',marg);
$('#overlay').show();
grafikON = true;
doPlot(active, startDay, data); // Start with plotting one day from now on
$('#btnset').show();
}
});
}
async function onMarkerClick(e, click) {
let item = e.target.options;
clickedSensor = item.name;
let addr = "Adresse";
let sensortyp = "Radiation-.Typ"
// try {
// let ret = await $.get("api/getprops?sensorid=" + item.name);
// addr = ret.values[0].address.street + " " + ret.values[0].address.plz + " " + ret.values[0].address.city;
// sensortyp = ret.values[0].typ;
// } catch (e) {
// console.log("onMarker - getpops", e)
// }
// console.log("addr:", addr);
popuptext = '