diff --git a/static/js/client.js b/static/js/client.js index e11acd5c8..e702aea5c 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -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'); @@ -400,14 +378,14 @@ 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('em').text((bgDelta >= 0 ? '+' : '') + bgDelta); + pill.children('em').text((bgDelta >= 0 ? '+' : '') + bgDelta).show(); } if (browserSettings.units == 'mmol') { @@ -416,6 +394,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; pill.children('label').text('mg/dL'); } + } function updateIOBIndicator(time) { @@ -445,7 +424,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) { @@ -461,17 +441,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('---'); @@ -480,10 +461,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(); @@ -493,7 +474,6 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; nowDate = new Date(now); updateCurrentSGV(latestSGV); - updateCurrentNoise(latestSGV); updateClockDisplay(); updateTimeAgo(); @@ -543,6 +523,10 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; return radius / focusRangeAdjustment; }; + function isDexcom(device) { + return device && device.toLowerCase().indexOf('dexcom') == 0; + } + function prepareFocusCircles(sel) { var badData = []; sel.attr('cx', function (d) { return xScale(d.date); }) @@ -558,8 +542,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; .attr('opacity', function (d) { return futureOpacity(d.date.getTime() - latestSGV.x); }) .attr('stroke-width', function (d) { if (d.type == 'mbg') return 2; else return 0; }) .attr('stroke', function (d) { - var device = d.device && d.device.toLowerCase(); - return (device == 'dexcom' ? 'white' : '#0099ff'); + return (isDexcom(d.device) ? 'white' : '#0099ff'); }) .attr('r', function (d) { return dotRadius(d.type); }); @@ -578,8 +561,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; .on('mouseover', function (d) { if (d.type != 'sgv' && d.type != 'mbg') return; - var device = d.device && d.device.toLowerCase() - , bgType = (d.type == 'sgv' ? 'CGM' : (device == 'dexcom' ? 'Calibration' : 'Meter')) + var bgType = (d.type == 'sgv' ? 'CGM' : (isDexcom(d.device) ? 'Calibration' : 'Meter')) , rawBG = 0 , noiseLabel = ''; @@ -1191,7 +1173,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; @@ -1213,7 +1194,6 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; treatmentGlucose = scaleBg(treatment.glucose); } } else { - console.warn('found an VALID glucose value', treatment); treatmentGlucose = treatment.glucose; } } else if (treatment.glucose) { @@ -1569,13 +1549,16 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; var temp1 = [ ]; if (cal && isRawBGEnabled()) { temp1 = d[0].map(function (entry) { - var noise = entry.noise || 0; - var rawBg = noise < 2 && browserSettings.showRawbg != 'always' ? 0 : rawIsigToRawBg(entry, cal); - return { date: new Date(entry.x - 2 * 1000), y: rawBg, sgv: scaleBg(rawBg), color: 'white', type: 'rawbg'} - }).filter(function(entry) { return entry.y > 0}); + var rawBg = showRawBGs(entry.y, entry.noise, cal) ? rawIsigToRawBg(entry, cal) : 0; + if (rawBg > 0) { + return { date: new Date(entry.x - 2000), y: rawBg, sgv: scaleBg(rawBg), color: 'white', type: 'rawbg' }; + } else { + return null; + } + }).filter(function(entry) { return entry != null; }); } 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', noise: obj.noise, filtered: obj.filtered, unfiltered: obj.unfiltered} + return { date: new Date(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}; }); data = []; data = data.concat(temp1, temp2);