convert x and date fields to mills and get rid of some conversion

This commit is contained in:
Jason Calabrese
2015-07-07 18:35:35 -07:00
parent 61d94a0190
commit b3f41dd137
16 changed files with 114 additions and 124 deletions
+10 -13
View File
@@ -7,7 +7,7 @@ var ObjectID = require('mongodb').ObjectID;
function uniq(a) {
var seen = {};
return a.filter(function (item) {
return seen.hasOwnProperty(item.x) ? false : (seen[item.x] = true);
return seen.hasOwnProperty(item.mills) ? false : (seen[item.mills] = true);
});
}
@@ -26,7 +26,6 @@ function init(env, ctx) {
var ONE_DAY = 86400000
, TWO_DAYS = 172800000;
data.clone = function clone() {
return _.cloneDeep(data, function (value) {
//special handling of mongo ObjectID's
@@ -47,7 +46,7 @@ function init(env, ctx) {
function sort(values) {
values.sort(function sorter(a, b) {
return a.x - b.x;
return a.mills - b.mills;
});
}
@@ -62,11 +61,11 @@ function init(env, ctx) {
if (element) {
if (element.mbg) {
mbgs.push({
y: element.mbg, x: element.date, device: element.device
y: element.mbg, mills: element.date, device: element.device
});
} else if (element.sgv) {
sgvs.push({
y: element.sgv, x: element.date, device: element.device, direction: element.direction, filtered: element.filtered, unfiltered: element.unfiltered, noise: element.noise, rssi: element.rssi
y: element.sgv, mills: element.date, device: element.device, direction: element.direction, filtered: element.filtered, unfiltered: element.unfiltered, noise: element.noise, rssi: element.rssi
});
}
}
@@ -89,7 +88,7 @@ function init(env, ctx) {
results.forEach(function (element) {
if (element) {
cals.push({
x: element.date, scale: element.scale, intercept: element.intercept, slope: element.slope
mills: element.date, scale: element.scale, intercept: element.intercept, slope: element.slope
});
}
});
@@ -102,15 +101,13 @@ function init(env, ctx) {
ctx.treatments.list(tq, function (err, results) {
if (!err && results) {
var treatments = results.map(function (treatment) {
treatment.created_at = new Date(treatment.created_at).getTime();
//TODO: #CleanUpDataModel, some code expects x everywhere
treatment.x = treatment.created_at;
treatment.mills = new Date(treatment.created_at).getTime();
return treatment;
});
//FIXME: sort in mongo
treatments.sort(function (a, b) {
return a.created_at - b.created_at;
return a.mills - b.mills;
});
data.treatments = treatments;
@@ -162,12 +159,12 @@ function init(env, ctx) {
var seen = {};
var l = oldArray.length;
for (var i = 0; i < l; i++) {
seen[oldArray[i].x] = true;
seen[oldArray[i].mills] = true;
}
var result = [];
l = newArray.length;
for (var j = 0; j < l; j++) {
if (!seen.hasOwnProperty(newArray[j].x)) {
if (!seen.hasOwnProperty(newArray[j].mills)) {
result.push(newArray[j]);
}
}
@@ -176,7 +173,7 @@ function init(env, ctx) {
function sort(values) {
values.sort(function sorter(a, b) {
return a.x - b.x;
return a.mills - b.mills;
});
}
+8 -8
View File
@@ -86,7 +86,7 @@ function init() {
//ignore when raw is 0, and use BG_MIN if raw is lower
var rawY = rawResult === 0 ? 0 : Math.max(rawResult, BG_MIN);
return { x: sgv.x, y: rawY };
return { mills: sgv.mills, y: rawY };
});
}
}
@@ -112,8 +112,8 @@ function init() {
if (current >= BG_MIN && sgvs[lastIndex - 1].y >= BG_MIN) {
// predict using AR model
var lastValidReadingTime = sgvs[lastIndex].x;
var elapsedMins = (sgvs[lastIndex].x - sgvs[lastIndex - 1].x) / ONE_MINUTE;
var lastValidReadingTime = sgvs[lastIndex].mills;
var elapsedMins = (sgvs[lastIndex].mills - sgvs[lastIndex - 1].mills) / ONE_MINUTE;
var y = Math.log(current / BG_REF);
if (elapsedMins < 5.1) {
y = [Math.log(prev / BG_REF), y];
@@ -122,12 +122,12 @@ function init() {
}
var n = Math.ceil(12 * (1 / 2 + (Date.now() - lastValidReadingTime) / ONE_HOUR));
var AR = [-0.723, 1.716];
var dt = sgvs[lastIndex].x;
var dt = sgvs[lastIndex].mills;
for (var i = 0; i <= n; i++) {
y = [y[1], AR[0] * y[0] + AR[1] * y[1]];
dt = dt + FIVE_MINUTES;
result.predicted[i] = {
x: dt,
mills: dt,
y: Math.max(BG_MIN, Math.min(BG_MAX, Math.round(BG_REF * Math.exp(y[1]))))
};
}
@@ -162,7 +162,7 @@ function init() {
}
var CONE = [0.020, 0.041, 0.061, 0.081, 0.099, 0.116, 0.132, 0.146, 0.159, 0.171, 0.182, 0.192, 0.201];
var elapsedMins = (sgvs[sgvs.length-1].x - sgvs[sgvs.length-2].x) / ONE_MINUTE;
var elapsedMins = (sgvs[sgvs.length-1].mills - sgvs[sgvs.length-2].mills) / ONE_MINUTE;
// construct a '5m ago' sgv offset from current sgv by the average change over the lookback interval
var delta = sgvs[sgvs.length-1].y - sgvs[sgvs.length-2].y;
@@ -182,13 +182,13 @@ function init() {
forecastTime = forecastTime + FIVE_MINUTES;
// Add 2000 ms so not same point as SG
conePoints[i * 2] = {
date: new Date(forecastTime + 2000)
mills: forecastTime + 2000
, sgv: Math.max(BG_MIN, Math.min(BG_MAX, sbx.scaleBg(BG_REF * Math.exp((y[1] - 2 * CONE[i])))))
, color: predictedColor
};
// Add 4000 ms so not same point as SG
conePoints[i * 2 + 1] = {
date: new Date(forecastTime + 4000)
mills: forecastTime + 4000
, sgv: Math.max(BG_MIN, Math.min(BG_MAX, sbx.scaleBg(BG_REF * Math.exp((y[1] + 2 * CONE[i])))))
, color: predictedColor
};
+1 -1
View File
@@ -15,7 +15,7 @@ function init() {
var now = Date.now();
var lastSGV = sbx.lastSGVEntry();
if (lastSGV && now - lastSGV.x < TIME_10_MINS_MS && lastSGV.y < 39) {
if (lastSGV && now - lastSGV.mills < TIME_10_MINS_MS && lastSGV.y < 39) {
var errorDisplay;
var pushoverSound = null;
+1 -1
View File
@@ -22,7 +22,7 @@ function init() {
var eventName = '';
if (lastSGV && lastSGVEntry && lastSGVEntry.y > 39 && Date.now() - lastSGVEntry.x < TIME_10_MINS_MS) {
if (lastSGV && lastSGVEntry && lastSGVEntry.y > 39 && Date.now() - lastSGVEntry.mills < TIME_10_MINS_MS) {
if (lastSGV > sbx.scaleBg(sbx.thresholds.bg_high)) {
trigger = true;
level = 2;
+2 -2
View File
@@ -21,11 +21,11 @@ function init() {
var lastTreatment = sbx.lastEntry(sbx.data.treatments);
//TODO: figure out why date is x here #CleanUpDataModel
var lastMBGTime = lastMBG ? lastMBG.x : 0;
var lastMBGTime = lastMBG ? lastMBG.mills : 0;
var mbgAgo = (lastMBGTime && lastMBGTime <= now) ? now - lastMBGTime : -1;
var mbgCurrent = mbgAgo !== -1 && mbgAgo < TIME_10_MINS_MS;
var lastTreatmentTime = lastTreatment ? lastTreatment.x : 0;
var lastTreatmentTime = lastTreatment ? lastTreatment.mills : 0;
var treatmentAgo = (lastTreatmentTime && lastTreatmentTime <= now) ? now - lastTreatmentTime : -1;
var treatmentCurrent = treatmentAgo !== -1 && treatmentAgo < TIME_10_MINS_MS;
+1 -2
View File
@@ -137,8 +137,7 @@ function init ( ) {
};
sbx.entryMills = function entryMills(entry) {
//FIXME: field mismatch between server and client :(
return (entry && entry.x) || (entry && entry.date && (new Date(entry.date)).getTime()) || 0;
return entry && entry.mills;
};
sbx.lastScaledSGV = function lastScaledSVG ( ) {
+3 -1
View File
@@ -294,7 +294,9 @@ body {
margin: 10px auto;
}
div.tooltip {
.tooltip {
top: 0;
left: 0;
color: #444;
position: absolute;
text-align: left;
+28 -31
View File
@@ -63,7 +63,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
, prevChartHeight = 0
, focusHeight
, contextHeight
, dateFn = function (d) { return new Date(d.date) }
, dateFn = function (d) { return new Date(d.mills) }
, documentHidden = false
, brush
, brushTimer
@@ -109,7 +109,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
var bg_title = '';
var time = latestSGV ? new Date(latestSGV.x).getTime() : (prevSGV ? new Date(prevSGV.x).getTime() : -1)
var time = latestSGV ? latestSGV.mills : (prevSGV ? prevSGV.mills : -1)
, ago = timeAgo(time, browserSettings);
if (browserSettings.customTitle) {
@@ -152,13 +152,13 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
// define the parts of the axis that aren't dependent on width or height
xScale = d3.time.scale()
.domain(d3.extent(data, function (d) { return d.date; }));
.domain(d3.extent(data, function (d) { return d.mills; }));
yScale = d3.scale.log()
.domain([scaleBg(30), scaleBg(510)]);
xScale2 = d3.time.scale()
.domain(d3.extent(data, function (d) { return d.date; }));
.domain(d3.extent(data, function (d) { return d.mills; }));
yScale2 = d3.scale.log()
.domain([scaleBg(36), scaleBg(420)]);
@@ -210,8 +210,8 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
// get the desired opacity for context chart based on the brush extent
function highlightBrushPoints(data) {
if (data.date.getTime() >= brush.extent()[0].getTime() && data.date.getTime() <= brush.extent()[1].getTime()) {
return futureOpacity(data.date.getTime() - latestSGV.x);
if (data.mills >= brush.extent()[0].getTime() && data.mills <= brush.extent()[1].getTime()) {
return futureOpacity(data.mills - latestSGV.mills);
} else {
return 0.5;
}
@@ -223,11 +223,11 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
// 2 days before now as x0 and 30 minutes from now for x1 for context plot, but this will be
// required to happen when 'now' event is sent from websocket.js every minute. When fixed,
// remove this code and all references to `type: 'server-forecast'`
var lastTime = data.length > 0 ? data[data.length - 1].date.getTime() : Date.now();
var lastTime = data.length > 0 ? data[data.length - 1].mills : Date.now();
var n = Math.ceil(12 * (1 / 2 + (now - lastTime) / SIXTY_MINS_IN_MS)) + 1;
for (var i = 1; i <= n; i++) {
data.push({
date: new Date(lastTime + (i * FIVE_MINS_IN_MS)), y: 100, sgv: scaleBg(100), color: 'none', type: 'server-forecast'
mills: lastTime + (i * FIVE_MINS_IN_MS), y: 100, sgv: scaleBg(100), color: 'none', type: 'server-forecast'
});
}
}
@@ -340,11 +340,9 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
;
function updateCurrentSGV(entry) {
var value, time, ago, isCurrent;
value = entry.y;
time = new Date(entry.x).getTime();
ago = timeAgo(time, browserSettings);
isCurrent = ago.status === 'current';
var value = entry.y
, ago = timeAgo(entry.mills, browserSettings)
, isCurrent = ago.status === 'current';
if (value === 9) {
currentBG.text('');
@@ -403,15 +401,15 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
// filter data for -12 and +5 minutes from reference time for retrospective focus data prediction
var lookbackTime = 3 * FIVE_MINS_IN_MS + 2 * ONE_MIN_IN_MS;
nowData = nowData.filter(function(d) {
return d.date.getTime() >= brushExtent[1].getTime() - TWENTY_FIVE_MINS_IN_MS - lookbackTime &&
d.date.getTime() <= brushExtent[1].getTime() - TWENTY_FIVE_MINS_IN_MS;
return d.mills >= brushExtent[1].getTime() - TWENTY_FIVE_MINS_IN_MS - lookbackTime &&
d.mills <= brushExtent[1].getTime() - TWENTY_FIVE_MINS_IN_MS;
});
// sometimes nowData contains duplicates. uniq it.
var lastDate = new Date('1/1/1970');
nowData = nowData.filter(function(d) {
var ok = (lastDate.getTime() + ONE_MIN_IN_MS) < d.date.getTime();
lastDate = d.date;
var ok = lastDate + ONE_MIN_IN_MS < d.mills;
lastDate = d.mills;
return ok;
});
@@ -474,7 +472,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
function prepareFocusCircles(sel) {
var badData = [];
sel.attr('cx', function (d) { return xScale(d.date); })
sel.attr('cx', function (d) { return xScale(d.mills); })
.attr('cy', function (d) {
if (isNaN(d.sgv)) {
badData.push(d);
@@ -484,7 +482,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
}
})
.attr('fill', function (d) { return d.color; })
.attr('opacity', function (d) { return futureOpacity(d.date.getTime() - latestSGV.x); })
.attr('opacity', function (d) { return futureOpacity(d.mills - latestSGV.mills); })
.attr('stroke-width', function (d) { return d.type === 'mbg' ? 2 : 0; })
.attr('stroke', function (d) {
return (isDexcom(d.device) ? 'white' : '#0099ff');
@@ -521,7 +519,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
(d.type === 'mbg' ? '<br/><strong>Device: </strong>' + d.device : '') +
(rawbgValue ? '<br/><strong>Raw BG:</strong> ' + rawbgValue : '') +
(noiseLabel ? '<br/><strong>Noise:</strong> ' + noiseLabel : '') +
'<br/><strong>Time:</strong> ' + formatTime(d.date))
'<br/><strong>Time:</strong> ' + formatTime(d.mills))
.style('left', (d3.event.pageX) + 'px')
.style('top', (d3.event.pageY + 15) + 'px');
}
@@ -945,7 +943,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
function prepareContextCircles(sel) {
var badData = [];
sel.attr('cx', function (d) { return xScale2(d.date); })
sel.attr('cx', function (d) { return xScale2(d.mills); })
.attr('cy', function (d) {
if (isNaN(d.sgv)) {
badData.push(d);
@@ -1085,10 +1083,10 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
});
var beforeTreatment = _.findLast(withBGs, function (d) {
return d.date.getTime() <= time;
return d.mills <= time;
});
var afterTreatment = _.find(withBGs, function (d) {
return d.date.getTime() >= time;
return d.mills >= time;
});
var calcedBG = 0;
@@ -1290,7 +1288,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
function updateTimeAgo() {
var lastEntry = $('#lastEntry')
, time = latestSGV ? new Date(latestSGV.x).getTime() : -1
, time = latestSGV ? latestSGV.mills : -1
, ago = timeAgo(time, browserSettings)
, retroMode = inRetroMode();
@@ -1443,10 +1441,10 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
function nsArrayDiff(oldArray, newArray) {
var seen = {};
var l = oldArray.length;
for (var i = 0; i < l; i++) { seen[oldArray[i].x] = true }
for (var i = 0; i < l; i++) { seen[oldArray[i].mills] = true }
var result = [];
l = newArray.length;
for (var j = 0; j < l; j++) { if (!seen.hasOwnProperty(newArray[j].x)) { result.push(newArray[j]); console.log('delta data found'); } }
for (var j = 0; j < l; j++) { if (!seen.hasOwnProperty(newArray[j].mills)) { result.push(newArray[j]); console.log('delta data found'); } }
return result;
}
@@ -1463,7 +1461,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
// If this is delta, calculate the difference, merge and sort
var diff = nsArrayDiff(cachedDataArray,receivedDataArray);
return cachedDataArray.concat(diff).sort(function(a, b) {
return a.x - b.x;
return a.mills - b.mills;
});
}
@@ -1505,22 +1503,21 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
temp1 = SGVdata.map(function (entry) {
var rawbgValue = rawbg.showRawBGs(entry.y, entry.noise, cal, sbx) ? rawbg.calc(entry, cal, sbx) : 0;
if (rawbgValue > 0) {
var rawX = entry.x - 2000;
return { date: new Date(rawX), x: rawX, y: rawbgValue, sgv: scaleBg(rawbgValue), color: 'white', type: 'rawbg' };
return { mills: entry.mills - 2000, y: rawbgValue, sgv: scaleBg(rawbgValue), color: 'white', type: 'rawbg' };
} else {
return null;
}
}).filter(function(entry) { return entry !== null; });
}
var temp2 = SGVdata.map(function (obj) {
return { date: new Date(obj.x), x: obj.x, y: obj.y, sgv: scaleBg(obj.y), direction: obj.direction, color: sgvToColor(obj.y), type: 'sgv', noise: obj.noise, filtered: obj.filtered, unfiltered: obj.unfiltered};
return { mills: obj.mills, y: obj.y, sgv: scaleBg(obj.y), direction: obj.direction, color: sgvToColor(obj.y), type: 'sgv', noise: obj.noise, filtered: obj.filtered, unfiltered: obj.unfiltered};
});
data = [];
data = data.concat(temp1, temp2);
addPlaceholderPoints();
data = data.concat(MBGdata.map(function (obj) { return { date: new Date(obj.x), x: obj.x, y: obj.y, sgv: scaleBg(obj.y), color: 'red', type: 'mbg', device: obj.device } }));
data = data.concat(MBGdata.map(function (obj) { return { mills: obj.mills, y: obj.y, sgv: scaleBg(obj.y), color: 'red', type: 'mbg', device: obj.device } }));
data.forEach(function (d) {
if (d.y < 39) { d.color = 'transparent'; }
+14 -14
View File
@@ -35,7 +35,7 @@ describe('ar2', function ( ) {
it('Not trigger an alarm when in range', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 100, x: before}, {y: 105, x: now}];
ctx.data.sgvs = [{y: 100, mills: before}, {y: 105, mills: now}];
var sbx = prepareSandbox();
ar2.checkNotifications(sbx);
@@ -46,7 +46,7 @@ describe('ar2', function ( ) {
it('should trigger a warning when going above target', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 150, x: before}, {y: 170, x: now}];
ctx.data.sgvs = [{y: 150, mills: before}, {y: 170, mills: now}];
var sbx = prepareSandbox();
sbx.offerProperty('iob', function setFakeIOB() {
@@ -66,7 +66,7 @@ describe('ar2', function ( ) {
it('should trigger a urgent alarm when going high fast', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 140, x: before}, {y: 200, x: now}];
ctx.data.sgvs = [{y: 140, mills: before}, {y: 200, mills: now}];
var sbx = prepareSandbox();
ar2.checkNotifications(sbx);
@@ -79,7 +79,7 @@ describe('ar2', function ( ) {
it('should trigger a warning when below target', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 90, x: before}, {y: 80, x: now}];
ctx.data.sgvs = [{y: 90, mills: before}, {y: 80, mills: now}];
var sbx = prepareSandbox();
ar2.checkNotifications(sbx);
@@ -92,7 +92,7 @@ describe('ar2', function ( ) {
it('should trigger a warning when almost below target', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 90, x: before}, {y: 83, x: now}];
ctx.data.sgvs = [{y: 90, mills: before}, {y: 83, mills: now}];
var sbx = prepareSandbox();
ar2.checkNotifications(sbx);
@@ -105,7 +105,7 @@ describe('ar2', function ( ) {
it('should trigger a urgent alarm when falling fast', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 120, x: before}, {y: 85, x: now}];
ctx.data.sgvs = [{y: 120, mills: before}, {y: 85, mills: now}];
var sbx = prepareSandbox();
ar2.checkNotifications(sbx);
@@ -118,8 +118,8 @@ describe('ar2', function ( ) {
it('should include current raw bg and raw bg forecast when predicting w/raw', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{unfiltered: 113680, filtered: 111232, y: 100, x: before, noise: 1}, {unfiltered: 183680, filtered: 111232, y: 100, x: now, noise: 1}];
ctx.data.cals = [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, x: now}];
ctx.data.sgvs = [{unfiltered: 113680, filtered: 111232, y: 100, mills: before, noise: 1}, {unfiltered: 183680, filtered: 111232, y: 100, mills: now, noise: 1}];
ctx.data.cals = [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, mills: now}];
var envRaw = require('../env')();
envRaw.extendedSettings = {'ar2': {useRaw: true}};
@@ -150,8 +150,8 @@ describe('ar2', function ( ) {
it('should not trigger an alarm when raw is missing or 0', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{unfiltered: 0, filtered: 0, y: 100, x: before, noise: 1}, {unfiltered: 0, filtered: 0, y: 100, x: now, noise: 1}];
ctx.data.cals = [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, x: now}];
ctx.data.sgvs = [{unfiltered: 0, filtered: 0, y: 100, mills: before, noise: 1}, {unfiltered: 0, filtered: 0, y: 100, mills: now, noise: 1}];
ctx.data.cals = [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, mills: now}];
var sbx = rawSandbox();
ar2.checkNotifications(sbx.withExtendedSettings(ar2));
@@ -163,8 +163,8 @@ describe('ar2', function ( ) {
it('should trigger a warning (no urgent for raw) when raw is falling really fast, but sgv is steady', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{unfiltered: 113680, filtered: 111232, y: 100, x: before, noise: 1}, {unfiltered: 43680, filtered: 111232, y: 100, x: now, noise: 1}];
ctx.data.cals = [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, x: now}];
ctx.data.sgvs = [{unfiltered: 113680, filtered: 111232, y: 100, mills: before, noise: 1}, {unfiltered: 43680, filtered: 111232, y: 100, mills: now, noise: 1}];
ctx.data.cals = [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, mills: now}];
var sbx = rawSandbox();
sbx.offerProperty('rawbg', function setFakeIOB() {
@@ -181,8 +181,8 @@ describe('ar2', function ( ) {
it('should trigger a warning (no urgent for raw) when raw is rising really fast, but sgv is steady', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{unfiltered: 113680, filtered: 111232, y: 100, x: before, noise: 1}, {unfiltered: 183680, filtered: 111232, y: 100, x: now, noise: 1}];
ctx.data.cals = [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, x: now}];
ctx.data.sgvs = [{unfiltered: 113680, filtered: 111232, y: 100, mills: before, noise: 1}, {unfiltered: 183680, filtered: 111232, y: 100, mills: now, noise: 1}];
ctx.data.cals = [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, mills: now}];
var sbx = rawSandbox();
sbx.offerProperty('rawbg', function setFakeIOB() {
+3 -3
View File
@@ -37,7 +37,7 @@ describe('boluswizardpreview', function ( ) {
it('Not trigger an alarm when in range', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: before, y: 95}, {x: now, y: 100}];
ctx.data.sgvs = [{mills: before, y: 95}, {mills: now, y: 100}];
ctx.data.profiles = [profile];
var sbx = prepareSandbox();
@@ -50,7 +50,7 @@ describe('boluswizardpreview', function ( ) {
it('trigger a warning when going out of range', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: before, y: 175}, {x: now, y: 180}];
ctx.data.sgvs = [{mills: before, y: 175}, {mills: now, y: 180}];
ctx.data.profiles = [profile];
var sbx = prepareSandbox();
@@ -65,7 +65,7 @@ describe('boluswizardpreview', function ( ) {
it('trigger an urgent alarms when going too high', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: before, y: 295}, {x: now, y: 300}];
ctx.data.sgvs = [{mills: before, y: 295}, {mills: now, y: 300}];
ctx.data.profiles = [profile];
var sbx = prepareSandbox();
+19 -15
View File
@@ -8,40 +8,44 @@ describe('Data', function ( ) {
var ctx = {};
var data = require('../lib/data')(env, ctx);
var now = Date.now();
var before = now - (5 * 60 * 1000);
it('should return original data if there are no changes', function() {
data.sgvs = [{sgv: 100, x:100},{sgv: 100, x:99}];
data.sgvs = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
var delta = data.calculateDeltaBetweenDatasets(data,data);
delta.should.equal(data);
});
it('adding one sgv record should return delta with one sgv', function() {
data.sgvs = [{sgv: 100, x:100},{sgv: 100, x:99}];
data.sgvs = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
var newData = data.clone();
newData.sgvs = [{sgv: 100, x:101},{sgv: 100, x:100},{sgv: 100, x:99}];
newData.sgvs = [{sgv: 100, mills:101},{sgv: 100, mills: before},{sgv: 100, mills: now}];
var delta = data.calculateDeltaBetweenDatasets(data,newData);
delta.delta.should.equal(true);
delta.sgvs.length.should.equal(1);
});
it('adding one treatment record should return delta with one treatment', function() {
data.treatments = [{sgv: 100, x:100},{sgv: 100, x:99}];
data.treatments = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
var newData = data.clone();
newData.treatments = [{sgv: 100, x:100},{sgv: 100, x:99},{sgv: 100, x:98}];
newData.treatments = [{sgv: 100, mills: before},{sgv: 100, mills: now},{sgv: 100, mills:98}];
var delta = data.calculateDeltaBetweenDatasets(data,newData);
delta.delta.should.equal(true);
delta.treatments.length.should.equal(1);
});
it('changes to treatments, mbgs and cals should be calculated even if sgvs is not changed', function() {
data.sgvs = [{sgv: 100, x:100},{sgv: 100, x:99}];
data.treatments = [{sgv: 100, x:100},{sgv: 100, x:99}];
data.mbgs = [{sgv: 100, x:100},{sgv: 100, x:99}];
data.cals = [{sgv: 100, x:100},{sgv: 100, x:99}];
data.sgvs = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
data.treatments = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
data.mbgs = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
data.cals = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
var newData = data.clone();
newData.sgvs = [{sgv: 100, x:100},{sgv: 100, x:99}];
newData.treatments = [{sgv: 100, x:101},{sgv: 100, x:100},{sgv: 100, x:99}];
newData.mbgs = [{sgv: 100, x:101},{sgv: 100, x:100},{sgv: 100, x:99}];
newData.cals = [{sgv: 100, x:101},{sgv: 100, x:100},{sgv: 100, x:99}];
newData.sgvs = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
newData.treatments = [{sgv: 100, mills:101},{sgv: 100, mills: before},{sgv: 100, mills: now}];
newData.mbgs = [{sgv: 100, mills:101},{sgv: 100, mills: before},{sgv: 100, mills: now}];
newData.cals = [{sgv: 100, mills:101},{sgv: 100, mills: before},{sgv: 100, mills: now}];
var delta = data.calculateDeltaBetweenDatasets(data,newData);
delta.delta.should.equal(true);
delta.treatments.length.should.equal(1);
@@ -50,11 +54,11 @@ describe('Data', function ( ) {
});
it('delta should include profile and devicestatus object if changed', function() {
data.sgvs = [{sgv: 100, x:100},{sgv: 100, x:99}];
data.sgvs = [{sgv: 100, mills: before},{sgv: 100, mills: now}];
data.profiles = {foo:true};
data.devicestatus = {foo:true};
var newData = data.clone();
newData.sgvs = [{sgv: 100, x:101},{sgv: 100, x:100},{sgv: 100, x:99}];
newData.sgvs = [{sgv: 100, mills:101},{sgv: 100, mills: before},{sgv: 100, mills: now}];
newData.profiles = {bar:true};
newData.devicestatus = {bar:true};
var delta = data.calculateDeltaBetweenDatasets(data,newData);
+5 -5
View File
@@ -14,7 +14,7 @@ describe('errorcodes', function ( ) {
it('Not trigger an alarm when in range', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 100, x: now}];
ctx.data.sgvs = [{y: 100, mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
errorcodes.checkNotifications(sbx);
@@ -25,7 +25,7 @@ describe('errorcodes', function ( ) {
it('should trigger a urgent alarm when ???', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 10, x: now}];
ctx.data.sgvs = [{y: 10, mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
errorcodes.checkNotifications(sbx);
@@ -36,7 +36,7 @@ describe('errorcodes', function ( ) {
it('should trigger a urgent alarm when hourglass', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 9, x: now}];
ctx.data.sgvs = [{y: 9, mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
errorcodes.checkNotifications(sbx);
@@ -47,7 +47,7 @@ describe('errorcodes', function ( ) {
it('should trigger a low notification when needing calibration', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: 5, x: now}];
ctx.data.sgvs = [{y: 5, mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
errorcodes.checkNotifications(sbx);
@@ -61,7 +61,7 @@ describe('errorcodes', function ( ) {
for (var i = 0; i < 9; i++) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{y: i, x: now}];
ctx.data.sgvs = [{y: i, mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
errorcodes.checkNotifications(sbx);
+2 -2
View File
@@ -9,8 +9,8 @@ describe('Raw BG', function ( ) {
var now = Date.now();
var pluginBase = {};
var data = {
sgvs: [{unfiltered: 113680, filtered: 111232, y: 110, noise: 1, x: now}]
, cals: [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, x: now}]
sgvs: [{unfiltered: 113680, filtered: 111232, y: 110, noise: 1, mills: now}]
, cals: [{scale: 1, intercept: 25717.82377004309, slope: 766.895601715918, mills: now}]
};
var app = { };
var clientSettings = {
+4 -13
View File
@@ -20,7 +20,7 @@ describe('sandbox', function ( ) {
};
var pluginBase = {};
var data = {sgvs: [{y: 100, x: now}]};
var data = {sgvs: [{y: 100, mills: now}]};
var sbx = sandbox.clientInit(app, clientSettings, Date.now(), pluginBase, data);
@@ -42,7 +42,7 @@ describe('sandbox', function ( ) {
it('init on server', function (done) {
var sbx = createServerSandbox();
sbx.data.sgvs = [{y: 100, x: now}];
sbx.data.sgvs = [{y: 100, mills: now}];
should.exist(sbx.notifications.requestNotify);
should.not.exist(sbx.notifications.process);
@@ -63,7 +63,7 @@ describe('sandbox', function ( ) {
it('build BG Now line using properties', function ( ) {
var sbx = createServerSandbox();
sbx.data.sgvs = [{y: 99, x: now}];
sbx.data.sgvs = [{y: 99, mills: now}];
sbx.properties = { delta: {display: '+5' }, direction: {value: 'FortyFiveUp', label: '↗', entity: '&#8599;'} };
sbx.buildBGNowLine().should.equal('BG Now: 99 +5 ↗ mg/dl');
@@ -72,7 +72,7 @@ describe('sandbox', function ( ) {
it('build default message using properties', function ( ) {
var sbx = createServerSandbox();
sbx.data.sgvs = [{y: 99, x: now}];
sbx.data.sgvs = [{y: 99, mills: now}];
sbx.properties = {
delta: {display: '+5' }
, direction: {value: 'FortyFiveUp', label: '↗', entity: '&#8599;'}
@@ -85,13 +85,4 @@ describe('sandbox', function ( ) {
});
//FIXME: field mismatch between server and client :(, remove this test when we get that cleaned up
it('Use the x or date fields to find an entries time in mills', function () {
var sbx = createServerSandbox();
sbx.entryMills({x: now}).should.equal(now);
sbx.entryMills({date: now}).should.equal(now);
});
});
+5 -5
View File
@@ -16,7 +16,7 @@ describe('simplealarms', function ( ) {
it('Not trigger an alarm when in range', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 100}];
ctx.data.sgvs = [{mills: now, y: 100}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
simplealarms.checkNotifications(sbx);
@@ -27,7 +27,7 @@ describe('simplealarms', function ( ) {
it('should trigger a warning when above target', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: before, y: 171}, {x: now, y: 181}];
ctx.data.sgvs = [{mills: before, y: 171}, {mills: now, y: 181}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
delta.setProperties(sbx);
@@ -40,7 +40,7 @@ describe('simplealarms', function ( ) {
it('should trigger a urgent alarm when really high', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 400}];
ctx.data.sgvs = [{mills: now, y: 400}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
simplealarms.checkNotifications(sbx);
@@ -51,7 +51,7 @@ describe('simplealarms', function ( ) {
it('should trigger a warning when below target', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 70}];
ctx.data.sgvs = [{mills: now, y: 70}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
simplealarms.checkNotifications(sbx);
@@ -62,7 +62,7 @@ describe('simplealarms', function ( ) {
it('should trigger a urgent alarm when really low', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 40}];
ctx.data.sgvs = [{mills: now, y: 40}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
simplealarms.checkNotifications(sbx);
+8 -8
View File
@@ -14,8 +14,8 @@ describe('treatmentnotify', function ( ) {
it('Request a snooze for a recent treatment and request an info notify', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 100}];
ctx.data.treatments = [{eventType: 'BG Check', glucose: '100', x: now}];
ctx.data.sgvs = [{mills: now, y: 100}];
ctx.data.treatments = [{eventType: 'BG Check', glucose: '100', mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
@@ -29,8 +29,8 @@ describe('treatmentnotify', function ( ) {
it('Not Request a snooze for an older treatment and not request an info notification', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 100}];
ctx.data.treatments = [{x: Date.now() - (15 * 60 * 1000)}];
ctx.data.sgvs = [{mills: now, y: 100}];
ctx.data.treatments = [{mills: now - (15 * 60 * 1000)}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
@@ -44,8 +44,8 @@ describe('treatmentnotify', function ( ) {
it('Request a snooze for a recent calibration and request an info notify', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 100}];
ctx.data.mbgs = [{y: '100', x: Date.now()}];
ctx.data.sgvs = [{mills: now, y: 100}];
ctx.data.mbgs = [{y: '100', mills: now}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);
@@ -59,8 +59,8 @@ describe('treatmentnotify', function ( ) {
it('Not Request a snooze for an older calibration treatment and not request an info notification', function (done) {
ctx.notifications.initRequests();
ctx.data.sgvs = [{x: now, y: 100}];
ctx.data.mbgs = [{y: '100', x: Date.now() - (15 * 60 * 1000)}];
ctx.data.sgvs = [{mills: now, y: 100}];
ctx.data.mbgs = [{y: '100', mills: now - (15 * 60 * 1000)}];
var sbx = require('../lib/sandbox')().serverInit(env, ctx);
treatmentnotify.checkNotifications(sbx);