mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-archive.git
synced 2025-02-04 08:20:15 +00:00
”2016-08-22”
This commit is contained in:
parent
0bfa4f6c4b
commit
ff8e7a9912
23174
mdot/mdot_mqtt/mdot_mqtt/backup.sql
Normal file
23174
mdot/mdot_mqtt/mdot_mqtt/backup.sql
Normal file
File diff suppressed because it is too large
Load Diff
@ -56,22 +56,22 @@ var doInsertEntry = (obj) => {
|
||||
dbSave.addNewEvent(obj)
|
||||
.then(function(d) {
|
||||
'use strict';
|
||||
console.log('Finished - Raw',d);
|
||||
logger.info('Finished - Raw',d);
|
||||
})
|
||||
.catch(function(e) {
|
||||
'use strict';
|
||||
console.error(e);
|
||||
logger.error(e);
|
||||
});
|
||||
|
||||
|
||||
dbSave.addProcessedEvent(obj)
|
||||
.then(function(d) {
|
||||
'use strict';
|
||||
console.log('Finished - Processed',d);
|
||||
logger.info('Finished - Processed',d);
|
||||
})
|
||||
.catch(function(e) {
|
||||
'use strict';
|
||||
console.error(e);
|
||||
logger.error(e);
|
||||
});
|
||||
};
|
||||
|
||||
@ -84,7 +84,7 @@ var mqttClient = function() {
|
||||
var address = '.messaging.internetofthings.ibmcloud.com';
|
||||
var appKey = '9txJEf3Cjy7hkSOvkv';
|
||||
var prefix = 'iot-2/type/mDot/id/';
|
||||
var deviceId = ['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 deviceId = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1','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 subscribeTopic = prefix + deviceId + '/evt/+/fmt/json';
|
||||
|
@ -17,6 +17,7 @@ module.exports = function(db) {
|
||||
return resolve('ok');
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
@ -33,6 +34,7 @@ module.exports = function(db) {
|
||||
return resolve('ok');
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
@ -54,6 +56,7 @@ module.exports = function(db) {
|
||||
return resolve({reply: 'raw event inserted'});
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
@ -72,6 +75,7 @@ module.exports = function(db) {
|
||||
return resolve({reply: 'Processed event inserted'});
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
return reject(err);
|
||||
});
|
||||
|
||||
@ -92,6 +96,7 @@ module.exports = function(db) {
|
||||
_obj.humid = (parseInt(_data[12] + _data[13] + _data[14] + _data[15] + _data[16], 10) / 10);
|
||||
_obj.noise = parseInt('0x' + ('0' + bytes[17]).substr(-2) + ('0' + bytes[18]).substr(-2));
|
||||
_obj.binData = bytes;
|
||||
console.log(_obj);
|
||||
return _obj;
|
||||
};
|
||||
|
||||
|
@ -54,58 +54,22 @@
|
||||
return newArray;
|
||||
|
||||
},
|
||||
findOccupancy: function(ts, occupancy)
|
||||
{
|
||||
let tsMS = new Date(ts).getTime();
|
||||
|
||||
// console.log(new Date(ts).getTime());
|
||||
// console.log(ts);
|
||||
_(occupancy).each(function(item) {
|
||||
|
||||
// console.log(new Date(item.start).getTime(), new Date(item.start).getTime());
|
||||
// console.log(item.start, item.end);
|
||||
if ((ts >= new Date(item.start).getTime()) && (ts <= new Date(item.end).getTime()))
|
||||
{
|
||||
// console.log('Occupancy', item.count);
|
||||
return item.count;
|
||||
}
|
||||
|
||||
}, this);
|
||||
return 0;
|
||||
},
|
||||
processAdded: function() {
|
||||
console.log('Model:ProcessAdded');
|
||||
var self = this;
|
||||
var tempCollection = new Backbone.Collection();
|
||||
var occuCollection = new Backbone.Collection();
|
||||
var occupancy = [];
|
||||
|
||||
var events;
|
||||
|
||||
_.invoke(DeviceCollection.toArray(), 'destroy');
|
||||
// _.invoke(OccupancyCollection.toArray(), 'destroy');
|
||||
|
||||
// console.log(this);
|
||||
|
||||
this.temporal = {low: 0, high: 0};
|
||||
events = this.get('events');
|
||||
|
||||
//_(this.get('events')).each(function(i) {
|
||||
_(events.data).each(function(i) {
|
||||
let _occupancy;
|
||||
|
||||
if (this.temporal.low === 0 || this.temporal.low > i.timestamp) {
|
||||
this.temporal.low = i.timestamp;
|
||||
}
|
||||
|
||||
if (this.temporal.high === 0 || this.temporal.high < i.timestamp) {
|
||||
this.temporal.high = i.timestamp;
|
||||
}
|
||||
|
||||
// _occupancy = this.findOccupancy(i.timestamp, events.occupancy);
|
||||
|
||||
tempCollection.add({
|
||||
dt: i.timestamp,
|
||||
dt: Date.create(i.timestamp).addHours(1),
|
||||
lux: i.lux,
|
||||
temp: i.temp,
|
||||
co2: i.co2,
|
||||
@ -115,16 +79,10 @@
|
||||
});
|
||||
}, this);
|
||||
|
||||
/* _(events.occupancy).each(function(item) {
|
||||
|
||||
occupancy = occupancy.concat(this.splitOccupancy(item));
|
||||
|
||||
}, this);*/
|
||||
|
||||
console.log('occupancy:', occupancy);
|
||||
|
||||
DeviceCollection.temporal = this.temporal;
|
||||
//DeviceCollection.occupancy = occupancy;
|
||||
|
||||
DeviceCollection.models = tempCollection.models;
|
||||
|
||||
@ -166,7 +124,7 @@
|
||||
url: 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/',
|
||||
initialize: function() {
|
||||
this.on('update', function() {
|
||||
// Console.log('Collection:update',this);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@ -176,7 +134,6 @@
|
||||
tagName: 'div', className: 'item mui-container', initialize: function() {
|
||||
this.template = _.template($('#item-template').html());
|
||||
console.log('ItemView:Init');
|
||||
// This.render();
|
||||
}, render: function() {
|
||||
|
||||
console.log('ItemView:Render');
|
||||
@ -197,9 +154,7 @@
|
||||
_.bindAll(this, 'render', 'refresh', 'update');
|
||||
this.collection.bind('change reset add remove', this.render, this);
|
||||
|
||||
//This.template = _.template($('#list-template').html());
|
||||
this.template = _.template($('#loaded-template').html());
|
||||
//This.render();
|
||||
}, refresh: function() {
|
||||
|
||||
}, update: function() {
|
||||
@ -209,10 +164,10 @@
|
||||
});
|
||||
|
||||
}, render: function() {
|
||||
var that = this;
|
||||
|
||||
console.log('MDOT:render');
|
||||
$('#output').empty();
|
||||
var that = this;
|
||||
// that.$el.append(this.template);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -246,11 +201,7 @@
|
||||
console.log('MainView:Updatedevice');
|
||||
notification.clearAll();
|
||||
if (this.model.has('device')) {
|
||||
// FetchObj.data = $.param({key:'"'+ this.model.get('device') + '"'});
|
||||
// this.collection.url = 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/' + this.model.get('device');
|
||||
// this.collection.url = '/api/mdot/' + this.model.get('device');
|
||||
this.collection.url = '/apiv2/mdot/' + this.model.get('device');
|
||||
// this.collection.url = 'http://127.0.0.1:5984/mdot/_design/getDevice/_view/getDevice';
|
||||
|
||||
$('#output').empty();
|
||||
this.collection.fetch(fetchObj);
|
||||
@ -277,13 +228,12 @@
|
||||
this.dataSet = new AmCharts.DataSet();
|
||||
|
||||
console.log('GraphView!');
|
||||
_.bindAll(this, 'render', 'updateGraph', 'setupChart');
|
||||
_.bindAll(this, 'render', 'updateGraphV2', 'setupChart');
|
||||
this.collection.on('update', function(d) {
|
||||
console.log('GraphView Collection update trigger!!');
|
||||
this.updateGraphV2();
|
||||
}, this);
|
||||
|
||||
// This.setupChart();
|
||||
}, events: {
|
||||
'change select#displaymode': 'changeMode'
|
||||
}, setupChart: function() {
|
||||
@ -295,7 +245,6 @@
|
||||
this.dataSet.color = '#b0de09';
|
||||
|
||||
this.chart.dataSets = [this.dataSet];
|
||||
// This.chart.write('chartdiv');
|
||||
},
|
||||
|
||||
doChartV2: function(chartData) {
|
||||
@ -309,7 +258,9 @@
|
||||
],
|
||||
|
||||
legend: {
|
||||
useGraphSettings: true
|
||||
useGraphSettings: true,
|
||||
color: '#fff',
|
||||
switchColor: '#556374'
|
||||
},
|
||||
color: '#ffffff',
|
||||
dataProvider: chartData,
|
||||
@ -321,14 +272,16 @@
|
||||
axisColor: '#FFC802',
|
||||
axisThickness: 2,
|
||||
axisAlpha: 1,
|
||||
position: 'left'
|
||||
position: 'left',
|
||||
gridColor: '#556374'
|
||||
},
|
||||
{
|
||||
id: 'co2',
|
||||
axisColor: 'rgba(0,191,255,1)',
|
||||
axisThickness: 2,
|
||||
axisAlpha: 1,
|
||||
position: 'right'
|
||||
position: 'right',
|
||||
gridColor: '#556374'
|
||||
},
|
||||
{
|
||||
id: 'temp',
|
||||
@ -337,7 +290,8 @@
|
||||
gridAlpha: 0,
|
||||
offset: 50,
|
||||
axisAlpha: 1,
|
||||
position: 'left'
|
||||
position: 'left',
|
||||
gridColor: '#556374'
|
||||
},
|
||||
{
|
||||
id: 'humid',
|
||||
@ -345,7 +299,8 @@
|
||||
axisThickness: 2,
|
||||
axisAlpha: 1,
|
||||
offset: 50,
|
||||
position: 'right'
|
||||
position: 'right',
|
||||
gridColor: '#556374'
|
||||
},
|
||||
{
|
||||
id: 'noise',
|
||||
@ -354,7 +309,8 @@
|
||||
gridAlpha: 0,
|
||||
offset: 100,
|
||||
axisAlpha: 1,
|
||||
position: 'left'
|
||||
position: 'left',
|
||||
gridColor: '#556374'
|
||||
}
|
||||
],
|
||||
graphs: [
|
||||
@ -396,14 +352,17 @@
|
||||
],
|
||||
chartScrollbar: {},
|
||||
chartCursor: {
|
||||
cursorPosition: 'mouse'
|
||||
cursorPosition: 'mouse',
|
||||
cursorColor: '#14bfff',
|
||||
color: '#000'
|
||||
},
|
||||
categoryField: 'date',
|
||||
categoryAxis: {
|
||||
minPeriod: 'mm',
|
||||
parseDates: true,
|
||||
axisColor: '#ff0000',
|
||||
minorGridEnabled: true
|
||||
axisColor: 'rgba(255,255,255,0.8)',
|
||||
minorGridEnabled: true,
|
||||
gridColor: '#556374'
|
||||
},
|
||||
export: {
|
||||
enabled: true, position: 'bottom-right'
|
||||
@ -426,63 +385,7 @@
|
||||
temp: i.get('temp')
|
||||
});
|
||||
});
|
||||
// Console.log(chartData);
|
||||
self.doChartV2(chartData);
|
||||
}, updateGraph: function() {
|
||||
var self = this;
|
||||
let getMode = this.modes[this.mode];
|
||||
|
||||
var chartData = [];
|
||||
|
||||
var temporal = {high: 0, low: 0};
|
||||
var HL = {high: 0, low: 0};
|
||||
|
||||
var mode = parseInt(this.mode);
|
||||
console.log('mode:', mode, this.mode);
|
||||
|
||||
_(this.collection.models).each(function(i) {
|
||||
var dt = i.get('dt');
|
||||
var obj;
|
||||
var value, valueB;
|
||||
if (mode < 6) {
|
||||
value = i.get(getMode);
|
||||
} else {
|
||||
if (mode === 6) {
|
||||
value = i.get(this.modes[1]);
|
||||
valueB = i.get(this.modes[3]);
|
||||
} else {
|
||||
|
||||
value = i.get(this.modes[2]);
|
||||
valueB = i.get(this.modes[4]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (temporal.low === 0 || dt < temporal.low) {
|
||||
temporal.low = dt;
|
||||
}
|
||||
if (temporal.high === 0 || dt > temporal.high) {
|
||||
temporal.high = dt;
|
||||
}
|
||||
|
||||
if (HL.low === 0 || value < HL.low) {
|
||||
HL.low = value;
|
||||
}
|
||||
if (HL.high === 0 || value > HL.high) {
|
||||
HL.high = value;
|
||||
}
|
||||
|
||||
obj = {date: dt, value: value};
|
||||
|
||||
if (mode => 6) {
|
||||
obj.valueB = valueB;
|
||||
}
|
||||
chartData.push(obj);
|
||||
|
||||
}, this);
|
||||
|
||||
self.doChartV2(mode, chartData);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
83
mdot/mdot_server/mdot_server/filler.js
Normal file
83
mdot/mdot_server/mdot_server/filler.js
Normal 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);
|
||||
});
|
||||
}
|
||||
)();
|
@ -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 {
|
||||
|
@ -7,6 +7,7 @@
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {
|
||||
"atob": "^2.0.3",
|
||||
"body-parser": "^1.15.1",
|
||||
"btoa": "^1.1.2",
|
||||
"cookie-parser": "*",
|
||||
@ -63,7 +64,7 @@
|
||||
"mqtt-ws": "^0.2.0",
|
||||
"node-cron": "^1.1.1",
|
||||
"require-dir": "^0.3.0",
|
||||
"should": "^10.0.0",
|
||||
"should": "^11.0.0",
|
||||
"string": "^3.3.1",
|
||||
"sugar": "^2.0.1",
|
||||
"sugar-date": "^2.0.0",
|
||||
|
Loading…
Reference in New Issue
Block a user