From 8d6b09fe8f65aa9e65951bd2155d35c23aa40f2f Mon Sep 17 00:00:00 2001 From: rxf Date: Thu, 8 Jun 2023 18:37:53 +0200 Subject: [PATCH] WIP WIP first changes to use radioact --- .vscode/launch.json | 23 ++++++++++++++ actions/getsensorData.js | 15 +++++++++- sensorspecials/radioact.js | 61 +++++++++++++++++++++++++++++++++++++- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e5d645f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/bin/www.js", + "env": { + "INFLUXHOST": "esprimo", + "INFLUXTOKEN": "uhsrE9MZtlVD18JnP19y0O0NW9C8HaQV3ElyAT_VwUlreluNsc9rM4djI9H10f6Dcw4oMFUzSngAo9dxtLjUoA==", + "MONGOHOST": "esprimo", + "MONGOPORT": "27098" + } + } + ] +} \ No newline at end of file diff --git a/actions/getsensorData.js b/actions/getsensorData.js index 2f7223d..de91cac 100644 --- a/actions/getsensorData.js +++ b/actions/getsensorData.js @@ -27,7 +27,20 @@ const noiseParams = [ ] const thpParams = [] const pmParams = [] -const radioParams = [] +const radioParams = [ + {name: 'what', type: 'string', default: 'day'}, + {name: 'span', type: 'int', default: ''}, + {name: 'daystart', type: 'bool', default: null}, + {name: 'avg', type: 'int', default: 10}, + {name: 'since', type: 'date', default: '1900-01-01T00:00:00Z'}, + {name: 'box', type: 'array', default: null}, + {name: 'out', type: 'string', default: ''}, + {name: 'csv', type: 'bool', default: false}, + {name: 'long', type: 'bool', default: false}, + {name: 'sort', type: 'int', default: 1}, + {name: 'last_seen', type: 'date', default: '1900-01-01T00:00:00Z'}, + {name: 'datetime', type: 'date', default: null} +] // >>>>>>>>>>>>>>>>>>>>> DUMMIES async function getPmData(opts) { diff --git a/sensorspecials/radioact.js b/sensorspecials/radioact.js index a812d39..a93cbc8 100644 --- a/sensorspecials/radioact.js +++ b/sensorspecials/radioact.js @@ -3,6 +3,8 @@ import {returnOnError} from "../utilities/reporterror.js"; import { getActData, getAvgData, getLongAvg } from "../actions/getsensorData.js" +import checkParams from "../utilities/checkparams.js"; + const radioactFilter = (data, opts, actual) => { let erg = {} @@ -25,7 +27,56 @@ const radioactFilter = (data, opts, actual) => { } -export const getRadioData = async (opts) => { +export const getRadioData = async (params, possibles, props) => { + let ret = {err: null} + + let {opts, erro} = checkParams(params, { + mandatory:[ + {name:'sensorid', type: 'int'}, + ], + optional: possibles + }) + // To be compatible with old API: + if (opts.out === 'csv') { + opts.csv = true + } + if (erro) { + return returnOnError(ret, erro, getNoiseData.name) + } + + // execute function depending on given 'what' + for(let x of whatTable) { + if (x.what === opts.what) { + opts.span = setoptionfromtable(opts.span, x.span) + opts.daystart = setoptionfromtable(opts.daystart, x.daystart) + let {start, stop} = calcRange(opts) // calc time range + opts.start = start + opts.stop = stop + let erg = await x.func(opts) // get the data + ret = { + err: erg.err, + options: { + sid: opts.sensorid, + indoor: props.location[0].indoor, + span: opts.span, + start: DateTime.fromISO(opts.start.slice(7)), + data: opts.data, + count: erg.values.length, + }, + values: erg.values, + } + if(ret.values.length === 0) { + ret.err = trans('NODATA') + } + return ret + } + } + return returnOnError(ret, 'CMNDUNKNOWN', getNoiseData.name) +} + +/* + + let erg = { err: null, data: {}} let params = { @@ -67,3 +118,11 @@ export const getRadioData = async (opts) => { } return erg } +*/ + + +const whatTable = [ + {'what':'day', 'span': 1, 'daystart': false, 'func': getDayData}, + {'what':'week', 'span': 7, 'daystart': false, 'func': getWeekgData}, + {'what':'month', 'span': 30, 'daystart': true, 'func': getMonthData}, +];