API-Auth dazu
automatisch auf INFLUX schalten, wenn es Chi-ID gibt zuzsätzlich option db=m zum erzwingen von Moing Anzeige Mongo/Influx im Datenstrom
This commit is contained in:
@@ -143,8 +143,9 @@ const transformInfluxResult = (series) => {
|
||||
columns.forEach((col, index) => {
|
||||
if (col === 'time') {
|
||||
// Convert timestamp to ISO string for compatibility
|
||||
record._time = new Date(row[index]).toISOString()
|
||||
record.datetime = new Date(row[index]).toISOString()
|
||||
} else {
|
||||
col = col.slice(11)
|
||||
record[col] = row[index]
|
||||
}
|
||||
})
|
||||
@@ -168,7 +169,7 @@ const fetchFromInflux = async (ret, query) => {
|
||||
logit(`ERROR ${fetchFromInflux.name}: ${ret.err}`)
|
||||
return ret
|
||||
}
|
||||
|
||||
logit(`values.length: ${values.length}`)
|
||||
if (!values || !values.length || !values[0].series) {
|
||||
ret.err = 'NODATA'
|
||||
logit(`ERROR ${fetchFromInflux.name}: No data returned from query`)
|
||||
@@ -195,6 +196,14 @@ export const fetchActData = async (opts) => {
|
||||
let startTime = opts.start.replace('start: ', '').trim()
|
||||
let stopTime = opts.stop.replace('stop: ', '').trim()
|
||||
|
||||
// If time is ISO string, wrap in quotes; if it's a relative time (like now() - 1h), leave as is
|
||||
if (startTime.match(/^\d{4}-\d{2}-\d{2}T/)) {
|
||||
startTime = `'${startTime}'`
|
||||
}
|
||||
if (stopTime.match(/^\d{4}-\d{2}-\d{2}T/)) {
|
||||
stopTime = `'${stopTime}'`
|
||||
}
|
||||
|
||||
// Build sorting clause
|
||||
let orderClause = ''
|
||||
if (opts.sort) {
|
||||
@@ -208,9 +217,9 @@ export const fetchActData = async (opts) => {
|
||||
// InfluxQL query to get LA_max for a sensor within time range
|
||||
// Note: In InfluxDB 1.8 we only have LA_max, not E10tel_eq like in 2.0
|
||||
const query = `
|
||||
SELECT "DNMS_noise_LA_max", "DNMS_noise_LA_min", "DNMS_noise_LA_eq"
|
||||
SELECT "DNMS_noise_LA_max", "DNMS_noise_LA_min", "DNMS_noise_LAeq"
|
||||
FROM "DNMS"
|
||||
WHERE "node" = '${opts.sensorid}'
|
||||
WHERE "node" = '${opts.chipid}'
|
||||
AND time >= ${startTime}
|
||||
AND time <= ${stopTime}
|
||||
${orderClause}
|
||||
@@ -275,17 +284,19 @@ const calculateLogMean = (values) => {
|
||||
export const fetchNoiseAVGData = async (opts) => {
|
||||
let ret = { err: null, values: [] }
|
||||
|
||||
// convert sensorID ti esp-chip-is, if possible
|
||||
const convert2espid = (opts) => {
|
||||
const sid = opts.sensorid
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Convert Flux time format to InfluxQL format
|
||||
let startTime = opts.start.replace('start: ', '').trim()
|
||||
let stopTime = opts.stop.replace('stop: ', '').trim()
|
||||
|
||||
// If time is ISO string, wrap in quotes; if it's a relative time (like now() - 1h), leave as is
|
||||
if (startTime.match(/^\d{4}-\d{2}-\d{2}T/)) {
|
||||
startTime = `'${startTime}'`
|
||||
}
|
||||
if (stopTime.match(/^\d{4}-\d{2}-\d{2}T/)) {
|
||||
stopTime = `'${stopTime}'`
|
||||
}
|
||||
|
||||
// Since InfluxQL doesn't support complex joins like Flux, we need to make multiple queries
|
||||
// and combine the results in JavaScript
|
||||
|
||||
@@ -294,7 +305,7 @@ export const fetchNoiseAVGData = async (opts) => {
|
||||
const queryLAmaxForE10 = `
|
||||
SELECT "DNMS_noise_LA_max"
|
||||
FROM "DNMS"
|
||||
WHERE "node" = '${opts.sensorid}'
|
||||
WHERE "node" = '${opts.chipid}'
|
||||
AND time >= ${startTime}
|
||||
AND time <= ${stopTime}
|
||||
ORDER BY time ASC
|
||||
|
||||
Reference in New Issue
Block a user