This commit is contained in:
Ubuntu 2016-08-22 14:58:26 +01:00
commit ef22636be6
3 changed files with 89 additions and 3 deletions

83
filler.js Normal file
View File

@ -0,0 +1,83 @@
var log4js = require('log4js');
var logger = log4js.getLogger();
var db = require('./lib/server/db-connector').dbConnection;
var dbSave = require('./lib/server/db-save')(db);
var Sugar = require('sugar-date');
var mdot = require('./lib/mdot/mdot.js');
(
function() {
var doInsertEntry = (obj) => {
// Logger.info('sendSocket: ' + JSON.stringify(obj));
// insertEntry(obj);
/*
dbSave.addNewEvent(obj)
.then(function(d) {
'use strict';
logger.info('Finished - Raw',d);
})
.catch(function(e) {
'use strict';
logger.error(e);
});
*/
dbSave.addProcessedEvent(obj)
.then(function(d) {
'use strict';
logger.info('Finished - Processed',d);
})
.catch(function(e) {
'use strict';
logger.error(e);
});
};
var device = 3;
var ids = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1','HIE-demo','HIE-mobile-2','HIE-smart-campus-1','HIE-smart-campus-2','HIE-smart-campus-3','HIE-smart-campus-4','HIE-smart-campus-5','HIE-smart-campus-6','HIE-smart-campus-7','HIE-mDot-1'];
var data = {id: ids[device]};
var startTs = Sugar.Date.create('2016-08-19 14:46:48');
var endTs = Sugar.Date.create('2016-08-21 10:03:39');
logger.debug(startTs, endTs);
logger.debug(startTs.getTime(), endTs.getTime());
data.start = startTs.getTime();
data.end = endTs.getTime();
mdot.doGet(data)
.then(function(d) {
'use strict';
//Logger.debug(d);
for (var item in d.events) {
var newItem = d.events[item].evt;
newItem.topic=['','','','',ids[device]].join('/');
logger.debug(newItem);
var gwTime = new Date(newItem.gateway_info['0'].gw_time);
if ((gwTime > startTs) && (gwTime < endTs)) {
doInsertEntry(newItem);
} else {
logger.warn('Out of range...');
}
}
})
.catch(function(err) {
'use strict';
logger.error(err);
});
}
)();

View File

@ -26,6 +26,8 @@ module.exports = function(db) {
let _data = data;
console.log('sqlInsertDecoded', _data.deviceid, _data.timestamp);
console.log('insert_decoded',
[_data.deviceid, _data.timestamp, _data.lux, _data.co2, _data.temp, _data.humidity, _data.sound]);
return new Promise(function(resolve, reject) {
db.func('insert_decoded',
[_data.deviceid, _data.timestamp, _data.lux, _data.co2, _data.temp, _data.humidity, _data.sound])
@ -66,6 +68,8 @@ module.exports = function(db) {
let _data = self.rawBreaker(data);
console.log(_data);
self.sqlInsertDecoded(_data)
.then((d)=> {
console.log('Postgres returns', d);
@ -100,9 +104,7 @@ module.exports = function(db) {
var workObj = {};
var device_name = data.topic.split('/')[4];
console.log('Device_name', device_name);
workObj.deviceid = self.deviceIds.indexOf(device_name);
if (data.hasOwnProperty('data')) {
var _data = self.decoder(data.data);
@ -112,7 +114,7 @@ module.exports = function(db) {
workObj.temp = _data.temp;
workObj.humidity = _data.humid;
workObj.sound = _data.noise;
workObj.timestamp = new Date();
workObj.timestamp = new Date(data.gateway_info['0'].gw_time);
return workObj;
} else {

View File

@ -7,6 +7,7 @@
"test": "test"
},
"dependencies": {
"atob": "^2.0.3",
"body-parser": "^1.15.1",
"btoa": "^1.1.2",
"cookie-parser": "*",