Werte für die Karte auch aus der Influx holen
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import {DateTime} from "luxon"
|
||||
import * as mongo from "../databases/mongo.js"
|
||||
import { returnOnError } from "../utilities/reporterror.js"
|
||||
import { fetchLatestLAmaxForChips } from '../databases/influx_sql.js'
|
||||
|
||||
|
||||
// Default distance for center search ( in km)
|
||||
@@ -127,6 +128,8 @@ export var getData4map = async (params) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Nur Einträge verwenden, die eine ESP-Chipid haben
|
||||
query.chip = { $exists: true }
|
||||
try {
|
||||
// fetch mapdata from mongodb
|
||||
let { properties, err } = await mongo.getallProperties(mongo.properties_collection, query)
|
||||
@@ -134,19 +137,26 @@ export var getData4map = async (params) => {
|
||||
return returnOnError(ret, 'NOPROPSFOUND', getData4map.name)
|
||||
}
|
||||
let v4map = getValue4Map(typ)
|
||||
|
||||
const chipIds = properties.map(prop => prop.chip?.id).filter(id => id)
|
||||
const result = await fetchLatestLAmaxForChips({ chipids: chipIds})
|
||||
|
||||
for (let sensor of properties) {
|
||||
const resIndex = result.values.findIndex((id) => id.chipid == sensor.chip.id)
|
||||
const chpvalues = result.values[resIndex]
|
||||
let oneAktData = {}
|
||||
if (sensor.values !== undefined) {
|
||||
if (!((sensor.values === undefined) || (chpvalues === undefined))) {
|
||||
oneAktData = {
|
||||
location: sensor.location[0].loc.coordinates,
|
||||
id: sensor._id,
|
||||
name: sensor.name[0].name,
|
||||
name: sensor.chip.name,
|
||||
indoor: sensor.location[0].indoor,
|
||||
lastseen: sensor.values.timestamp
|
||||
lastseen: chpvalues.timestamp
|
||||
}
|
||||
let now = new Date().getTime()
|
||||
if(oneAktData.lastseen !== '') {
|
||||
let diff = now - oneAktData.lastseen.getTime()
|
||||
const dt = new Date(oneAktData.lastseen).getTime()
|
||||
let diff = now - dt
|
||||
if (diff >= 365 * 24 * 3600 * 1000) {
|
||||
oneAktData.value = -4
|
||||
} else if (diff >= 30 * 24 * 3600 * 1000) {
|
||||
@@ -156,15 +166,15 @@ export var getData4map = async (params) => {
|
||||
} else if (diff >= 2 * 3600 * 1000) {
|
||||
oneAktData.value = -1
|
||||
} else {
|
||||
if (sensor.values !== undefined) {
|
||||
oneAktData.value = Math.round(sensor.values[v4map] * 100) / 100
|
||||
if (chpvalues !== undefined) {
|
||||
oneAktData.value = Math.round(chpvalues[v4map] * 100) / 100
|
||||
}
|
||||
}
|
||||
let weeks = Math.round(diff / (7 * 24 * 3600 * 1000))
|
||||
oneAktData.weeks = weeks
|
||||
}
|
||||
if (sensor.values.timestamp > lastDate) {
|
||||
lastDate = sensor.values.timestamp
|
||||
if (new Date(oneAktData.lastseen).getTime() > lastDate) {
|
||||
lastDate = new Date(oneAktData.lastseen).getTime()
|
||||
}
|
||||
} else {
|
||||
oneAktData.value = -5
|
||||
@@ -176,7 +186,7 @@ export var getData4map = async (params) => {
|
||||
ret = {
|
||||
err: null,
|
||||
options: {
|
||||
lastdate: lastDate,
|
||||
lastdate: new Date(lastDate).toISOString(),
|
||||
count: aktData.length,
|
||||
data: 'map'
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user