diff --git a/lib/websocket.js b/lib/websocket.js index 7175a3b671e..c816db8625e 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -45,7 +45,6 @@ var dir2Char = { function emitData ( ) { console.log('running emitData', now, patientData && patientData.length); if (patientData.length > 0) { - io.sockets.emit("now", now); io.sockets.emit("sgv", patientData); } } @@ -62,7 +61,6 @@ var dir2Char = { function listeners ( ) { io.sockets.on('connection', function (socket) { - io.sockets.emit("now", now); io.sockets.emit("sgv", patientData); io.sockets.emit("clients", ++watchers); socket.on('ack', function(alarmType, silenceTime) { @@ -312,6 +310,7 @@ function loadData() { } } } + function is_different (actual, predicted, mbg, treatment, errorCode) { if (patientData && patientData.length < 3) { return true; @@ -333,6 +332,7 @@ function loadData() { // textual diff of objects if (JSON.stringify(old) == JSON.stringify(last)) { + console.info("data isn't different, will not send to clients"); return false; } return true; diff --git a/static/index.html b/static/index.html index 39b393c38d3..0fe5dd347e7 100644 --- a/static/index.html +++ b/static/index.html @@ -75,7 +75,7 @@

Nightscout

-
Enable Alarms
+
Enable Alarms
@@ -213,6 +213,7 @@

Nightscout

+ diff --git a/static/js/client.js b/static/js/client.js index 55bb62d63de..b2eb3a7a85a 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -26,6 +26,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; var socket , isInitialData = false , latestSGV + , latestUpdateTime , prevSGV , errorCode , treatments @@ -192,6 +193,14 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; .style('opacity', function (d) { return highlightBrushPoints(d) }); } + function inRetroMode() { + if (!brush) return false; + + var brushExtent = brush.extent(); + var elementHidden = document.getElementById('bgButton').hidden == ''; + return brushExtent[1].getTime() - THIRTY_MINS_IN_MS < now && elementHidden != true; + } + // function to call when context chart is brushed function brushed(skipTimer) { @@ -230,7 +239,6 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; } } - var element = document.getElementById('bgButton').hidden == ''; var nowDate = new Date(brushExtent[1] - THIRTY_MINS_IN_MS); // predict for retrospective data @@ -239,7 +247,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; // the dexcom switches from unfiltered to filtered at the start of a rapid rise or fall, while preserving // almost identical predications at other times. var lookback = 2; - if (brushExtent[1].getTime() - THIRTY_MINS_IN_MS < now && element != true) { + if (inRetroMode()) { // 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; var nowDataRaw = data.filter(function(d) { @@ -319,9 +327,8 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; focusData = focusData.concat(prediction); var dateTime = new Date(now); nowDate = dateTime; - $('#currentTime') - .text(formatTime(dateTime)) - .css('text-decoration', ''); + + updateClockDisplay(); if (errorCode) { var errorDisplay; @@ -355,9 +362,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; } else { - var secsSinceLast = (Date.now() - new Date(latestSGV.x).getTime()) / 1000; - $('#lastEntry').text(timeAgo(secsSinceLast)).toggleClass('current', secsSinceLast < 10 * 60); - + updateTimeAgo(); //in this case the SGV is unscaled if (latestSGV.y < 40) { $('.container .currentBG').text('LOW'); @@ -1174,6 +1179,37 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; return predicted; } + function updateClock() { + updateClockDisplay(); + var interval = (60 - (new Date()).getSeconds()) * 1000 + 5; + setTimeout(updateClock,interval); + + updateTimeAgo(); + + // Dim the screen by reducing the opacity when at nighttime + if (browserSettings.nightMode) { + if (opacity.current != opacity.NIGHT && (dateTime.getHours() > 21 || dateTime.getHours() < 7)) { + $('body').css({ 'opacity': opacity.NIGHT }); + } else { + $('body').css({ 'opacity': opacity.DAY }); + } + } + } + + function updateClockDisplay() { + if (inRetroMode()) return; + now = Date.now(); + var dateTime = new Date(now); + $('#currentTime').text(formatTime(dateTime)).css('text-decoration', ''); + } + + function updateTimeAgo() { + if (!latestSGV || inRetroMode()) return; + + var secsSinceLast = (Date.now() - new Date(latestSGV.x).getTime()) / 1000; + $('#lastEntry').text(timeAgo(secsSinceLast)).toggleClass('current', secsSinceLast < 10 * 60); + } + function init() { jqWindow = $(window); @@ -1244,6 +1280,8 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; }, 100); }; + updateClock(); + var silenceDropdown = new Dropdown('.dropdown-menu'); $('#bgButton').click(function (e) { @@ -1260,27 +1298,13 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// socket = io.connect(); - socket.on('now', function (d) { - now = d; - var dateTime = new Date(now); - $('#currentTime').text(formatTime(dateTime)); - - // Dim the screen by reducing the opacity when at nighttime - if (browserSettings.nightMode) { - if (opacity.current != opacity.NIGHT && (dateTime.getHours() > 21 || dateTime.getHours() < 7)) { - $('body').css({ 'opacity': opacity.NIGHT }); - } else { - $('body').css({ 'opacity': opacity.DAY }); - } - } - }); - socket.on('sgv', function (d) { if (d.length > 1) { errorCode = d.length >= 5 ? d[4] : undefined; // change the next line so that it uses the prediction if the signal gets lost (max 1/2 hr) if (d[0].length) { + latestUpdateTime = Date.now(); latestSGV = d[0][d[0].length - 1]; prevSGV = d[0][d[0].length - 2]; } @@ -1389,6 +1413,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; , head: xhr.head , apiEnabled: xhr.apiEnabled , thresholds: xhr.thresholds + , alarm_types: xhr.alarm_types , units: xhr.units , careportalEnabled: xhr.careportalEnabled }; diff --git a/static/js/ui-utils.js b/static/js/ui-utils.js index f9b70185536..bdb15c0d427 100644 --- a/static/js/ui-utils.js +++ b/static/js/ui-utils.js @@ -24,6 +24,10 @@ function getBrowserSettings(storage) { } } + function appendThresholdValue(threshold) { + return app.alarm_types.indexOf('simple') == -1 ? '' : ' (' + scaleBg(threshold) + ')'; + } + try { var json = { "units": storage.get("units"), @@ -49,10 +53,10 @@ function getBrowserSettings(storage) { json.alarmHigh = setDefault(json.alarmHigh, defaultSettings.alarmHigh); json.alarmLow = setDefault(json.alarmLow, defaultSettings.alarmLow); json.alarmUrgentLow = setDefault(json.alarmUrgentLow, defaultSettings.alarmUrgentLow); - $("#alarm-urgenthigh-browser").prop("checked", json.alarmUrgentHigh).next().text('Urgent High Alarm (' + scaleBg(app.thresholds.bg_high) + ')'); - $("#alarm-high-browser").prop("checked", json.alarmHigh).next().text('High Alarm (' + scaleBg(app.thresholds.bg_target_top) + ')'); - $("#alarm-low-browser").prop("checked", json.alarmLow).next().text('Low Alarm (' + scaleBg(app.thresholds.bg_target_bottom) + ')'); - $("#alarm-urgentlow-browser").prop("checked", json.alarmUrgentLow).next().text('Urgent Low Alarm (' + scaleBg(app.thresholds.bg_low) + ')'); + $("#alarm-urgenthigh-browser").prop("checked", json.alarmUrgentHigh).next().text('Urgent High Alarm' + appendThresholdValue(app.thresholds.bg_high)); + $("#alarm-high-browser").prop("checked", json.alarmHigh).next().text('High Alarm' + appendThresholdValue(app.thresholds.bg_target_top)); + $("#alarm-low-browser").prop("checked", json.alarmLow).next().text('Low Alarm' + appendThresholdValue(app.thresholds.bg_target_bottom)); + $("#alarm-urgentlow-browser").prop("checked", json.alarmUrgentLow).next().text('Urgent Low Alarm' + appendThresholdValue(app.thresholds.bg_low)); json.nightMode = setDefault(json.nightMode, defaultSettings.nightMode); $("#nightmode-browser").prop("checked", json.nightMode);