Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added searching for MBG data from mongo query. #128

Merged
merged 2 commits into from
Sep 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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);
Expand Down