Many changes to have Noise Live Chart
This commit is contained in:
+84
-14
@@ -23,6 +23,8 @@ if (MONGOAUTH === 'true') {
|
||||
MONGO_URL = 'mongodb://'+MONGOUSRP+'@' + MONGOHOST + ':' + MONGOPORT + '/?authSource=' + MONGOBASE; // URL to mongo database
|
||||
}
|
||||
|
||||
export const properties_collection = 'pptest'
|
||||
|
||||
let statistics = {}
|
||||
let client
|
||||
|
||||
@@ -56,13 +58,13 @@ const listDatabases = async (client) => {
|
||||
|
||||
// Read properties from the database
|
||||
export const readProperties = async (query, limit = 0) => {
|
||||
let ret = {err: null, values: null}
|
||||
let ret = {err: null, properties: null}
|
||||
client = await connectMongo()
|
||||
try {
|
||||
if ("sid" in query) { // if sid is given, read property for sid
|
||||
ret.values = await client.db(MONGOBASE).collection("properties").findOne({_id: query.sid})
|
||||
ret.properties = await client.db(MONGOBASE).collection(properties_collection).findOne({_id: query.sid})
|
||||
} else { // otherwise read props corresponding to query
|
||||
ret.values = await client.db(MONGOBASE).collection("properties").find(query).limit(limit).toArray()
|
||||
ret.properties = await client.db(MONGOBASE).collection(properties_collection).find(query).limit(limit).toArray()
|
||||
}
|
||||
} catch (e) {
|
||||
ret.err = e
|
||||
@@ -76,10 +78,10 @@ export const readProperties = async (query, limit = 0) => {
|
||||
|
||||
// read mapdata from database
|
||||
export const readMapdata = async (query, limit) => {
|
||||
let ret = {err: null, values: []}
|
||||
let ret = {err: null, mapdata: []}
|
||||
client = await connectMongo()
|
||||
try {
|
||||
ret.values = await client.db(MONGOBASE).collection("mapdata").find(query).limit(limit).toArray()
|
||||
ret.mapdata = await client.db(MONGOBASE).collection("mapdata").find(query).limit(limit).toArray()
|
||||
} catch (e) {
|
||||
ret.err = e
|
||||
}
|
||||
@@ -91,17 +93,28 @@ export const readMapdata = async (query, limit) => {
|
||||
}
|
||||
|
||||
|
||||
export const getallProperties = async (client) => {
|
||||
return await client.db(MONGOBASE).collection("properties")
|
||||
.find().toArray()
|
||||
|
||||
export const getallProperties = async (coll, query) => {
|
||||
let ret = {err: null, properties: []}
|
||||
client = await connectMongo()
|
||||
try {
|
||||
ret.properties = await client.db(MONGOBASE).collection(coll)
|
||||
.find(query).toArray()
|
||||
} catch (e) {
|
||||
ret.err = e
|
||||
}
|
||||
finally {
|
||||
await closeMongo(client)
|
||||
client = null
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
export const getOneproperty = async (sid) => {
|
||||
let ret = {error: false}
|
||||
client = await connectMongo()
|
||||
try {
|
||||
ret.properties = await client.db(MONGOBASE).collection("properties")
|
||||
ret.properties = await client.db(MONGOBASE).collection("properties_collection")
|
||||
.findOne({_id: sid})
|
||||
} catch (e) {
|
||||
ret = {error: true, errortext: e}
|
||||
@@ -136,7 +149,7 @@ export const doAggregate = async (coll, query, conn, clos) => {
|
||||
|
||||
export const writeOneproperty = async (client, prop) => {
|
||||
try {
|
||||
let result = await client.db(MONGOBASE).collection("properties")
|
||||
let result = await client.db(MONGOBASE).collection("properties_collection")
|
||||
.insertOne(prop)
|
||||
} catch(e) {
|
||||
if (e.code === 11000) {
|
||||
@@ -152,7 +165,7 @@ export const writeProperties = async (client, props) => {
|
||||
let start = DateTime.now();
|
||||
if (props.new.length !== 0) {
|
||||
try {
|
||||
let result = await client.db(MONGOBASE).collection("properties")
|
||||
let result = await client.db(MONGOBASE).collection("properties_collection")
|
||||
.insertMany(props.new)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
@@ -161,7 +174,7 @@ export const writeProperties = async (client, props) => {
|
||||
if (props.loc.length !== 0) {
|
||||
try {
|
||||
for (let item of props.loc) {
|
||||
let result = await client.db(MONGOBASE).collection("properties")
|
||||
let result = await client.db(MONGOBASE).collection("properties_collection")
|
||||
.updateOne({_id: item._id}, {
|
||||
$set: {location_id: item.location_id},
|
||||
$push: {location: { $each: [item.location[0]], $position: 0}}
|
||||
@@ -174,7 +187,7 @@ export const writeProperties = async (client, props) => {
|
||||
if (props.sname.lenth !== 0) {
|
||||
try {
|
||||
for (let item of props.sname) {
|
||||
let result = await client.db(MONGOBASE).collection("properties")
|
||||
let result = await client.db(MONGOBASE).collection("properties_collection")
|
||||
.updateOne({_id: item._id}, {
|
||||
$set: {name: item.name, since: item.since}
|
||||
})
|
||||
@@ -250,3 +263,60 @@ export const readAKWs = async (options) => {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
/*
|
||||
async function getMAPaktData(db,opt) {
|
||||
let box = opt.box;
|
||||
if ((box == "") || (box == undefined)) {
|
||||
return {"avgs": [], "lastDate": null};
|
||||
}
|
||||
var south = parseFloat(box[0][1]);
|
||||
var north = parseFloat(box[1][1]);
|
||||
var east = parseFloat(box[1][0]);
|
||||
var west = parseFloat(box[0][0]);
|
||||
var collection = db.collection('mapdata'); // use the mapdata collection
|
||||
var aktData = [];
|
||||
var now = moment();
|
||||
var lastDate = 0;
|
||||
let loc;
|
||||
loc = {
|
||||
location: {
|
||||
$geoWithin: {
|
||||
$box: [
|
||||
[west, south],
|
||||
[east, north]
|
||||
]
|
||||
}
|
||||
},
|
||||
name: { $regex : "^Laerm|^DNMS"},
|
||||
}
|
||||
let docs = await collection.find(loc).toArray();
|
||||
// console.log(docs);
|
||||
for (var i = 0; i < docs.length; i++) {
|
||||
var item = docs[i];
|
||||
var oneAktData = {};
|
||||
oneAktData['location'] = item.location.coordinates;
|
||||
oneAktData['id'] = item._id; // ID des Sensors holen
|
||||
oneAktData['lastSeen'] = item.values.datetime;
|
||||
oneAktData['indoor'] = item.indoor;
|
||||
var dati = item.values.datetime;
|
||||
var dt = new Date(dati);
|
||||
if ((now - dt) >= 31 * 24 * 3600 * 1000) { // älter als 1 Monat ->
|
||||
oneAktData['noise_max'] = -2; // -2 zurückgeben
|
||||
} else if ((now - dt) >= 3600 * 1000) { // älter als 1 Stunde ->
|
||||
oneAktData['noise_max'] = -1; // -1 zurückgeben
|
||||
} else {
|
||||
oneAktData['noise_max'] = -5; // bedutet -> nicht anzeigen
|
||||
if (item.values.hasOwnProperty('noise_LA_max')) {
|
||||
oneAktData['noise_max'] = item.values.noise_LA_max.toFixed(0); // und merken
|
||||
}
|
||||
if (dati > lastDate) {
|
||||
lastDate = dati;
|
||||
}
|
||||
}
|
||||
aktData.push(oneAktData); // dies ganzen Werte nun in das Array
|
||||
}
|
||||
return {"avgs": aktData, "lastDate": lastDate}; // alles bearbeitet _> Array senden
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user