*** WIP WIP *** some smaller changes
This commit is contained in:
@@ -31,7 +31,7 @@ export const getOneProperty = async (params) => {
|
|||||||
// now find sensors with same location
|
// now find sensors with same location
|
||||||
let query = {"location.0.id": pp.properties.location[0].id}
|
let query = {"location.0.id": pp.properties.location[0].id}
|
||||||
let others = await readProperties(query)
|
let others = await readProperties(query)
|
||||||
if (others.error) {
|
if (others.err) {
|
||||||
return returnOnError(properties, ERR.NOPROPSREAD.replace('xx',others.errortext), getOneProperty.name)
|
return returnOnError(properties, ERR.NOPROPSREAD.replace('xx',others.errortext), getOneProperty.name)
|
||||||
}
|
}
|
||||||
if (others.properties.length > 0) {
|
if (others.properties.length > 0) {
|
||||||
|
|||||||
+10
-187
@@ -25,9 +25,6 @@ if (MONGOAUTH === 'true') {
|
|||||||
|
|
||||||
export const properties_collection = 'pptest'
|
export const properties_collection = 'pptest'
|
||||||
|
|
||||||
let statistics = {}
|
|
||||||
let client
|
|
||||||
|
|
||||||
export const connectMongo = async () => {
|
export const connectMongo = async () => {
|
||||||
try {
|
try {
|
||||||
logit(`Try to connect to ${MONGO_URL}`)
|
logit(`Try to connect to ${MONGO_URL}`)
|
||||||
@@ -41,10 +38,6 @@ export const connectMongo = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const closeMongo = async (client) => {
|
|
||||||
client.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
const listDatabases = async (client) => {
|
const listDatabases = async (client) => {
|
||||||
let databasesList = await client.db().admin().listDatabases();
|
let databasesList = await client.db().admin().listDatabases();
|
||||||
|
|
||||||
@@ -59,7 +52,7 @@ const listDatabases = async (client) => {
|
|||||||
// Read properties from the database
|
// Read properties from the database
|
||||||
export const readProperties = async (query, limit = 0) => {
|
export const readProperties = async (query, limit = 0) => {
|
||||||
let ret = {err: null, properties: null}
|
let ret = {err: null, properties: null}
|
||||||
client = await connectMongo()
|
let client = await connectMongo()
|
||||||
try {
|
try {
|
||||||
if ("sid" in query) { // if sid is given, read property for sid
|
if ("sid" in query) { // if sid is given, read property for sid
|
||||||
ret.properties = await client.db(MONGOBASE).collection(properties_collection).findOne({_id: query.sid})
|
ret.properties = await client.db(MONGOBASE).collection(properties_collection).findOne({_id: query.sid})
|
||||||
@@ -70,8 +63,7 @@ export const readProperties = async (query, limit = 0) => {
|
|||||||
ret.err = e
|
ret.err = e
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
await closeMongo(client)
|
client.close()
|
||||||
client = null
|
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -79,15 +71,14 @@ export const readProperties = async (query, limit = 0) => {
|
|||||||
// read mapdata from database
|
// read mapdata from database
|
||||||
export const readMapdata = async (query, limit) => {
|
export const readMapdata = async (query, limit) => {
|
||||||
let ret = {err: null, mapdata: []}
|
let ret = {err: null, mapdata: []}
|
||||||
client = await connectMongo()
|
let client = await connectMongo()
|
||||||
try {
|
try {
|
||||||
ret.mapdata = 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) {
|
} catch (e) {
|
||||||
ret.err = e
|
ret.err = e
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
await closeMongo(client)
|
client.close()
|
||||||
client = null
|
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -95,7 +86,7 @@ export const readMapdata = async (query, limit) => {
|
|||||||
|
|
||||||
export const getallProperties = async (coll, query) => {
|
export const getallProperties = async (coll, query) => {
|
||||||
let ret = {err: null, properties: []}
|
let ret = {err: null, properties: []}
|
||||||
client = await connectMongo()
|
let client = await connectMongo()
|
||||||
try {
|
try {
|
||||||
ret.properties = await client.db(MONGOBASE).collection(coll)
|
ret.properties = await client.db(MONGOBASE).collection(coll)
|
||||||
.find(query).toArray()
|
.find(query).toArray()
|
||||||
@@ -103,8 +94,7 @@ export const getallProperties = async (coll, query) => {
|
|||||||
ret.err = e
|
ret.err = e
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
await closeMongo(client)
|
client.close()
|
||||||
client = null
|
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
@@ -112,7 +102,7 @@ export const getallProperties = async (coll, query) => {
|
|||||||
|
|
||||||
export const getOneproperty = async (sid) => {
|
export const getOneproperty = async (sid) => {
|
||||||
let ret = {error: false}
|
let ret = {error: false}
|
||||||
client = await connectMongo()
|
let client = await connectMongo()
|
||||||
try {
|
try {
|
||||||
ret.properties = await client.db(MONGOBASE).collection("properties_collection")
|
ret.properties = await client.db(MONGOBASE).collection("properties_collection")
|
||||||
.findOne({_id: sid})
|
.findOne({_id: sid})
|
||||||
@@ -120,125 +110,16 @@ export const getOneproperty = async (sid) => {
|
|||||||
ret = {error: true, errortext: e}
|
ret = {error: true, errortext: e}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
await closeMongo(client)
|
client.close()
|
||||||
client = null
|
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const doAggregate = async (coll, query, conn, clos) => {
|
|
||||||
let ret = {error: false}
|
|
||||||
if (conn) {
|
|
||||||
client = await connectMongo()
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ret.values = await client.db(MONGOBASE).collection(coll).aggregate(query).toArray()
|
|
||||||
} catch (e) {
|
|
||||||
ret = {error: true, errortext: e}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (clos) {
|
|
||||||
await closeMongo(client)
|
|
||||||
client = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export const writeOneproperty = async (client, prop) => {
|
|
||||||
try {
|
|
||||||
let result = await client.db(MONGOBASE).collection("properties_collection")
|
|
||||||
.insertOne(prop)
|
|
||||||
} catch(e) {
|
|
||||||
if (e.code === 11000) {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
throw(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
export const writeProperties = async (client, props) => {
|
|
||||||
let start = DateTime.now();
|
|
||||||
if (props.new.length !== 0) {
|
|
||||||
try {
|
|
||||||
let result = await client.db(MONGOBASE).collection("properties_collection")
|
|
||||||
.insertMany(props.new)
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (props.loc.length !== 0) {
|
|
||||||
try {
|
|
||||||
for (let item of props.loc) {
|
|
||||||
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}}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (props.sname.lenth !== 0) {
|
|
||||||
try {
|
|
||||||
for (let item of props.sname) {
|
|
||||||
let result = await client.db(MONGOBASE).collection("properties_collection")
|
|
||||||
.updateOne({_id: item._id}, {
|
|
||||||
$set: {name: item.name, since: item.since}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
statistics.writePropsTime = DateTime.now().diff(start, ['seconds']).toObject().seconds
|
|
||||||
logit(`Write properties to mongoDB: ${statistics.writePropsTime} sec.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const writeDataArray = async (data, collection, conn, clos) => {
|
|
||||||
let start = DateTime.now();
|
|
||||||
let result
|
|
||||||
if (conn) {
|
|
||||||
client = await connectMongo()
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
result = await client.db(MONGOBASE).collection(collection)
|
|
||||||
.insertMany(data)
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
} finally {
|
|
||||||
if(clos) {
|
|
||||||
await closeMongo(client)
|
|
||||||
client = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
statistics.writeDataTime = DateTime.now().diff(start, ['seconds']).toObject().seconds
|
|
||||||
logit(`Write Data to mongoDB: ${statistics.writeDataTime} sec.`)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
export const writeStatistic = async (client, stat) => {
|
|
||||||
let start = DateTime.now();
|
|
||||||
let entry = { timestamp: new Date(), ...stat }
|
|
||||||
try {
|
|
||||||
let result = await client.db(MONGOBASE).collection("statistics")
|
|
||||||
.insertOne(entry)
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
statistics.writeStatisticTime = DateTime.now().diff(start, ['seconds']).toObject().seconds
|
|
||||||
logit(`Write statistics to mongoDB: ${statistics.writeStatisticTime} sec.`)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const readAKWs = async (options) => {
|
export const readAKWs = async (options) => {
|
||||||
let ret = {values: { akws: [], th1_akws: []}, err: null}
|
let ret = {values: { akws: [], th1_akws: []}, err: null}
|
||||||
let erg = []
|
let erg = []
|
||||||
client = await connectMongo()
|
let client = await connectMongo()
|
||||||
try {
|
try {
|
||||||
let docs = await client.db(MONGOBASE).collection("akws")
|
let docs = await client.db(MONGOBASE).collection("akws")
|
||||||
.find().toArray()
|
.find().toArray()
|
||||||
@@ -258,65 +139,7 @@ export const readAKWs = async (options) => {
|
|||||||
return returnOnError(ret, e, readAKWs.name)
|
return returnOnError(ret, e, readAKWs.name)
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
await closeMongo(client)
|
client.close()
|
||||||
client = null
|
|
||||||
}
|
}
|
||||||
return ret
|
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
|
|
||||||
};
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ export const dayNightData = (params, values) => {
|
|||||||
let options = utils.createGlobObtions()
|
let options = utils.createGlobObtions()
|
||||||
// options.xAxis.plotBands = utils.calcWeekends(data, true)
|
// options.xAxis.plotBands = utils.calcWeekends(data, true)
|
||||||
options.xAxis.tickInterval = 24 * 3600 * 1000
|
options.xAxis.tickInterval = 24 * 3600 * 1000
|
||||||
options.xAxis.title = 'Date'
|
options.xAxis.title.text = 'Date'
|
||||||
// options.xAxis.labels = {
|
// options.xAxis.labels = {
|
||||||
// formatter: function () {
|
// formatter: function () {
|
||||||
// return this.axis.defaultLabelFormatter.call(this);
|
// return this.axis.defaultLabelFormatter.call(this);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ export function createGlobObtions() {
|
|||||||
let globObject = {
|
let globObject = {
|
||||||
chart: {
|
chart: {
|
||||||
height: 600,
|
height: 600,
|
||||||
// width: 1000,
|
|
||||||
spacingRight: 20,
|
spacingRight: 20,
|
||||||
spacingLeft: 20,
|
spacingLeft: 20,
|
||||||
spacingTop: 25,
|
spacingTop: 25,
|
||||||
|
|||||||
Reference in New Issue
Block a user