Merge pull request #128 from nightscout/wip/mbg

Added searching for MBG data from mongo query.
This commit is contained in:
Ben West
2014-09-12 17:49:04 -07:00
2 changed files with 25 additions and 8 deletions
+24 -7
View File
@@ -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;
+1 -1
View File
@@ -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);