diff --git a/lib/websocket.js b/lib/websocket.js index 159c85413..760aae25b 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,53 +155,58 @@ function update() { treatmentData = []; mbgData = []; profileData = []; + devicestatusData = {}; var earliest_data = now - TWO_DAYS; async.parallel({ 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(); }); } @@ -217,17 +223,29 @@ 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) { + if (!err && result) { + devicestatusData = { + uploaderBattery: result.uploaderBattery + }; + } + callback(); + }) + } }, loadData); return update; @@ -311,8 +329,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..ef5bc95ef 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; } @@ -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; } @@ -108,7 +116,6 @@ span.pill label { color: #808080; font-size: 100px; line-height: 100px; - padding-top: 15px; } .timebox { text-align: center; @@ -119,39 +126,27 @@ 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 { - background: yellow; - border-color: yellow; -} -#lastEntry.warn em { - color: yellow; -} - -#lastEntry.urgent, #lastEntry.urgent label { - background: red; - border-color: red; -} -#lastEntry.urgent em { - color: red; +#uploaderBattery label { + padding: 0 !important; } #chartContainer { @@ -263,6 +258,7 @@ div.tooltip { list-style: none; margin: 4px; padding: 0; + color: #808080; width: 250px; text-align: center; } @@ -296,7 +292,7 @@ div.tooltip { line-height: 80px; } - .bgStatus .currentBG.icon-hourglass { + .bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 70px; } @@ -319,6 +315,10 @@ div.tooltip { line-height: 40px; } + #uploaderBattery label { + font-size: 15px !important; + } + .focus-range { margin: 0; } @@ -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 { @@ -442,6 +443,10 @@ div.tooltip { font-size: 15px; } + #uploaderBattery label { + font-size: 15px !important; + } + .alarming .focus-range { display: none; } @@ -508,7 +513,7 @@ div.tooltip { line-height: 80px; } - .bgStatus .currentBG.icon-hourglass { + .bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 70px; } @@ -531,6 +536,10 @@ div.tooltip { font-size: 15px; } + #uploaderBattery label { + font-size: 15px !important; + } + } @media (max-height: 480px) and (max-width: 400px) { @@ -540,7 +549,7 @@ div.tooltip { line-height: 60px; } - .bgStatus .currentBG.icon-hourglass { + .bgStatus .currentBG.bg-limit, .bgStatus .currentBG.icon-hourglass { font-size: 60px; } diff --git a/static/index.html b/static/index.html index 5fab9d6b1..0ff53abe7 100644 --- a/static/index.html +++ b/static/index.html @@ -44,7 +44,8 @@