getCityCoords added
remove 'noise_' on every value
This commit is contained in:
Vendored
+4
-4
@@ -30,10 +30,10 @@
|
|||||||
],
|
],
|
||||||
"program": "${workspaceFolder}/bin/www.js",
|
"program": "${workspaceFolder}/bin/www.js",
|
||||||
"env": {
|
"env": {
|
||||||
"INFLUXHOST": "esprimo",
|
"MONGOUSRP": "rexfue:noise4mongo",
|
||||||
"INFLUXTOKEN": "uhsrE9MZtlVD18JnP19y0O0NW9C8HaQV3ElyAT_VwUlreluNsc9rM4djI9H10f6Dcw4oMFUzSngAo9dxtLjUoA==",
|
"MONGOAUTH": "true",
|
||||||
"MONGOHOST": "esprimo",
|
"INFLUXTOKEN": "q35XUBaElzcy8dDd9HF2_mpeHvYCampZg_9mJNP5jeBQRopq3EWIzNTZ555QLSIXhZC05RXCoFgjiaT7VzyNkQ==",
|
||||||
"MONGOPORT": "27098",
|
"DEVELOP": "true",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
+2
-2
@@ -9,7 +9,7 @@ const DEFAULT_DISTANCE = 10
|
|||||||
|
|
||||||
// Value to use fpr map
|
// Value to use fpr map
|
||||||
const value4map = [
|
const value4map = [
|
||||||
{ typ: 'noise', value: 'noise_LA_max'},
|
{ typ: 'noise', value: 'LA_max'},
|
||||||
{ typ: 'pm', value: 'P1'},
|
{ typ: 'pm', value: 'P1'},
|
||||||
{ typ: 'thp', value: 'temperature'},
|
{ typ: 'thp', value: 'temperature'},
|
||||||
{ typ: 'radioactivity', value: 'counts_per_minute'},
|
{ typ: 'radioactivity', value: 'counts_per_minute'},
|
||||||
@@ -29,7 +29,7 @@ const getValue4Map = (t) => {
|
|||||||
const vtype2measurement = {
|
const vtype2measurement = {
|
||||||
P1: 'pm', P2: 'pm', P0: 'pm',
|
P1: 'pm', P2: 'pm', P0: 'pm',
|
||||||
temperature: 'thp', humidity: 'thp', pressure: 'thp',
|
temperature: 'thp', humidity: 'thp', pressure: 'thp',
|
||||||
noise_LAeq: 'noise',
|
LAeq: 'noise',
|
||||||
counts_per_minute: 'radioactivity'
|
counts_per_minute: 'radioactivity'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,27 @@ import {returnOnError} from "../utilities/reporterror.js"
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import {logit} from "../utilities/logit.js"
|
import {logit} from "../utilities/logit.js"
|
||||||
import {getOneProperty} from "./getproperties.js"
|
import {getOneProperty} from "./getproperties.js"
|
||||||
|
import { response } from "express"
|
||||||
|
|
||||||
const NOMINATIM_URL = `https://nominatim.openstreetmap.org/reverse?lat=${'xx'}&lon=${'yy'}&format=json`
|
const NOMINATIM_URL = `https://nominatim.openstreetmap.org/reverse?lat=${'xx'}&lon=${'yy'}&format=json`
|
||||||
|
const NOMINATIM_CITY_URL = `https://nominatim.openstreetmap.org/?q="${'xx'}"&format=json`
|
||||||
|
|
||||||
|
export const getCityCoords = async (params) => {
|
||||||
|
let ret = {coords: [], city: params.city, err: null}
|
||||||
|
let url = NOMINATIM_CITY_URL.replace('xx', params.city)
|
||||||
|
// let url = 'https://nominatim.openstreetmap.org/?q="K%C3%B6ln"&format=json'
|
||||||
|
try {
|
||||||
|
const response = await axios(url)
|
||||||
|
if (response.status !== 200) {
|
||||||
|
return returnOnError(ret, 'RESPSTATUS', getCityCoord.name, response.status)
|
||||||
|
}
|
||||||
|
ret.coords = [response.data[0].lat,response.data[0].lon]
|
||||||
|
logit(JSON.stringify(ret.coords))
|
||||||
|
} catch (e) {
|
||||||
|
return returnOnError(ret, e, getCityCoords.name)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
export const getAddress = async (params) => {
|
export const getAddress = async (params) => {
|
||||||
let ret = {address: "", err: null}
|
let ret = {address: "", err: null}
|
||||||
|
|||||||
@@ -250,8 +250,8 @@ export var getLongAvg = async (params) => {
|
|||||||
// return
|
// return
|
||||||
// JSON
|
// JSON
|
||||||
// { avgs: [
|
// { avgs: [
|
||||||
// { location: [ 9.00, 48.80 ], id: 29174, lastSeen: "2019-10-23T12:03:00.000Z", noise_max: "65" }
|
// { location: [ 9.00, 48.80 ], id: 29174, lastSeen: "2019-10-23T12:03:00.000Z", max: "65" }
|
||||||
// { location: [ 9.10, 49.80 ], id: 28194, lastSeen: "2019-10-22T16:03:00.000Z", noise_max: "45" }
|
// { location: [ 9.10, 49.80 ], id: 28194, lastSeen: "2019-10-22T16:03:00.000Z", max: "45" }
|
||||||
// .........
|
// .........
|
||||||
// ], lastDate: "2019-10-29T15:05:59.000Z" }
|
// ], lastDate: "2019-10-29T15:05:59.000Z" }
|
||||||
//
|
//
|
||||||
@@ -295,8 +295,8 @@ export const getMAPaktData = async (opt) => {
|
|||||||
oneAktData['noise_max'] = -1 // -1 zurückgeben
|
oneAktData['noise_max'] = -1 // -1 zurückgeben
|
||||||
} else {
|
} else {
|
||||||
oneAktData['noise_max'] = -5 // bedutet -> nicht anzeigen
|
oneAktData['noise_max'] = -5 // bedutet -> nicht anzeigen
|
||||||
if (item.values.hasOwnProperty('noise_LA_max')) {
|
if (item.values.hasOwnProperty('LA_max')) {
|
||||||
oneAktData['noise_max'] = item.values.noise_LA_max.toFixed(0) // und merken
|
oneAktData['noise_max'] = item.values.LA_max.toFixed(0) // und merken
|
||||||
}
|
}
|
||||||
if (dati > lastDate) {
|
if (dati > lastDate) {
|
||||||
lastDate = dati
|
lastDate = dati
|
||||||
|
|||||||
+1
-1
@@ -142,7 +142,7 @@ esum = data
|
|||||||
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|
||||||
|> rename(columns: {"E10tel_eq" : "n_sum"})
|
|> rename(columns: {"E10tel_eq" : "n_sum"})
|
||||||
peak = data
|
peak = data
|
||||||
|> filter(fn: (r) => r._field == "noise_LA_max")
|
|> filter(fn: (r) => r._field == "LA_max")
|
||||||
|> aggregateWindow(
|
|> aggregateWindow(
|
||||||
every: 1h,
|
every: 1h,
|
||||||
fn: (column, tables=<-) => tables
|
fn: (column, tables=<-) => tables
|
||||||
|
|||||||
+22
-5
@@ -28,7 +28,7 @@ export const properties_collection = 'properties'
|
|||||||
|
|
||||||
export const connectMongo = async () => {
|
export const connectMongo = async () => {
|
||||||
try {
|
try {
|
||||||
// logit(`Try to connect to ${MONGO_URL}`)
|
// logit(`Try to connect to ${MONGO_URL}`)
|
||||||
let client = await MongoClient.connect(MONGO_URL)
|
let client = await MongoClient.connect(MONGO_URL)
|
||||||
// logit(`Mongodbase connected to ${MONGO_URL}`)
|
// logit(`Mongodbase connected to ${MONGO_URL}`)
|
||||||
return client
|
return client
|
||||||
@@ -154,8 +154,25 @@ export const fetchActData = async (opts) => {
|
|||||||
let options = { projection: {_id: 0, values: 1, datetime: 1}, sort: {datetime: 1}}
|
let options = { projection: {_id: 0, values: 1, datetime: 1}, sort: {datetime: 1}}
|
||||||
let client = await connectMongo()
|
let client = await connectMongo()
|
||||||
try {
|
try {
|
||||||
ret.values = await client.db(MONGOBASE).collection('noise_sensors')
|
// ret.values = await client.db(MONGOBASE).collection('noise_sensors')
|
||||||
.find(query, options).toArray()
|
// .find(query, options).toArray()
|
||||||
|
ret.values = await client.db(MONGOBASE).collection('noise_sensors').aggregate([
|
||||||
|
{$match: query},
|
||||||
|
{$sort: { datetime: 1}},
|
||||||
|
{$replaceWith:
|
||||||
|
{
|
||||||
|
datetime: {$dateToString: {format: '%Y-%m-%dT%H:%M:%SZ', date: '$datetime'}},
|
||||||
|
LA_min: '$values.LA_min',
|
||||||
|
LA_max: '$values.LA_max',
|
||||||
|
LAeq: '$values.LAeq',
|
||||||
|
E10tel_eq: '$values.E10tel_eq'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// {$project: {
|
||||||
|
// datetime: {$dateToString: {format: '%Y-%m-%dT%H:%M:%SZ', date: '$datetime'}},
|
||||||
|
// _id: 0, values:1
|
||||||
|
// }},
|
||||||
|
]).toArray()
|
||||||
}
|
}
|
||||||
catch(e) {
|
catch(e) {
|
||||||
ret.err = e
|
ret.err = e
|
||||||
@@ -279,7 +296,7 @@ export const fetchNoiseAVGData = async (opts) => {
|
|||||||
_id: grpId,
|
_id: grpId,
|
||||||
n_average: {$avg: "$values.E10tel_eq"}, // calculate the average
|
n_average: {$avg: "$values.E10tel_eq"}, // calculate the average
|
||||||
n_sum: {$sum: "$values.E10tel_eq"}, // calculate the sum
|
n_sum: {$sum: "$values.E10tel_eq"}, // calculate the sum
|
||||||
peakcount: {$sum: {$cond: [{$gte: ["$values.noise_LA_max", peak]}, 1, 0]}}, // count peaks
|
peakcount: {$sum: {$cond: [{$gte: ["$values.LA_max", peak]}, 1, 0]}}, // count peaks
|
||||||
count: {$sum: 1}, // count entries
|
count: {$sum: 1}, // count entries
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -345,7 +362,7 @@ async function getAverageData(db,opt) {
|
|||||||
_id: grpId,
|
_id: grpId,
|
||||||
n_average: {$avg: '$E10tel_eq'}, // calculate the average
|
n_average: {$avg: '$E10tel_eq'}, // calculate the average
|
||||||
n_sum: {$sum: '$E10tel_eq'}, // calculate the sum
|
n_sum: {$sum: '$E10tel_eq'}, // calculate the sum
|
||||||
peakcount: {$sum: {$cond: [{$gte: ["$noise_LA_max", peak]}, 1, 0]}}, // count peaks
|
peakcount: {$sum: {$cond: [{$gte: ["$LA_max", peak]}, 1, 0]}}, // count peaks
|
||||||
count: {$sum: 1}, // count entries
|
count: {$sum: 1}, // count entries
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const cmdTable = [
|
|||||||
{cmd: 'getoneproperty', func: getProps.getOneProperty},
|
{cmd: 'getoneproperty', func: getProps.getOneProperty},
|
||||||
{cmd: 'getakwdata', func: getAKWs.getakwdata},
|
{cmd: 'getakwdata', func: getAKWs.getakwdata},
|
||||||
{cmd: 'getaddress', func: holAddr.getAddress},
|
{cmd: 'getaddress', func: holAddr.getAddress},
|
||||||
|
{cmd: 'getcitycoords', func: holAddr.getCityCoords},
|
||||||
{cmd: 'getsensordata', func: getData.getSensorData},
|
{cmd: 'getsensordata', func: getData.getSensorData},
|
||||||
{cmd: 'getmapdata', func: getData4map}
|
{cmd: 'getmapdata', func: getData4map}
|
||||||
]
|
]
|
||||||
|
|||||||
+21
-6
@@ -45,7 +45,7 @@ export const getNoiseData = async (params, possibles, props) => {
|
|||||||
sid: opts.sensorid,
|
sid: opts.sensorid,
|
||||||
indoor: props.location[0].indoor,
|
indoor: props.location[0].indoor,
|
||||||
span: opts.span,
|
span: opts.span,
|
||||||
start: DateTime.fromISO(opts.start.slice(7)).toUTC().toISO(),
|
start: DateTime.fromISO(opts.start.slice(7)).toUTC().toFormat("yyyy-LL-dd'T'HH:mm:ss'Z'"),
|
||||||
data: opts.data,
|
data: opts.data,
|
||||||
peak: opts.peak,
|
peak: opts.peak,
|
||||||
count: erg.values.length,
|
count: erg.values.length,
|
||||||
@@ -78,8 +78,8 @@ export const getNoiseData = async (params, possibles, props) => {
|
|||||||
// return:
|
// return:
|
||||||
// JSON:
|
// JSON:
|
||||||
// { sid: 29212, span: 1, start: "2019-10-23T00:00", count: 381, values: [
|
// { sid: 29212, span: 1, start: "2019-10-23T00:00", count: 381, values: [
|
||||||
// { datetime: "2019-10-22T22:05:34.000Z", noise_LAeq: 42.22, noise_LA_min: 39.91, noise_LA_max: 45.18, E10tel_eq: 16672.47212551061 },
|
// { datetime: "2019-10-22T22:05:34.000Z", LAeq: 42.22, LA_min: 39.91, LA_max: 45.18, E10tel_eq: 16672.47212551061 },
|
||||||
// { datetime: "2019-10-22T22:07:59.000Z", noise_LAeq: 53.72, noise_LA_min: 39.97, noise_LA_max: 63.54, E10tel_eq: 235504.9283896009 },
|
// { datetime: "2019-10-22T22:07:59.000Z", LAeq: 53.72, LA_min: 39.97, LA_max: 63.54, E10tel_eq: 235504.9283896009 },
|
||||||
// .........
|
// .........
|
||||||
// ]}
|
// ]}
|
||||||
// CSV
|
// CSV
|
||||||
@@ -92,6 +92,21 @@ export const getNoiseData = async (params, possibles, props) => {
|
|||||||
// *********************************************
|
// *********************************************
|
||||||
const getLiveData = async (opts) => {
|
const getLiveData = async (opts) => {
|
||||||
const erg = await getActData(opts)
|
const erg = await getActData(opts)
|
||||||
|
if (opts.csv) {
|
||||||
|
let csvStr = "datetime,LAeq,LAmax,LAmin,10^(LAeq/10)\n"
|
||||||
|
if (!erg.err) {
|
||||||
|
for (let item of erg.values) {
|
||||||
|
if (item.n_AVG != -1) {
|
||||||
|
csvStr += item.datetime + ','
|
||||||
|
+ item.LAeq + ','
|
||||||
|
+ item.LA_max + ','
|
||||||
|
+ item.LA_min+ ','
|
||||||
|
+ item.E10tel_eq + '\n'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return csvStr
|
||||||
|
}
|
||||||
return erg
|
return erg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +197,7 @@ async function getdavgData(opts) {
|
|||||||
pk += item.peakcount;
|
pk += item.peakcount;
|
||||||
if (werte.datetime === undefined) {
|
if (werte.datetime === undefined) {
|
||||||
let dt = DateTime.fromISO(item.datetime)
|
let dt = DateTime.fromISO(item.datetime)
|
||||||
werte.datetime = dt.startOf('day').toISO()
|
werte.datetime = dt.startOf('day').toFormat("yyyy-LL-dd'T'HH:mm:ss'Z'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +225,7 @@ async function getdavgData(opts) {
|
|||||||
const addDatetime = (werte, item) => {
|
const addDatetime = (werte, item) => {
|
||||||
if (werte.datetime === undefined) {
|
if (werte.datetime === undefined) {
|
||||||
let dt = DateTime.fromISO(item.datetime)
|
let dt = DateTime.fromISO(item.datetime)
|
||||||
werte.datetime = dt.startOf('day').toISO()
|
werte.datetime = dt.startOf('day').toFormat("yyyy-LL-dd'T'HH:mm:ss'Z'")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,7 +449,7 @@ const getNoiseAVGData = async (opts) => {
|
|||||||
ret = await influx.fetchNoiseAVGData(opts)
|
ret = await influx.fetchNoiseAVGData(opts)
|
||||||
// Influx stores the average from 00:00h to 01:00h as 01:00h, so we have to shift the time 1 hour back
|
// Influx stores the average from 00:00h to 01:00h as 01:00h, so we have to shift the time 1 hour back
|
||||||
for (let x=0; x < ret.values.length; x++) {
|
for (let x=0; x < ret.values.length; x++) {
|
||||||
ret.values[x].datetime = DateTime.fromISO(ret.values[x].datetime).toUTC().minus({hours:1}).toISO()
|
ret.values[x].datetime = DateTime.fromISO(ret.values[x].datetime).toUTC().minus({hours:1}).toFormat("yyyy-LL-dd'T'HH:mm:ss'Z'")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret.err = 'DBASEUNKNOWN'
|
ret.err = 'DBASEUNKNOWN'
|
||||||
|
|||||||
Reference in New Issue
Block a user