mdot_server/filler.js

100 lines
2.4 KiB
JavaScript

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 doBulkInsert = (qArray) => {
'use strict';
logger.info('Doing bulk insert...');
dbSave.doBulkInsert(qArray)
.then(function(d) {
logger.info('Finished bulk insert');
})
.catch(function(e) {
logger.error(e);
});
};
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 queries = [];
var device = 8;
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('2015-07-19 14:46:48');
var startTs = Sugar.Date.create('2015-8-29 08:46:48');
var endTs = Sugar.Date.create('2016-08-29 09:35:36');
// first record recorded "2016-08-29 09:44:59+00"
// 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);
logger.info('Number of items:', d.events.length);
for (var item in d.events) {
var newItem = d.events[item];
queries.push(dbSave.genRawQuery(newItem));
}
doBulkInsert(queries);
logger.info('Number of queries:', queries.length);
})
.catch(function(err) {
'use strict';
logger.error(err);
});
}
)();