*** WIP WIP *** woks now for live and havg
This commit is contained in:
+23
-17
@@ -4,11 +4,9 @@
|
||||
import {returnOnError} from "../utilities/reporterror.js";
|
||||
import { getActData, getAvgData, getLongAvg, fetchFromInflux, calcRange} from "../actions/getsensorData.js"
|
||||
import checkParams from "../utilities/checkparams.js";
|
||||
import {getOneProperty} from "../actions/getproperties.js";
|
||||
import * as ERR from "../utilities/errortexts.js"
|
||||
import {DateTime} from 'luxon'
|
||||
import {getData4map} from "../actions/data4map.js";
|
||||
import {NODATA} from "../utilities/errortexts.js";
|
||||
import * as noiseChart from "./noiseChart.js";
|
||||
|
||||
const setoptionfromtable = (opt,tabval) => {
|
||||
let ret = opt
|
||||
@@ -25,6 +23,7 @@ export const getNoiseData = async (params, possibles, props) => {
|
||||
let {opts, err} = checkParams(params, {
|
||||
mandatory:[
|
||||
{name:'sensorid', type: 'int'},
|
||||
{name:'chart', type: 'bool'},
|
||||
],
|
||||
optional: possibles
|
||||
})
|
||||
@@ -44,6 +43,9 @@ export const getNoiseData = async (params, possibles, props) => {
|
||||
opts.start = start
|
||||
opts.stop = stop
|
||||
let erg = await x.func(opts) // get the data
|
||||
if (opts.chart) {
|
||||
return erg
|
||||
}
|
||||
ret = {
|
||||
err: erg.err,
|
||||
sid: opts.sensorid,
|
||||
@@ -92,8 +94,12 @@ export const getNoiseData = async (params, possibles, props) => {
|
||||
// ....
|
||||
//
|
||||
// *********************************************
|
||||
const getLiveData = async (opt) => {
|
||||
return await getActData(opt)
|
||||
const getLiveData = async (opts) => {
|
||||
const erg = await getActData(opts)
|
||||
if (!opts.chart || erg.err) {
|
||||
return erg
|
||||
}
|
||||
return noiseChart.liveData(opts, erg.values)
|
||||
}
|
||||
|
||||
|
||||
@@ -135,9 +141,10 @@ const gethavgData = async (opts, props) => {
|
||||
}
|
||||
}
|
||||
return csvStr
|
||||
} else {
|
||||
} else if (!opts.chart || erg.err) {
|
||||
return {err: erg.err, values: erg.values}
|
||||
|
||||
} else {
|
||||
return noiseChart.havgData(opts, erg.values)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,16 +420,6 @@ const getAPIprops = (opt) => {
|
||||
|
||||
}
|
||||
|
||||
const whatTable = [
|
||||
{'what':'live', 'span': 1, 'daystart': false, peak: false, 'func': getLiveData},
|
||||
{'what':'havg', 'span': 7, 'daystart': true, peak: true, 'func': gethavgData},
|
||||
{'what':'davg', 'span': 30, 'daystart': true, peak: true, 'func': getdavgData},
|
||||
{'what':'daynight', 'span': 30, 'daystart': true, peak: false, 'func': getdaynightData},
|
||||
{'what':'lden', 'span': 30, 'daystart': true, peak: false, 'func': getLdenData},
|
||||
{'what':'props', 'span': 0, 'daystart': true, peak:false, 'func': getAPIprops},
|
||||
];
|
||||
|
||||
|
||||
const getNoiseAVGData = async (opts) => {
|
||||
let ret = {err: null, values: []}
|
||||
let emptyValues = {n_AVG:-1}
|
||||
@@ -506,3 +503,12 @@ peak = data
|
||||
return { err: ret.err, values: hoursArr}
|
||||
}
|
||||
|
||||
const whatTable = [
|
||||
{'what':'live', 'span': 1, 'daystart': false, peak: false, 'func': getLiveData},
|
||||
{'what':'havg', 'span': 7, 'daystart': true, peak: true, 'func': gethavgData},
|
||||
{'what':'davg', 'span': 30, 'daystart': true, peak: true, 'func': getdavgData},
|
||||
{'what':'daynight', 'span': 30, 'daystart': true, peak: false, 'func': getdaynightData},
|
||||
{'what':'lden', 'span': 30, 'daystart': true, peak: false, 'func': getLdenData},
|
||||
{'what':'props', 'span': 0, 'daystart': true, peak:false, 'func': getAPIprops},
|
||||
];
|
||||
|
||||
|
||||
@@ -1,2 +1,273 @@
|
||||
// Prepare all data to plt the charts
|
||||
// Prepare all data to plot the charts
|
||||
import * as utils from '../utilities/chartoptions.js'
|
||||
|
||||
export const liveData = (params, values) => {
|
||||
let series1 = []
|
||||
let series2 = []
|
||||
let series3 = []
|
||||
|
||||
// save the current (actual) values here
|
||||
let aktVal = {}
|
||||
|
||||
|
||||
// Put values into the arrays
|
||||
let cnt = 0
|
||||
values.forEach((x) => {
|
||||
let dat = new Date(x.datetime).getTime()
|
||||
series1.push([dat, x.noise_LAeq])
|
||||
series2.push([dat, x.noise_LA_max])
|
||||
series3.push([dat, x.noise_LA_min]) // put data and value into series array
|
||||
})
|
||||
|
||||
if (values.length != 0) {
|
||||
const lastidx = values.length - 1
|
||||
// Aktuelle Werte speichern
|
||||
aktVal['LAeq'] = values[lastidx].noise_LAeq
|
||||
aktVal['LAMax'] = values[lastidx].noise_LA_max
|
||||
aktVal['LAMin'] = values[lastidx].noise_LA_min
|
||||
|
||||
// InfoTafel füllen
|
||||
let infoTafel =
|
||||
'<table class="infoTafel"><tr >' +
|
||||
'<th colspan="3">Aktuelle Werte</th>' +
|
||||
'</tr><tr>' +
|
||||
'<td>LAeq</td><td>' + (aktVal.LAeq).toFixed(1) + '</td><td>dbA</td>'
|
||||
infoTafel +=
|
||||
'</tr><tr>' +
|
||||
'<td>LAmin</td><td>' + (aktVal.LAMin).toFixed(0) + '</td><td>dbA</td>'
|
||||
infoTafel +=
|
||||
'</tr><tr>' +
|
||||
'<td>LAmax</td><td>' + (aktVal.LAMax).toFixed(0) + '</td><td>dbA</td>'
|
||||
infoTafel +=
|
||||
'</tr></table>' +
|
||||
'</div>'
|
||||
}
|
||||
let txtMeldung = false
|
||||
|
||||
|
||||
// Plot-Options
|
||||
let options = utils.createGlobObtions('dd.LL HH:mm:ss')
|
||||
|
||||
let series_LAeq = {
|
||||
name: 'LAeq',
|
||||
data: series1,
|
||||
color: utils.colors.eq,
|
||||
yAxis: 0,
|
||||
zIndex: 1,
|
||||
marker: {
|
||||
enabled: false,
|
||||
symbol: 'square',
|
||||
},
|
||||
visible: true,
|
||||
fillColor: {
|
||||
linearGradient: [0, 600, 0, 0],
|
||||
stops: [
|
||||
[0, 'rgb(238,223,236)'],
|
||||
[1, 'rgb(238,223,236)']
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
let series_LAMax = {
|
||||
name: 'LAmax',
|
||||
data: series2,
|
||||
color: utils.colors.max,
|
||||
yAxis: 0,
|
||||
zIndex: 0,
|
||||
marker: {
|
||||
enabled: false,
|
||||
symbol: 'square',
|
||||
},
|
||||
visible: true,
|
||||
fillColor: {
|
||||
linearGradient: [0, 600, 0, 0],
|
||||
stops: [
|
||||
[0, 'rgb(255,233,236)'],
|
||||
[1, 'rgb(255,233,236)']
|
||||
]
|
||||
},
|
||||
// fillOpacity: 0.2,
|
||||
}
|
||||
|
||||
let series_LAMin = {
|
||||
name: 'LAmin',
|
||||
data: series3,
|
||||
color: utils.colors.min,
|
||||
yAxis: 0,
|
||||
zIndex: 6,
|
||||
marker: {
|
||||
enabled: false,
|
||||
symbol: 'square',
|
||||
},
|
||||
visible: true,
|
||||
fillColor: {
|
||||
linearGradient: [0, 600, 0, 0],
|
||||
stops: [
|
||||
[0, 'rgb(219,216,217)'],
|
||||
[1, 'rgb(219,216,217)']
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
let yAxis_LAeq = { // 1
|
||||
title: {
|
||||
text: 'dbA',
|
||||
style: {
|
||||
color: 'black'
|
||||
}
|
||||
},
|
||||
max: utils.noise_ymax,
|
||||
// min: utils.noise_ymin,
|
||||
min: 20,
|
||||
// opposite: true,
|
||||
tickAmount: 11,
|
||||
useHTML: true,
|
||||
}
|
||||
|
||||
options.series = []
|
||||
options.yAxis = []
|
||||
options.series[0] = series_LAeq
|
||||
options.series[1] = series_LAMin
|
||||
options.title.text = 'Noise level for one day'
|
||||
options.subtitle.useHTML = true
|
||||
options.subtitle.text = '2.5min log. average values <br />  '
|
||||
options.series[2] = series_LAMax
|
||||
// options.yAxis[2] = yAxis_LAMin
|
||||
options.yAxis[0] = yAxis_LAeq
|
||||
// options.yAxis[1] = yAxis_LAMax
|
||||
options.chart.zoomType = 'x'
|
||||
options.chart.type = 'area'
|
||||
options.chart.resetZoomButton= {
|
||||
position: {
|
||||
align: 'left',
|
||||
verticalAlign: 'bottom',
|
||||
x: 20,
|
||||
y: -50,
|
||||
},
|
||||
relativeTo: 'chart'
|
||||
}
|
||||
options.tooltip.formatter = function () {
|
||||
let y = Math.round(this.y * 100) / 100
|
||||
return '<div style="border: 2px solid ' + this.point.color + '; padding: 3px;">' +
|
||||
DateTime.fromMillis(this.x, {zone: 'utc'}).toFormat("dd.LL - HH:mm:ss") + '<br />' +
|
||||
'<span style="color: ' + this.point.color + '">● </span>' +
|
||||
this.series.name + ': <b>' + y + '</b></div>'
|
||||
}
|
||||
|
||||
|
||||
let noDataTafel = '<div class="errTafel">' +
|
||||
'Für heute liegen leider keine Daten vor!<br /> Bitte den Sensor überprüfen!\' <br />' +
|
||||
'</div>'
|
||||
|
||||
|
||||
let navy = 20
|
||||
let navbreit = 55
|
||||
let navtxt = ['-24h', '-12h', 'live', '+12h', '+24h']
|
||||
let navtime = [-24, -12, 0, 12, 24]
|
||||
|
||||
return { options: options, params: params}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const havgData = (params, values) => {
|
||||
let series1 = []
|
||||
let series2 = []
|
||||
// Put values into the serieses
|
||||
let cnt = 0
|
||||
values.forEach((x) => {
|
||||
if (x.n_AVG != -1) {
|
||||
let dat = new Date(x.datetime).getTime() // retrieve the date
|
||||
series1.push([dat, x.n_AVG])
|
||||
series2.push([dat, x.peakcount])
|
||||
}
|
||||
})
|
||||
|
||||
// Plot-Options
|
||||
let options = utils.createGlobObtions()
|
||||
options.xAxis.tickInterval = 6 * 3600 * 1000
|
||||
// options.xAxis.plotBands = utils.calcWeekends(data, true)
|
||||
options.xAxis.minTickInterval = 3600 * 1000
|
||||
|
||||
options.yAxis = {
|
||||
title: {
|
||||
text: 'dbA',
|
||||
useHTML: true,
|
||||
},
|
||||
min: utils.noise_ymin,
|
||||
tickAmount: 10,
|
||||
gridLineColor: 'lightgray',
|
||||
}
|
||||
options.series = [
|
||||
{
|
||||
name: 'Mean value LAeq',
|
||||
data: series1,
|
||||
color: utils.colors.eq,
|
||||
type: 'column',
|
||||
zIndex: 2,
|
||||
},
|
||||
]
|
||||
options.plotOptions.column = {
|
||||
pointWidth: 8,
|
||||
groupPadding: 0.5
|
||||
}
|
||||
options.title.text = 'Noise hourly mean values'
|
||||
options.subtitle.text = 'Hourly mean values of LAeq for each full hour <br /> '
|
||||
options.subtitle.useHTML = true
|
||||
options.chart.zoomType = 'x'
|
||||
options.chart.height = 350
|
||||
options.chart.resetZoomButton= {
|
||||
position: {
|
||||
align: 'left',
|
||||
// verticalAlign: 'bottom',
|
||||
x: 20,
|
||||
y: 300,
|
||||
},
|
||||
relativeTo: 'chart'
|
||||
}
|
||||
options.tooltip.formatter = function () {
|
||||
let y = Math.round(this.y * 10) / 10
|
||||
return '<div style="border: 2px solid ' + this.point.color + '; padding: 3px;">' +
|
||||
DateTime.fromMillis(this.x, {zone: 'utc'}).toFormat("dd.LL - HH'h'") + '<br />' +
|
||||
'<span style="color: ' + this.point.color + '">● </span>' +
|
||||
this.series.name + ': <b>' + y + '</b></div>'
|
||||
}
|
||||
|
||||
return { options: options, params: params}
|
||||
/*
|
||||
|
||||
// Do PLOT 1
|
||||
let ch = Highcharts.chart('dhour', options, function (chart) {
|
||||
utils.addSensorID2chart(chart, {sid: data.sid, indoor: data.indoor}, document.getElementById('dhour').offsetWidth)
|
||||
})
|
||||
// Do PLOT 2
|
||||
options.series[0] = {
|
||||
name: 'Peaks',
|
||||
data: series2,
|
||||
color: utils.colors.peaks,
|
||||
type: 'column'
|
||||
}
|
||||
options.title.text = 'Peaks more than ' + data.peak + ' dbA'
|
||||
options.subtitle.text = 'Number of exceedances per hour <br /> '
|
||||
options.yAxis = {
|
||||
title: {
|
||||
text: 'Counts',
|
||||
useHTML: true,
|
||||
},
|
||||
tickAmount: 10,
|
||||
allowDecimals: false,
|
||||
gridLineColor: 'lightgray',
|
||||
}
|
||||
options.tooltip.formatter = function () {
|
||||
let y = Math.round(this.y)
|
||||
return '<div style="border: 2px solid ' + this.point.color + '; padding: 3px;">' +
|
||||
DateTime.fromMillis(this.x, {zone: 'utc'}).toFormat("dd.LL - HH'h'") + '<br />' +
|
||||
'<span style="color: ' + this.point.color + '">● </span>' +
|
||||
this.series.name + ': <b>' + y + '</b></div>'
|
||||
}
|
||||
|
||||
let ch1 = Highcharts.chart('dpeak', options)
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
Reference in New Issue
Block a user