diff --git a/actions/data4map.js b/actions/data4map.js index 7911d50..a5f1b1c 100644 --- a/actions/data4map.js +++ b/actions/data4map.js @@ -174,8 +174,11 @@ export var getData4map = async (params) => { logit(`Query duration: ${start.diffNow('seconds').toObject().seconds * -1} sec`) ret = { err: null, - lastdate: lastDate, - count: aktData.length, + options: { + lastdate: lastDate, + count: aktData.length, + data: 'map' + }, values: aktData } return ret diff --git a/app.js b/app.js index eb2e1d6..40b695e 100644 --- a/app.js +++ b/app.js @@ -5,8 +5,7 @@ import cookieParser from 'cookie-parser' import cors from 'cors' import indexRouter from './routes/index.js' -import { apiRouter, chartapiRouter } from './routes/api.js' -// import chartRouter from './routes/chartapi.js' +import { apiRouter } from './routes/api.js' const app = express() @@ -18,7 +17,6 @@ app.use(cookieParser()) app.use('/', indexRouter) app.use('/api', apiRouter) -app.use('/chart', chartapiRouter) // catch 404 and forward to error handler diff --git a/routes/api.js b/routes/api.js index 62e0520..12de650 100644 --- a/routes/api.js +++ b/routes/api.js @@ -1,7 +1,6 @@ import express from 'express' import {getData4map} from "../actions/data4map.js" -import * as tables from "../utilities/tables.js" import * as ERR from "../utilities/errortexts.js" import * as getData from "../actions/getsensorData.js"; import * as getProps from "../actions/getproperties.js"; @@ -46,10 +45,3 @@ apiRouter.get('/:cmd', async (req, res) => { params.chart = false await dispatchCommand(req.params.cmd, cmdTable, params, res) }) - -// normal routes called from javascript client -chartapiRouter.get('/:cmd', async (req, res) => { - const params = req.query - params.chart = true - await dispatchCommand(req.params.cmd, cmdTable, params, res) -}) diff --git a/routes/chartapi.js b/routes/chartapi.js deleted file mode 100644 index 2571039..0000000 --- a/routes/chartapi.js +++ /dev/null @@ -1,14 +0,0 @@ -import express from 'express' -import * as tables from "../utilities/tables.js" -import { dispatchCommand } from "./api.js" - -const chartapiRouter = express.Router(); - -// normal routes called from javascript client -chartapiRouter.get('/:cmd', async (req, res) => { - const params = req.query - params.kind = 'chart' - await dispatchCommand(req.params.cmd, tables.cmdTable, params, res) -}) - -export default chartapiRouter \ No newline at end of file diff --git a/sensorspecials/noise.js b/sensorspecials/noise.js index 9fc18ba..7bd64bb 100644 --- a/sensorspecials/noise.js +++ b/sensorspecials/noise.js @@ -6,7 +6,6 @@ import { getActData, getAvgData, getLongAvg, fetchFromInflux, calcRange} from ". import checkParams from "../utilities/checkparams.js"; import * as ERR from "../utilities/errortexts.js" import {DateTime} from 'luxon' -import * as noiseChart from "./noiseChart.js"; const setoptionfromtable = (opt,tabval) => { let ret = opt @@ -23,7 +22,6 @@ export const getNoiseData = async (params, possibles, props) => { let {opts, err} = checkParams(params, { mandatory:[ {name:'sensorid', type: 'int'}, - {name:'chart', type: 'bool'}, ], optional: possibles }) @@ -43,22 +41,21 @@ 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, - indoor: props.location[0].indoor, - span: opts.span, - start: opts.start.slice(7), - data: opts.data, - peak: opts.peak, - count: erg.values.length, + options: { + sid: opts.sensorid, + indoor: props.location[0].indoor, + span: opts.span, + start: opts.start.slice(7), + data: opts.data, + peak: opts.peak, + count: erg.values.length, + }, values: erg.values, } if (!x.peak) { - delete ret.peak + delete ret.options.peak } if(ret.values.length === 0) { ret.err = ERR.NODATA @@ -96,10 +93,7 @@ export const getNoiseData = async (params, possibles, props) => { // ********************************************* const getLiveData = async (opts) => { const erg = await getActData(opts) - if (!opts.chart || erg.err) { - return erg - } - return noiseChart.liveData(opts, erg.values) + return erg } @@ -133,7 +127,7 @@ const gethavgData = async (opts, props) => { let erg = await getNoiseAVGData(opts) if (opts.csv) { let csvStr = "datetime,n_AVG,peakcount\n" - if(!erg.err) { + if (!erg.err) { for (let item of erg.values) { if (item.n_AVG != -1) { csvStr += item.datetime + ',' + item.n_AVG + ',' + item.peakcount + '\n' @@ -141,11 +135,8 @@ const gethavgData = async (opts, props) => { } } return csvStr - } else if (!opts.chart || erg.err) { - return {err: erg.err, values: erg.values} - } else { - return noiseChart.havgData(opts, erg.values) } + return {err: erg.err, values: erg.values} } @@ -175,10 +166,10 @@ const gethavgData = async (opts, props) => { // ********************************************* async function getdavgData(opts) { opts.long = true; - let erg = await getNoiseAVGData(opts); + let erg = await getNoiseAVGData(opts); let val = []; let csvStr = 'datetime,n_AVG,peakcount\n'; - if(!erg.err) { + if (!erg.err) { for (let i = 0; i < erg.values.length; i += 24) { let sum = 0; let count = 0; @@ -196,7 +187,7 @@ async function getdavgData(opts) { } } } - if (count === 0 ) { + if (count === 0) { werte.n_AVG = -1 } else { werte.n_AVG = 10 * Math.log10(sum / count); @@ -211,11 +202,8 @@ async function getdavgData(opts) { } if (opts.csv) { return csvStr; - } else if (!opts.chart || erg.err) { - return {err: erg.err, values: val} - } else { - return noiseChart.davgData(opts, val) } + return {err: erg.err, values: val} } @@ -310,13 +298,11 @@ async function getdaynightData(opts) { } if (opts.csv) { return csvStr; - } else if (!opts.chart || erg.err) { - return {err: erg.err, values: val} - } else { - return noiseChart.dayNightData(opts, val) } + return {err: erg.err, values: val} } + // ********************************************* // getLdenData // @@ -345,10 +331,10 @@ async function getdaynightData(opts) { // ********************************************* async function getLdenData(opts) { opts.long = true; - let erg = await getNoiseAVGData(opts); + let erg = await getNoiseAVGData(opts); let val = []; let csvStr = 'datetime,lden\n'; - if(!erg.err) { + if (!erg.err) { let done = false; const calcAVG = (sum, cnt) => { if (cnt != 0) { @@ -425,11 +411,8 @@ async function getLdenData(opts) { } if (opts.csv) { return csvStr; - } else if (!opts.chart || erg.err) { - return {err: erg.err, values: val} - } else { - return noiseChart.ldenData(opts, val) } + return {err: erg.err, values: val} } diff --git a/sensorspecials/noiseChart.js b/sensorspecials/noiseChart.js deleted file mode 100644 index 1790779..0000000 --- a/sensorspecials/noiseChart.js +++ /dev/null @@ -1,535 +0,0 @@ -// Prepare all data to plot the charts -import * as utils from '../utilities/chartoptions.js' - -/********************************************** - * Live-Data - * * - * @param params - * @param values - * @returns {{options: {plotOptions: {series: {marker: {enabled: boolean}, turboThreshold: number, animation: boolean}}, xAxis: {gridLineWidth: number, type: string, title: {text: string}, labels: {formatter: function(): (string|*)}}, legend: {layout: string, borderWidth: number, align: string, enabled: boolean}, subtitle: {align: string}, tooltip: {backgroundColor: number, valueDecimals: number, borderRadius: number, useHTML: boolean, borderWidth: number}, title: {useHTML: boolean, style: {fontSize: string}, align: string}, chart: {backgroundColor: {linearGradient: number[], stops: [[number,string],[number,string]]}, spacingTop: number, borderWidth: string, spacingLeft: number, type: string, spacingRight: number, events: {selection: function(*): void}, height: number}}, params}} - * - ***********************************************/ -export const liveData = (params, values) => { - let series1 = [] - let series2 = [] - let series3 = [] - let infoTafel - - // 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 - infoTafel = - '' + - '' + - '' + - '' - infoTafel += - '' + - '' - infoTafel += - '' + - '' - infoTafel += - '
Aktuelle Werte
LAeq' + (aktVal.LAeq).toFixed(1) + 'dbA
LAmin' + (aktVal.LAMin).toFixed(0) + 'dbA
LAmax' + (aktVal.LAMax).toFixed(0) + 'dbA
' + - '' - } - 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 levels last 24 hours' - options.subtitle.useHTML = true - options.subtitle.text = '2.5min log. average values
 ' - 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 '
' + - // DateTime.fromMillis(this.x, {zone: 'utc'}).toFormat("dd.LL - HH:mm:ss") + '
' + - // '● ' + - // this.series.name + ':  ' + y + '
' - // } - - - let noDataTafel = '
' + - 'Für heute liegen leider keine Daten vor!
Bitte den Sensor überprüfen!\'
' + - '
' - - - 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, info: {class: 'infoTafel', text:infoTafel}} -} - - -/******************************************** - * havg - Data - * - * @param params - * @param values - * @returns {{options: {plotOptions: {series: {marker: {enabled: boolean}, turboThreshold: number, animation: boolean}}, xAxis: {gridLineWidth: number, type: string, title: {text: string}, labels: {formatter: function(): (string|*)}}, legend: {layout: string, borderWidth: number, align: string, enabled: boolean}, subtitle: {align: string}, tooltip: {backgroundColor: number, valueDecimals: number, borderRadius: number, useHTML: boolean, borderWidth: number}, title: {useHTML: boolean, style: {fontSize: string}, align: string}, chart: {backgroundColor: {linearGradient: number[], stops: [[number,string],[number,string]]}, spacingTop: number, borderWidth: string, spacingLeft: number, type: string, spacingRight: number, events: {selection: function(*): void}, height: number}}, params, options2: any}} - * - ********************************************/ -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' - }, { - title: { - text: 'Counts', - useHTML: true, - }, - tickAmount: 10, - allowDecimals: false, - gridLineColor: 'lightgray', - opposite: true - } - ] - options.series = [ - { - name: 'Mean value LAeq', - data: series1, - color: utils.colors.eq, - type: 'column', - zIndex: 2, - yAxis: 0 - }, { - name: 'Peaks', - data: series2, - color: utils.colors.peaks, - type: 'column', - yAxis: 1, - zIndex: 2 - } - ] - // options.plotOptions.column = { - // pointWidth: 8, - // groupPadding: 0.5 - // } - options.plotOptions.column = { - pointWidth: 8, - groupPadding: 0.1 - } - - options.title.text = 'Hourly mean values / Peaks over ' + params.peak + ' dbA' - options.subtitle.text = 'Hourly mean values of LAeq for each full hour / Number of peaks per hour' - options.subtitle.useHTML = true - options.chart.zoomType = 'x' - options.chart.resetZoomButton= { - position: { - align: 'left', - x: 20, - y: 300, - }, - relativeTo: 'chart' - } - - return { options: options, params: params} - -} - -/******************************************** - * davg - Data - * - * @param params - * @param values - * @returns {{options: {plotOptions: {series: {marker: {enabled: boolean}, turboThreshold: number, animation: boolean}}, xAxis: {gridLineWidth: number, type: string, title: {text: string}, labels: {formatter: function(): (string|*)}}, legend: {layout: string, borderWidth: number, align: string, enabled: boolean}, subtitle: {align: string}, tooltip: {backgroundColor: number, valueDecimals: number, borderRadius: number, useHTML: boolean, borderWidth: number}, title: {useHTML: boolean, style: {fontSize: string}, align: string}, chart: {backgroundColor: {linearGradient: number[], stops: [[number,string],[number,string]]}, spacingTop: number, borderWidth: string, spacingLeft: number, type: string, spacingRight: number, events: {selection: function(*): void}, height: number}}, params, options2: any}} - * - ********************************************/ - - export const davgData = (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.plotBands = utils.calcWeekends(values, true) - options.xAxis.tickInterval = 24 * 3600 * 1000 - options.xAxis.title.text = 'Date' - // options.xAxis.labels = { - // formatter: function () { - // return this.axis.defaultLabelFormatter.call(this); - // } - // } - - options.chart.type = 'column' - - options.yAxis = [ - { - title: { - text: 'dbA', - useHTML: true, - }, - min: utils.noise_ymin, - tickAmount: 10, - gridLineColor: 'lightgray', - }, { - title: { - text: 'Counts', - useHTML: true, - }, - tickAmount: 10, - allowDecimals: false, - gridLineColor: 'lightgray', - opposite: true - } - ] - - options.series = [ - { - name: 'Mean value LAeq', - data: series1, - color: utils.colors.eq, - type: 'column', - zIndex: 2, - yAxis: 0 - },{ - name: 'Peaks', - data: series2, - color: utils.colors.peaks, - type: 'column', - yAxis: 1, - zIndex: 2, - } - ] - options.plotOptions.column = { - pointWidth: 20, - groupPadding: 0.1 - } - options.title.text = 'Daily mean values / Peaks over ' + params.peak + ' dbA' - options.subtitle.text = 'Daily mean values of LAeq for each full day / Number of peaks per day' - options.subtitle.useHTML = true - options.chart.zoomType = 'x' - options.chart.resetZoomButton = { - position: { - align: 'left', -// verticalAlign: 'bottom', - x: 20, - y: 300, - }, - relativeTo: 'chart' - } - - return {options: options, params: params} - -} - -/******************************************** - * dayNight - Data - * - * @param params - * @param values - * @returns {{options: {plotOptions: {series: {marker: {enabled: boolean}, turboThreshold: number, animation: boolean}}, xAxis: {gridLineWidth: number, type: string, title: {text: string}, labels: {formatter: function(): (string|*)}}, legend: {layout: string, borderWidth: number, align: string, enabled: boolean}, subtitle: {align: string}, tooltip: {backgroundColor: number, valueDecimals: number, borderRadius: number, useHTML: boolean, borderWidth: number}, title: {useHTML: boolean, style: {fontSize: string}, align: string}, chart: {backgroundColor: {linearGradient: number[], stops: [[number,string],[number,string]]}, spacingTop: number, borderWidth: string, spacingLeft: number, type: string, spacingRight: number, events: {selection: function(*): void}, height: number}}, params}} - * - ********************************************/ -export const dayNightData = (params, values) => { - - let series1 = [] - let series2 = [] - // Put values into the serieses - let cnt = 0 - values.forEach((x) => { - if (x.n_dayAVG > 0) { - let dat = new Date(x.datetime).getTime() // retrieve the date - series1.push([dat, x.n_dayAVG]) - series2.push([dat, x.n_nightAVG]) - } - }) - // Plot-Options - let options = utils.createGlobObtions() -// options.xAxis.plotBands = utils.calcWeekends(data, true) - options.xAxis.tickInterval = 24 * 3600 * 1000 - options.xAxis.title.text = 'Date' - // options.xAxis.labels = { - // formatter: function () { - // return this.axis.defaultLabelFormatter.call(this); - // } - // } - - options.chart.type = 'column' - options.yAxis = { - title: { - text: 'dbA', - useHTML: true, - }, - min: utils.noise_ymin, - tickAmount: 10, - gridLineColor: 'lightgray', - } - options.series = [ - { - name: 'Day', - data: series1, - color: utils.colors.eq, - type: 'column', - zIndex: 2, - }, - { - name: 'Night', - data: series2, - color: utils.colors.max, - type: 'column', - zIndex: 2, - }, - ] - options.plotOptions.series = { - animation: false - } - options.plotOptions.column = { - pointWidth: 20, - groupPadding: 0.3 - } - options.title.text = 'Average values during the day and night hours' - options.subtitle.text = 'Daily mean values of LAeq from 6h00 to 22h00
Nightly mean values of LAeq from 22h00 to 6h00' - options.subtitle.useHTML = true - options.chart.zoomType = 'x' - options.chart.resetZoomButton = { - position: { - align: 'left', -// verticalAlign: 'bottom', - x: 20, - y: 300, - }, - relativeTo: 'chart' - } - return {options: options, params: params} -} - -/*********************************** - Lden - Data - * - * @param params - * @param values - * @returns {{options: {plotOptions: {series: {marker: {enabled: boolean}, turboThreshold: number, animation: boolean}}, xAxis: {gridLineWidth: number, type: string, title: {text: string}, labels: {formatter: function(): (string|*)}}, legend: {layout: string, borderWidth: number, align: string, enabled: boolean}, subtitle: {align: string}, tooltip: {backgroundColor: number, valueDecimals: number, borderRadius: number, useHTML: boolean, borderWidth: number}, title: {useHTML: boolean, style: {fontSize: string}, align: string}, chart: {backgroundColor: {linearGradient: number[], stops: [[number,string],[number,string]]}, spacingTop: number, borderWidth: string, spacingLeft: number, type: string, spacingRight: number, events: {selection: function(*): void}, height: number}}, params}} - **********************************/ -export const ldenData = (params, values) => { - - let series1 = [] - - // Put values into the series - let cnt = 0 - values.forEach((x) => { - if (!((x.lden === -1) || (x.datetime === undefined))) { - let dat = new Date(x.datetime).getTime() // retrieve the date - series1.push([dat, x.lden]) - } - }) - // Plot-Options - let options = utils.createGlobObtions() - -// options.xAxis.plotBands = utils.calcWeekends(data, true) - options.xAxis.tickInterval = 24 * 3600 * 1000 - options.xAxis.title = 'Date' - options.xAxis.labels = { - formatter: function () { - let lbl = this.axis.defaultLabelFormatter.call(this); - this.value += 86400000; - let lbl1 = this.axis.defaultLabelFormatter.call(this); - return parseInt(lbl) + '/' + lbl1; - } - } - options.chart.type = 'column' - options.yAxis = { - title: { - text: 'dbA', - useHTML: true, - }, - min: utils.noise_ymin, - tickAmount: 10, - gridLineColor: 'lightgray', - } - options.series = [ - { - name: 'lden', - data: series1, - color: utils.colors.eq, - type: 'column', - zIndex: 2, - } - ] - options.plotOptions.series = { - animation: false - } - options.plotOptions.column = { - pointWidth: 20, - groupPadding: 0.1 - } - options.title.text = 'LDEN-Index' - options.subtitle.text = 'Daily mean values of LDEN\-Index' - options.subtitle.useHTML = true - options.chart.zoomType = 'x' - options.chart.resetZoomButton = { - position: { - align: 'left', -// verticalAlign: 'bottom', - x: 20, - y: 300, - }, - relativeTo: 'chart' - } -/* options.tooltip.formatter = function () { - let d = DateTime.fromMillis(this.x, {zone: 'utc'}) - let d1 = d.plus({days: 1}) - let txt = d.toFormat('dd') + '/' + d1.toFormat('dd.LL') - return '
' + - '  ' + txt + '
' + - '● ' + - this.series.name + ':  ' + - Highcharts.numberFormat(this.y, 1) + - '
'; - } - - */ - return {options: options, params: params} -} - diff --git a/utilities/tables.js b/utilities/tables.js deleted file mode 100644 index 8cfcc29..0000000 --- a/utilities/tables.js +++ /dev/null @@ -1,13 +0,0 @@ -// Command table for http calls - -import * as getData from "../actions/getsensorData.js" -import * as getProps from "../actions/getproperties.js" -import * as getAKWs from "../actions/getAKWData.js" -import * as holAddr from "../actions/getaddress.js" -import * as radioact from "../sensorspecials/radioact.js" -import * as noise from "../sensorspecials/noise.js" -import {getData4map} from "../actions/data4map.js" -import * as noiseChart from '../sensorspecials/noiseChart.js' - - -