Skip to content

Commit

Permalink
Merge pull request #128 from nightscout/wip/mbg
Browse files Browse the repository at this point in the history
Added searching for MBG data from mongo query.
  • Loading branch information
bewest committed Sep 13, 2014
2 parents 1008149 + 6555e75 commit b82a06e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var dir2Char = {

var cgmData = [],
treatmentData = [],
mbgData = [],
patientData = [];

function start ( ) {
Expand Down Expand Up @@ -104,17 +105,26 @@ function update() {

cgmData = [];
treatmentData = [];
mbgData = [];
var earliest_data = now - TWO_DAYS;
var q = { find: {"date": {"$gte": earliest_data}} };
entries.list(q, function (err, results) {
results.forEach(function(element, index, array) {
if (element) {
var obj = {};
obj.y = element.sgv;
obj.x = element.date;
obj.d = element.dateString;
obj.direction = directionToChar(element.direction);
cgmData.push(obj);
if (element.mbg) {
var obj = {};
obj.y = element.mbg;
obj.x = element.date;
obj.d = element.dateString;
mbgData.push(obj);
} else if (element.sgv) {
var obj = {};
obj.y = element.sgv;
obj.x = element.date;
obj.d = element.dateString;
obj.direction = directionToChar(element.direction);
cgmData.push(obj);
}
}
});
treatments.list(function (err, results) {
Expand Down Expand Up @@ -143,11 +153,11 @@ function emitAlarm(alarmType) {
function loadData() {

console.log('running loadData');
var mbg = [];

var actual = [],
actualCurrent,
treatment = [],
mbg = [],
errorCode;

if (cgmData) {
Expand All @@ -172,6 +182,13 @@ function loadData() {
});
}

if (mbgData) {
mbg = mbgData.slice();
mbg.sort(function(a, b) {
return a.x - b.x;
});
}

if (actualCurrent && actualCurrent < 39) errorCode = actualCurrent;

var actualLength = actual.length - 1;
Expand Down
2 changes: 1 addition & 1 deletion static/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
} else {
// if the brush comes back into the current time range then it should reset to the current time and sg
var nowData = data.filter(function(d) {
return d.color != 'none';
return d.color != 'none' && d.color != 'red';
});
nowData = [nowData[nowData.length - 2], nowData[nowData.length - 1]];
var prediction = predictAR(nowData);
Expand Down

0 comments on commit b82a06e

Please sign in to comment.