”2016-09-12”

This commit is contained in:
Martin Donnelly 2016-09-12 16:45:05 +01:00
parent b1212ea9bd
commit d635c4179e
5 changed files with 80 additions and 16 deletions

View File

@ -243,7 +243,7 @@
this.model.set('device', newDevice); this.model.set('device', newDevice);
if (this.socketHandler) { if (this.socketHandler) {
this.socketHandler.listenFor(newDevice); this.socketHandler.listenFor(newDevice);
} }
}, updateDevice: function() { }, updateDevice: function() {
var fetchObj = {beforeSend: sendAuthentication}; var fetchObj = {beforeSend: sendAuthentication};
@ -295,6 +295,7 @@
}, this); }, this);
}, events: { }, events: {
'change select#displaymode': 'changeMode' 'change select#displaymode': 'changeMode'
}, setupChart: function() { }, setupChart: function() {
@ -408,7 +409,15 @@
title: 'Humidity', title: 'Humidity',
valueField: 'humid', valueField: 'humid',
fillAlphas: 0 fillAlphas: 0
} },
{
valueAxis: 'co2',
lineColor: 'rgba(255,0,255,1)',
title: 'sub100',
valueField: 'sub100',
fillAlphas: 0
}
], ],
chartScrollbar: { chartScrollbar: {
graph: 'occ',oppositeAxis: false, graph: 'occ',oppositeAxis: false,
@ -451,17 +460,36 @@
console.time('updateGraphV2'); console.time('updateGraphV2');
var self = this; var self = this;
var chartData = []; var chartData = [];
var filter = [];
console.time('chartData'); console.time('chartData');
var step = 0;
const max = 20;
_(this.collection.models).each(function(i) { _(this.collection.models).each(function(i) {
chartData.push({ const co2 = i.get('co2');
date: i.get('dt'), let chunk = {
co2: i.get('co2'), date: i.get('dt'),
humid: i.get('humid'), co2: co2,
lux: i.get('lux'), humid: i.get('humid'),
noise: i.get('noise'), lux: i.get('lux'),
temp: i.get('temp'), noise: i.get('noise'),
occupancy: i.get('occupancy') temp: i.get('temp'),
}); occupancy: i.get('occupancy')
};
if (filter.length >= max) {
filter.shift();
}
filter.push(co2);
//if (step % 100 === 0) {
if (filter.length >= max) {
let sub100 = filter.reduce((prev, cur) => prev + cur);
chunk.sub100 = sub100 / max;
}
chartData.push(chunk);
step++;
}); });
console.timeEnd('chartData'); console.timeEnd('chartData');
@ -470,6 +498,10 @@
}, },
setSocket: function(newSocket) { setSocket: function(newSocket) {
this.socketHandler = newSocket; this.socketHandler = newSocket;
this.socketHandler.on('update', function() {
console.log('Model updated:', this.get('data'));
});
} }
}); });

View File

@ -26,7 +26,8 @@ var SOCKETMANAGER = (function() {
this.on('message', function(o) { this.on('message', function(o) {
if (this.listening) if (this.listening)
{ {
console.log('Message', o); //console.log('Message', o);
this.checkItem(o);
} }
}); });
@ -44,8 +45,22 @@ var SOCKETMANAGER = (function() {
listenFor: function(id) { listenFor: function(id) {
console.log('index of', this.deviceId.indexOf(id)); console.log('index of', this.deviceId.indexOf(id));
this.listeningID = id; this.listeningID = this.deviceId.indexOf(id);
},
checkItem : function(item) {
//console.log('Checking Item:', item);
if (item.hasOwnProperty('tick')) {
//console.log('Reject heartbeat');
} else {
console.log('Wanted deviceid', this.listeningID, item.data.deviceid);
//console.log('Data packet!!!');
if (item.data.deviceid === this.listeningID) {
console.log(item.data);
this.set({data:item.data});
}
} }
}
}); });
return SocketManager; return SocketManager;

View File

@ -31,7 +31,7 @@ var WEBSOCKET = function(model) {
model.trigger('message',d); model.trigger('message',d);
switch (d.id) { switch (d.id) {
default: default:
console.log('Default:',d); // console.log('Default:',d);
break; break;
} }
}; };

View File

@ -0,0 +1,15 @@
/**
*
* User: Martin Donnelly
* Date: 2016-09-12
* Time: 16:19
*
*/
var WIDGET = (function() {
'use strict';
var Widget = Backbone.View.extend({
});
}());

View File

@ -19,13 +19,15 @@ var cn = {
// ElephantSql settings // ElephantSql settings
/*var cn = { /*
var cn = {
host: 'jumbo.db.elephantsql.com', host: 'jumbo.db.elephantsql.com',
port: 5432, port: 5432,
database: 'amlrxqev', database: 'amlrxqev',
user: 'amlrxqev', user: 'amlrxqev',
password: 'K11cvCplk0--oNafsYj4ISN-rVQmVS3y' password: 'K11cvCplk0--oNafsYj4ISN-rVQmVS3y'
};*/ };
*/
exports.dbConnection = pgp(cn); exports.dbConnection = pgp(cn);