WIP WIP first changes to use radioact

This commit is contained in:
rxf
2023-06-08 18:37:53 +02:00
parent ec64eb3992
commit 8d6b09fe8f
3 changed files with 97 additions and 2 deletions
+23
View File
@@ -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": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/bin/www.js",
"env": {
"INFLUXHOST": "esprimo",
"INFLUXTOKEN": "uhsrE9MZtlVD18JnP19y0O0NW9C8HaQV3ElyAT_VwUlreluNsc9rM4djI9H10f6Dcw4oMFUzSngAo9dxtLjUoA==",
"MONGOHOST": "esprimo",
"MONGOPORT": "27098"
}
}
]
}
+14 -1
View File
@@ -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) {
+60 -1
View File
@@ -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},
];