From 647dec228ee39f5eef24ac4c93c2bb5792464390 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sun, 15 Mar 2015 23:23:57 -0700 Subject: [PATCH 1/6] display uploader battery next to time ago --- lib/websocket.js | 18 ++++++++++++++---- server.js | 2 +- static/css/main.css | 16 ++++++++-------- static/index.html | 3 ++- static/js/client.js | 13 +++++++++++++ 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lib/websocket.js b/lib/websocket.js index 161d239f8..59a66e350 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -1,6 +1,6 @@ var async = require('async'); -function websocket (env, server, entries, treatments, profiles) { +function websocket (env, server, entries, treatments, profiles, devicestatus) { "use strict"; // CONSTANTS var ONE_HOUR = 3600000, @@ -31,7 +31,8 @@ var dir2Char = { mbgData = [], calData = [], profileData = [], - patientData = []; + patientData = [], + devicestatusData = {}; function start ( ) { io = require('socket.io').listen(server, { @@ -154,6 +155,7 @@ function update() { treatmentData = []; mbgData = []; profileData = []; + devicestatusData = {}; var earliest_data = now - TWO_DAYS; async.parallel({ @@ -228,6 +230,14 @@ function update() { callback(); }); } + , devicestatus: function(callback) { + devicestatus.last(function (err, result) { + devicestatusData = { + uploaderBattery: result.uploaderBattery + }; + callback(); + }) + } }, loadData); return update; @@ -311,8 +321,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, cal); - patientData = [actual, predicted, mbg, treatment, profile, cal]; + var shouldEmit = is_different(actual, predicted, mbg, treatment, cal, devicestatusData); + patientData = [actual, predicted, mbg, treatment, profile, cal, devicestatusData]; console.log('patientData', patientData.length); if (shouldEmit) { emitData( ); diff --git a/server.js b/server.js index e427926d6..10eb36028 100644 --- a/server.js +++ b/server.js @@ -115,7 +115,7 @@ store(function ready ( ) { // setup socket io for data and message transmission /////////////////////////////////////////////////// var websocket = require('./lib/websocket'); - var io = websocket(env, server, entriesStorage, treatmentsStorage, profile); + var io = websocket(env, server, entriesStorage, treatmentsStorage, profile, devicestatusStorage); }); /////////////////////////////////////////////////// diff --git a/static/css/main.css b/static/css/main.css index 18b6944a4..b4b9e8788 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -119,38 +119,38 @@ span.pill label { line-height: 30px; } -.loading #lastEntry { +.loading .timeOther { display: none; } -#lastEntry { +.timeOther .pill { background: #808080; border-color: #808080; } -#lastEntry.pill em { +.timeOther .pill em { color: #bdbdbd; background: #000; border-radius: 4px 0 0 4px; } -#lastEntry.pill label { +.timeOther .pill label { background: #808080; } -#lastEntry.warn, #lastEntry.warn label { +.timeOther .warn, .timeOther .warn label { background: yellow; border-color: yellow; } -#lastEntry.warn em { +.timeOther .warn em { color: yellow; } -#lastEntry.urgent, #lastEntry.urgent label { +.timeOther .urgent, .timeOther .urgent label { background: red; border-color: red; } -#lastEntry.urgent em { +.timeOther .urgent em { color: red; } diff --git a/static/index.html b/static/index.html index 5fab9d6b1..6a8e1df85 100644 --- a/static/index.html +++ b/static/index.html @@ -44,7 +44,8 @@

Nightscout

---
- - + +
diff --git a/static/js/client.js b/static/js/client.js index 75bc5600c..ffb9f4f25 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -35,6 +35,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; , treatments , profile , cal + , devicestatusData , padding = { top: 0, right: 10, bottom: 30, left: 10 } , opacity = {current: 1, DAY: 1, NIGHT: 0.5} , now = Date.now() @@ -442,6 +443,17 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; updateClockDisplay(); updateTimeAgo(); + var battery = devicestatusData.uploaderBattery; + $('#uploaderBattery em').text(battery + '%'); + $('#uploaderBattery label') + .toggleClass('icon-battery-100', battery >= 95) + .toggleClass('icon-battery-75', battery < 95 && battery >= 55) + .toggleClass('icon-battery-50', battery < 55 && battery >= 30) + .toggleClass('icon-battery-25', battery < 30); + + $('#uploaderBattery').toggleClass('warn', battery <= 30 && battery > 20); + $('#uploaderBattery').toggleClass('urgent', battery <= 20); + updateBGDelta(prevSGV.y, latestSGV.y); updateIOBIndicator(nowDate); @@ -1452,6 +1464,7 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; profile = d[4][0]; cal = d[5][d[5].length-1]; + devicestatusData = d[6]; var temp1 = [ ]; if (cal && showRawBGs()) { From 9062a6c5b0680278bed6849132355b7e9b0f850a Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Sun, 15 Mar 2015 23:40:39 -0700 Subject: [PATCH 2/6] smaller battery icon when screen < 800px --- static/css/main.css | 4 ++++ static/index.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/static/css/main.css b/static/css/main.css index b4b9e8788..62dce4ceb 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -319,6 +319,10 @@ div.tooltip { line-height: 40px; } + #uploaderBattery label { + font-size: 15px !important; + } + .focus-range { margin: 0; } diff --git a/static/index.html b/static/index.html index 6a8e1df85..0ff53abe7 100644 --- a/static/index.html +++ b/static/index.html @@ -45,7 +45,7 @@

Nightscout

---
- +
From 429d3b2d06aa433486891de9d6fb89500ab052db Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Mon, 16 Mar 2015 17:52:30 -0700 Subject: [PATCH 3/6] better handling of potentional errors and null vars --- lib/websocket.js | 96 +++++++++++++++++++++++++++++------------------------ static/js/client.js | 26 +++++++++------ 2 files changed, 68 insertions(+), 54 deletions(-) diff --git a/lib/websocket.js b/lib/websocket.js index 59a66e350..f035dd901 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -162,47 +162,51 @@ function update() { entries: function(callback) { var q = { find: {"date": {"$gte": earliest_data}} }; entries.list(q, function (err, results) { - results.forEach(function (element) { - if (element) { - if (element.mbg) { - mbgData.push({ - y: element.mbg - , x: element.date - , d: element.dateString - , device: element.device - }); - } else if (element.sgv) { - cgmData.push({ - y: element.sgv - , x: element.date - , d: element.dateString - , device: element.device - , direction: directionToChar(element.direction) - , filtered: element.filtered - , unfiltered: element.unfiltered - , noise: element.noise - , rssi: element.rssi - }); + if (!err && results) { + results.forEach(function (element) { + if (element) { + if (element.mbg) { + mbgData.push({ + y: element.mbg + , x: element.date + , d: element.dateString + , device: element.device + }); + } else if (element.sgv) { + cgmData.push({ + y: element.sgv + , x: element.date + , d: element.dateString + , device: element.device + , direction: directionToChar(element.direction) + , filtered: element.filtered + , unfiltered: element.unfiltered + , noise: element.noise + , rssi: element.rssi + }); + } } - } - }); + }); + } callback(); }) } , cal: function(callback) { var cq = { count: 1, find: {"type": "cal"} }; entries.list(cq, function (err, results) { - results.forEach(function (element) { - if (element) { - calData.push({ - x: element.date - , d: element.dateString - , scale: element.scale - , intercept: element.intercept - , slope: element.slope - }); - } - }); + if (!err && results) { + results.forEach(function (element) { + if (element) { + calData.push({ + x: element.date + , d: element.dateString + , scale: element.scale + , intercept: element.intercept + , slope: element.slope + }); + } + }); + } callback(); }); } @@ -219,22 +223,26 @@ function update() { } , profile: function(callback) { profiles.list(function (err, results) { - // There should be only one document in the profile collection with a DIA. If there are multiple, use the last one. - results.forEach(function(element, index, array) { - if (element) { - if (element.dia) { - profileData[0] = element; + if (!err && results) { + // There should be only one document in the profile collection with a DIA. If there are multiple, use the last one. + results.forEach(function (element, index, array) { + if (element) { + if (element.dia) { + profileData[0] = element; + } } - } - }); + }); + } callback(); }); } , devicestatus: function(callback) { devicestatus.last(function (err, result) { - devicestatusData = { - uploaderBattery: result.uploaderBattery - }; + if (!err && result) { + devicestatusData = { + uploaderBattery: result.uploaderBattery + }; + } callback(); }) } diff --git a/static/js/client.js b/static/js/client.js index ffb9f4f25..c2d3c5c95 100644 --- a/static/js/client.js +++ b/static/js/client.js @@ -443,16 +443,22 @@ var app = {}, browserSettings = {}, browserStorage = $.localStorage; updateClockDisplay(); updateTimeAgo(); - var battery = devicestatusData.uploaderBattery; - $('#uploaderBattery em').text(battery + '%'); - $('#uploaderBattery label') - .toggleClass('icon-battery-100', battery >= 95) - .toggleClass('icon-battery-75', battery < 95 && battery >= 55) - .toggleClass('icon-battery-50', battery < 55 && battery >= 30) - .toggleClass('icon-battery-25', battery < 30); - - $('#uploaderBattery').toggleClass('warn', battery <= 30 && battery > 20); - $('#uploaderBattery').toggleClass('urgent', battery <= 20); + var battery = devicestatusData && devicestatusData.uploaderBattery; + if (battery) { + $('#uploaderBattery em').text(battery + '%'); + $('#uploaderBattery label') + .toggleClass('icon-battery-100', battery >= 95) + .toggleClass('icon-battery-75', battery < 95 && battery >= 55) + .toggleClass('icon-battery-50', battery < 55 && battery >= 30) + .toggleClass('icon-battery-25', battery < 30); + + $('#uploaderBattery') + .show() + .toggleClass('warn', battery <= 30 && battery > 20) + .toggleClass('urgent', battery <= 20); + } else { + $('#uploaderBattery').hide(); + } updateBGDelta(prevSGV.y, latestSGV.y); updateIOBIndicator(nowDate); From cce7622be8f4418f120e31e0762d1479e16a6c03 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Mon, 16 Mar 2015 19:28:07 -0700 Subject: [PATCH 4/6] some tweeks for the battery and time ago pills --- static/css/main.css | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/static/css/main.css b/static/css/main.css index 62dce4ceb..554be735c 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -79,27 +79,35 @@ body { margin-left: 5px; } -span.pill { +.pill { white-space: nowrap; border-radius: 5px; border: 2px solid #808080; } -span.pill * { +.pill * { padding-left: 2px; padding-right: 2px; } -span.pill em { +.pill em { font-style: normal; font-weight: bold; } -span.pill label { +.pill label { color: #000; background: #808080; } +.pill.warn em { + color: yellow !important; +} + +.pill.urgent em { + color: red !important; +} + .bgStatus.current .currentBG { text-decoration: none; } @@ -138,20 +146,8 @@ span.pill label { background: #808080; } -.timeOther .warn, .timeOther .warn label { - background: yellow; - border-color: yellow; -} -.timeOther .warn em { - color: yellow; -} - -.timeOther .urgent, .timeOther .urgent label { - background: red; - border-color: red; -} -.timeOther .urgent em { - color: red; +#uploaderBattery label { + padding: 0 !important; } #chartContainer { From 46f4a40ecc7241e85b95ebe0023d6860e6256e4f Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Mon, 16 Mar 2015 20:11:23 -0700 Subject: [PATCH 5/6] adjust size in case where BG is at LOW or HIGH limit --- static/css/main.css | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/static/css/main.css b/static/css/main.css index 554be735c..2a9c92880 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -59,7 +59,7 @@ body { vertical-align: middle; } -.bgStatus .currentBG.icon-hourglass { +.bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 90px; } @@ -292,7 +292,7 @@ div.tooltip { line-height: 80px; } - .bgStatus .currentBG.icon-hourglass { + .bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 70px; } @@ -346,7 +346,7 @@ div.tooltip { line-height: 60px; } - .bgStatus .currentBG.icon-hourglass { + .bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 50px; } @@ -398,8 +398,9 @@ div.tooltip { line-height: 70px; } - .bgStatus .currentBG.icon-hourglass { + .bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 60px; + padding-left: 20px; } .bgStatus .currentDirection { @@ -508,7 +509,7 @@ div.tooltip { line-height: 80px; } - .bgStatus .currentBG.icon-hourglass { + .bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 70px; } @@ -540,7 +541,7 @@ div.tooltip { line-height: 60px; } - .bgStatus .currentBG.icon-hourglass { + .bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 60px; } From 04d1d37fc0fa29ebf8545ea4701cd7ea0af69c93 Mon Sep 17 00:00:00 2001 From: Jason Calabrese Date: Tue, 17 Mar 2015 07:59:06 -0700 Subject: [PATCH 6/6] a couple more little css tweeks for battery --- static/css/main.css | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/static/css/main.css b/static/css/main.css index 2a9c92880..ef5bc95ef 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -116,7 +116,6 @@ body { color: #808080; font-size: 100px; line-height: 100px; - padding-top: 15px; } .timebox { text-align: center; @@ -259,6 +258,7 @@ div.tooltip { list-style: none; margin: 4px; padding: 0; + color: #808080; width: 250px; text-align: center; } @@ -443,6 +443,10 @@ div.tooltip { font-size: 15px; } + #uploaderBattery label { + font-size: 15px !important; + } + .alarming .focus-range { display: none; } @@ -532,6 +536,10 @@ div.tooltip { font-size: 15px; } + #uploaderBattery label { + font-size: 15px !important; + } + } @media (max-height: 480px) and (max-width: 400px) {