Ertser Commit der test-Version
This commit is contained in:
148
utilities/chartoptions.js
Normal file
148
utilities/chartoptions.js
Normal file
@@ -0,0 +1,148 @@
|
||||
// Utility routine for plotting the data
|
||||
|
||||
export const colors = {'eq': '#0000FF', 'max': '#FF0000', 'min': '#008000', 'peaks': '#DAA520'};
|
||||
export const noise_ymin = 30;
|
||||
|
||||
export function createGlobObtions() {
|
||||
// Options, die für alle Plots identisch sind
|
||||
let globObject = {
|
||||
chart: {
|
||||
spacingRight: 20,
|
||||
spacingLeft: 20,
|
||||
spacingTop: 25,
|
||||
backgroundColor: {
|
||||
linearGradient: [0, 400, 0, 0],
|
||||
stops: [
|
||||
[0, '#eee'],//[0, '#ACD0AA'], //[0, '#A18D99'], // [0, '#886A8B'], // [0, '#F2D0B5'],
|
||||
[1, '#fff']
|
||||
]
|
||||
},
|
||||
type: 'line',
|
||||
borderWidth: '2',
|
||||
// events: {
|
||||
// selection: function (event) {
|
||||
// if (event.xAxis) {
|
||||
// doUpdate = false;
|
||||
// } else {
|
||||
// doUpdate = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
},
|
||||
title: {
|
||||
align: 'left',
|
||||
style: {'fontSize': '25px'},
|
||||
useHTML: true,
|
||||
},
|
||||
subtitle: {
|
||||
align: 'left',
|
||||
},
|
||||
tooltip: {
|
||||
valueDecimals: 1,
|
||||
backgroundColor: '#ffffff',
|
||||
borderWidth: 0,
|
||||
borderRadius: 0,
|
||||
useHTML: true,
|
||||
},
|
||||
xAxis: {
|
||||
type: 'datetime',
|
||||
title: {
|
||||
text: 'date/time',
|
||||
},
|
||||
gridLineWidth: 2,
|
||||
labels: {
|
||||
formatter: function () {
|
||||
let v = this.axis.defaultLabelFormatter.call(this);
|
||||
if (v.indexOf(':') == -1) {
|
||||
return '<span style="font-weight:bold;color:red">' + v + '<span>';
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
legend: {
|
||||
enabled: true,
|
||||
layout: 'horizontal',
|
||||
// verticalAlign: 'top',
|
||||
borderWidth: 1,
|
||||
align: 'center',
|
||||
},
|
||||
plotOptions: {
|
||||
series: {
|
||||
animation: false,
|
||||
turboThreshold: 0,
|
||||
marker: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
return globObject;
|
||||
}
|
||||
|
||||
export function calcWeekends(data, isyear) {
|
||||
/* let weekend = [];
|
||||
let oldDay = 8;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let mom = moment(data[i].date);
|
||||
if (isyear) {
|
||||
mom = moment(data[i]._id)
|
||||
}
|
||||
let day = mom.day();
|
||||
let 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;
|
||||
*/}
|
||||
|
||||
export function calcDays(data, isyear) {
|
||||
let days = [];
|
||||
if (data.length == 0) {
|
||||
return days
|
||||
}
|
||||
let oldday = moment(data[0].date).day();
|
||||
if (isyear) {
|
||||
oldday = moment(data[0]._id).day();
|
||||
}
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let m = moment(data[i].date);
|
||||
if (isyear) {
|
||||
m = moment(data[i]._id);
|
||||
}
|
||||
let tag = m.day()
|
||||
if (tag != oldday) {
|
||||
m.startOf('day');
|
||||
days.push({color: 'lightgray', value: m.valueOf(), width: 1, zIndex: 2});
|
||||
oldday = tag;
|
||||
}
|
||||
}
|
||||
return days;
|
||||
};
|
||||
|
||||
export const setoptionfromtable = (opt,tabval) => {
|
||||
let ret = opt
|
||||
if ((opt === null) || (opt === '') || (opt === undefined) || (opt < tabval)){
|
||||
ret = tabval
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
54
utilities/checkparams.js
Normal file
54
utilities/checkparams.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// parse the params from http call
|
||||
|
||||
import {returnOnError} from "./reporterror.js"
|
||||
|
||||
const checkParams = (params, mo) => {
|
||||
let o = {opts: {}, err: null}
|
||||
if ((mo.mandatory.length !== 0) && (params === undefined)) {
|
||||
return returnOnError(o, 'NOPARAMETER', checkParams.name )
|
||||
}
|
||||
for (let p of mo.mandatory) {
|
||||
if (!(p.name in params)) {
|
||||
return returnOnError(o, 'NOMANDPARAM', checkParams.name, p.name)
|
||||
}
|
||||
if (p.type === 'int') {
|
||||
let x = parseInt(params[p.name])
|
||||
if (isNaN(x)) {
|
||||
return returnOnError(o, 'PARAMNONUM', checkParams.name, p.name)
|
||||
} else {
|
||||
o.opts[p.name] = x
|
||||
continue
|
||||
}
|
||||
} else if (p.type === 'float') {
|
||||
let x = parseFloat(params[p.name])
|
||||
if (isNaN(x)) {
|
||||
return returnOnError(o, 'PARAMNONUM', checkParams.name, p.name)
|
||||
} else {
|
||||
o.opts[p.name] = x
|
||||
continue
|
||||
}
|
||||
}
|
||||
o.opts[p.name] = params[p.name]
|
||||
}
|
||||
for(let p of mo.optional) {
|
||||
if (!(p.name in params)) {
|
||||
o.opts[p.name] = p.default
|
||||
} else {
|
||||
if (p.type === 'int') {
|
||||
let x = parseInt(params[p.name])
|
||||
if (isNaN(x)) {
|
||||
o.opts[p.name] = p.default
|
||||
} else {
|
||||
o.opts[p.name] = x
|
||||
}
|
||||
} else if (p.type === 'bool') {
|
||||
o.opts[p.name] = params[p.name] === 'true'
|
||||
} else {
|
||||
o.opts[p.name] = params[p.name]
|
||||
}
|
||||
}
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
export default checkParams
|
||||
35
utilities/csv2json.js
Normal file
35
utilities/csv2json.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// convert influx csv output to JSON
|
||||
|
||||
export function csv2Json(str, delimiter = ",") {
|
||||
// slice from start of text to the first \n index
|
||||
// use split to create an array from string by delimiter
|
||||
const headers = str.slice(0, str.indexOf("\r\n")).split(delimiter).slice(3);
|
||||
let x = headers.findIndex((x) => (x === '_time') || (x === '_stop'))
|
||||
if (x != -1) {
|
||||
headers[x] = 'datetime'
|
||||
}
|
||||
// slice from \n index + 1 to the end of the text
|
||||
// use split to create an array of each csv value row
|
||||
const rows = str.slice(str.indexOf("\r\n") + 2).split("\r\n").slice(0,-2)
|
||||
|
||||
// Map the rows
|
||||
// split values from each row into an array
|
||||
// use headers.reduce to create an object
|
||||
// object properties derived from headers:values
|
||||
// the object passed as an element of the array
|
||||
const arr = rows.map(function (row) {
|
||||
const values = row.split(delimiter).slice(3);
|
||||
const el = headers.reduce(function (object, header, index) {
|
||||
if(header !== 'datetime') {
|
||||
object[header] = parseFloat(values[index]);
|
||||
} else {
|
||||
object[header] = values[index];
|
||||
}
|
||||
return object;
|
||||
}, {});
|
||||
return el;
|
||||
});
|
||||
|
||||
// return the array
|
||||
return arr;
|
||||
}
|
||||
16
utilities/logit.js
Normal file
16
utilities/logit.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { DateTime} from 'luxon'
|
||||
|
||||
const MOCHA_TEST = process.env.MOCHA_TEST || false
|
||||
|
||||
export function logit(str) {
|
||||
if(MOCHA_TEST) return
|
||||
let s = `${DateTime.now().toISO()} => ${str}`;
|
||||
console.log(s);
|
||||
}
|
||||
|
||||
export function logerror(str) {
|
||||
if(MOCHA_TEST) return
|
||||
let s = `${DateTime.toISO()} => *** ERROR *** ${str}`;
|
||||
console.log(s);
|
||||
}
|
||||
|
||||
22
utilities/reporterror.js
Normal file
22
utilities/reporterror.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import {logit} from "./logit.js";
|
||||
import { translate as trans } from '../routes/api.js'
|
||||
|
||||
export const reportError = (message, errortext) => {
|
||||
message.error = true
|
||||
message.errortext = errortext
|
||||
return message
|
||||
}
|
||||
|
||||
export const returnOnError = (pr, error, name, p1='', p2='') => {
|
||||
error = trans(error)
|
||||
if (error.indexOf('xxx') !== -1) {
|
||||
error = error.replace('xxx', p1)
|
||||
}
|
||||
if (error.indexOf('yyy') !== -1) {
|
||||
error = error.replace('yyy', p1)
|
||||
}
|
||||
pr.err = error
|
||||
logit(`${name}: ${error}`)
|
||||
return pr
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user