initial port from iob-cob branch

This commit is contained in:
Jason Calabrese
2015-01-29 21:42:46 -08:00
parent 0eef982f78
commit e7440425ac
2 changed files with 63 additions and 10 deletions
+23 -3
View File
@@ -28,6 +28,7 @@ var dir2Char = {
var cgmData = [],
treatmentData = [],
mbgData = [],
calData = [],
patientData = [];
function start ( ) {
@@ -164,7 +165,18 @@ function update() {
obj.d = element.dateString;
obj.device = element.device;
obj.direction = directionToChar(element.direction);
obj.filtered = element.filtered;
obj.unfiltered = element.unfiltered;
obj.rssi = element.rssi;
cgmData.push(obj);
} else if (element.slope) {
var obj = {};
obj.x = element.date;
obj.d = element.dateString;
obj.scale = element.scale;
obj.intercept = element.intercept;
obj.slope = element.slope;
calData.push(obj);
}
}
});
@@ -191,6 +203,7 @@ function loadData() {
actualCurrent,
treatment = [],
mbg = [],
cal = [],
errorCode;
if (cgmData) {
@@ -204,7 +217,7 @@ function loadData() {
// sgv less than or equal to 10 means error code
// or warm up period code, so ignore
actual = actual.filter(function (a) {
return a.y > 10;
return (a.y > 10 || a.unfiltered > 0);
})
}
@@ -222,6 +235,13 @@ function loadData() {
});
}
if (calData) {
cal = calData.slice(calData.length-200, calData.length);
cal.sort(function(a, b) {
return a.x - b.x;
});
}
if (actualCurrent && actualCurrent < 39) errorCode = actualCurrent;
var actualLength = actual.length - 1;
@@ -255,8 +275,8 @@ function loadData() {
//TODO: need to consider when data being sent has less than the 2 day minimum
// consolidate and send the data to the client
var shouldEmit = is_different(actual, predicted, mbg, treatment, errorCode);
patientData = [actual, predicted, mbg, treatment, errorCode];
var shouldEmit = is_different(actual, predicted, mbg, treatment, errorCode, cal);
patientData = [actual, predicted, mbg, treatment, errorCode, cal];
console.log('patientData', patientData.length);
if (shouldEmit) {
emitData( );
+40 -7
View File
@@ -30,6 +30,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
, prevSGV
, errorCode
, treatments
, cal
, padding = { top: 20, right: 10, bottom: 30, left: 10 }
, opacity = {current: 1, DAY: 1, NIGHT: 0.5}
, now = Date.now()
@@ -95,7 +96,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
]);
// lixgbg: Convert mg/dL BG value to metric mmol
// lixgbg: Convert mg/dL BG value to metric mmol
function scaleBg(bg) {
if (browserSettings.units == 'mmol') {
return (Math.round((bg / 18) * 10) / 10).toFixed(1);
@@ -103,6 +104,19 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
return bg;
}
}
function rawIsigToRawBg(unfiltered, scale, intercept, slope, filtered, sgv) {
if (slope == 0 || unfiltered == 0 || scale ==0 || slope == null || unfiltered == null || scale == null) return 0;
else if (filtered == 0 || filtered == null || sgv < 30 || sgv == null) {
console.info("Skipping ratio adjustment for SGV " + sgv);
return scale*(unfiltered-intercept)/slope;
}
else {
var ratio = scale*(filtered-intercept)/slope / sgv;
return scale*(unfiltered-intercept)/slope / ratio;
}
}
// initial setup of chart when data is first made available
function initializeCharts() {
@@ -417,6 +431,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
var dotRadius = function(type) {
var radius = prevChartWidth > WIDTH_BIG_DOTS ? 4 : (prevChartWidth < WIDTH_SMALL_DOTS ? 2 : 3);
if (type == 'mbg') radius *= 2;
else if (type == 'rawbg') radius = Math.min(2, radius - 1);
return radius;
};
@@ -1309,9 +1324,32 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
latestSGV = d[0][d[0].length - 1];
prevSGV = d[0][d[0].length - 2];
}
data = d[0].map(function (obj) {
treatments = d[3];
treatments.forEach(function (d) {
d.created_at = new Date(d.created_at);
});
cal = d[5][d[5].length-1];
var temp1 = [ ];
if (cal) {
temp1 = d[0].map(function (obj) {
var rawBg = rawIsigToRawBg(obj.unfiltered
, cal.scale || [ ]
, cal.intercept
, cal.slope || [ ]
, obj.filtered
, obj.y);
return { date: new Date(obj.x-2*1000), y: rawBg, sgv: scaleBg(rawBg), color: 'white', type: 'rawbg'}
});
}
var temp2 = d[0].map(function (obj) {
return { date: new Date(obj.x), y: obj.y, sgv: scaleBg(obj.y), direction: obj.direction, color: sgvToColor(obj.y), type: 'sgv'}
});
data = [];
data = data.concat(temp1, temp2);
// TODO: This is a kludge to advance the time as data becomes stale by making old predictor clear (using color = 'none')
// This shouldn't have to be sent and can be fixed by using xScale.domain([x0,x1]) function with
// 2 days before now as x0 and 30 minutes from now for x1 for context plot, but this will be
@@ -1327,11 +1365,6 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
d.color = 'transparent';
});
treatments = d[3];
treatments.forEach(function (d) {
d.created_at = new Date(d.created_at);
});
if (!isInitialData) {
isInitialData = true;
initializeCharts();