From 07f5435a80218fe37ba6cc1b7f4b1e1da0c526ab Mon Sep 17 00:00:00 2001 From: rnpenguin Date: Mon, 1 Sep 2014 18:08:18 -0700 Subject: [PATCH 1/2] Added searching for MBG data from mongo query. --- lib/websocket.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/websocket.js b/lib/websocket.js index d034bd3ec47..97c132ee0a1 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -27,6 +27,7 @@ var dir2Char = { var cgmData = [], treatmentData = [], + mbgData = [], patientData = []; function start ( ) { @@ -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) { @@ -143,11 +153,11 @@ function emitAlarm(alarmType) { function loadData() { console.log('running loadData'); - var mbg = []; var actual = [], actualCurrent, treatment = [], + mbg = [], errorCode; if (cgmData) { @@ -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; From 6555e75126c6486b5efe5a2da4a818f5efcac3d6 Mon Sep 17 00:00:00 2001 From: Ben West Date: Wed, 3 Sep 2014 01:27:19 -0700 Subject: [PATCH 2/2] hack: only consider 'grey' sgv records Quick hack to force predictor to only use actual sgv records. --- static/js/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/client.js b/static/js/client.js index 612d57354eb..a0b7b41793d 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -259,7 +259,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);