Skip to content

Commit

Permalink
show bg (and rawbg/noise) even if there isn't a previous value
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Mar 28, 2015
1 parent d8164d5 commit 2bfa20c
Showing 1 changed file with 18 additions and 42 deletions.
60 changes: 18 additions & 42 deletions static/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,28 +369,6 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
currentBG.toggleClass('bg-limit', value == 39 || value > 400);
}

function updateCurrentNoise(entry) {
var noise = entry.noise
, noiseType;

if (!showRawBGs(entry.y, noise, cal)) {
noiseType = null;
} else if (entry.y < 40) {
noiseType = 'error';
} else if (noise == 2) {
noiseType = 'light';
} else if (noise == 3) {
noiseType = 'medium';
} else if (noise >= 4) {
noiseType = 'heavy';
}

bgButton.removeClass('noise-light noise-medium noise-heavy noise-error');
if (noiseType) {
bgButton.addClass('noise-' + noiseType);
}
}

function updateBGDelta(prev, current) {

var pill = currentDetails.find('span.pill.bgdelta');
Expand All @@ -400,21 +378,19 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
}

if (prev === undefined || current == undefined || prev < 40 || prev > 400 || current < 40 || current > 400) {
pill.children('em').text('#');
pill.children('em').hide();
} else {
var bgDelta = scaleBg(current) - scaleBg(prev);
if (browserSettings.units == 'mmol') {
bgDelta = bgDelta.toFixed(1);
pill.children('label').text('mmol/L');
} else {
pill.children('label').text('mg/dL');
}

pill.children('em').text((bgDelta >= 0 ? '+' : '') + bgDelta);
pill.children('em').text((bgDelta >= 0 ? '+' : '') + bgDelta).show();
}

if (browserSettings.units == 'mmol') {
pill.children('label').text('mmol/L');
} else {
pill.children('label').text('mg/dL');
}

}

Expand Down Expand Up @@ -445,7 +421,8 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
});

if (inRetroMode()) {
var time = new Date(brushExtent[1] - THIRTY_MINS_IN_MS);
var retroTime = new Date(brushExtent[1] - THIRTY_MINS_IN_MS);

// filter data for -12 and +5 minutes from reference time for retrospective focus data prediction
var lookbackTime = (lookback + 2) * FIVE_MINS_IN_MS + 2 * ONE_MIN_IN_MS;
nowData = nowData.filter(function(d) {
Expand All @@ -461,17 +438,18 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
return ok;
});

if (nowData.length > lookback) {
var focusPoint = nowData[nowData.length - 1];
var prevfocusPoint = nowData[nowData.length - 2];

var focusPoint = nowData.length > 0 ? nowData[nowData.length - 1] : null;
if (focusPoint) {
updateCurrentSGV(focusPoint);
updateCurrentNoise(focusPoint);

updateBGDelta(prevfocusPoint.y, focusPoint.y);

currentBG.css('text-decoration','line-through');
currentDirection.html(focusPoint.y < 39 ? '✖' : focusPoint.direction);

var prevfocusPoint = nowData.length > lookback ? nowData[nowData.length - 2] : null;
if (prevfocusPoint) {
updateBGDelta(prevfocusPoint.y, focusPoint.y);
} else {
updateBGDelta();
}
} else {
updateBGDelta();
currentBG.text('---');
Expand All @@ -480,10 +458,10 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
bgButton.removeClass('urgent warning inrange');
}

updateIOBIndicator(time);
updateIOBIndicator(retroTime);

$('#currentTime')
.text(formatTime(time))
.text(formatTime(retroTime))
.css('text-decoration','line-through');

updateTimeAgo();
Expand All @@ -493,7 +471,6 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
nowDate = new Date(now);

updateCurrentSGV(latestSGV);
updateCurrentNoise(latestSGV);
updateClockDisplay();
updateTimeAgo();

Expand Down Expand Up @@ -1191,7 +1168,6 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage;
var totalBG = 0;
closeBGs.forEach(function(d) {
totalBG += Number(d.y);
parseFloat()
});

return totalBG > 0 ? (totalBG / closeBGs.length) : 450;
Expand Down

0 comments on commit 2bfa20c

Please sign in to comment.