mdot_server/filler.js

84 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-08-22 13:56:42 +00:00
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);
});
};
2016-08-23 08:45:59 +00:00
var device = 13;
2016-08-22 13:56:42 +00:00
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');
2016-08-23 08:45:59 +00:00
// logger.debug(startTs, endTs);
// logger.debug(startTs.getTime(), endTs.getTime());
2016-08-22 13:56:42 +00:00
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('/');
2016-08-23 08:45:59 +00:00
// logger.debug(newItem);
2016-08-22 13:56:42 +00:00
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);
});
}
)();