Skip to content

Commit

Permalink
display uploader battery next to time ago
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Mar 16, 2015
1 parent b73aec7 commit 647dec2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
18 changes: 14 additions & 4 deletions lib/websocket.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -31,7 +31,8 @@ var dir2Char = {
mbgData = [],
calData = [],
profileData = [],
patientData = [];
patientData = [],
devicestatusData = {};

function start ( ) {
io = require('socket.io').listen(server, {
Expand Down Expand Up @@ -154,6 +155,7 @@ function update() {
treatmentData = [];
mbgData = [];
profileData = [];
devicestatusData = {};
var earliest_data = now - TWO_DAYS;

async.parallel({
Expand Down Expand Up @@ -228,6 +230,14 @@ function update() {
callback();
});
}
, devicestatus: function(callback) {
devicestatus.last(function (err, result) {
devicestatusData = {
uploaderBattery: result.uploaderBattery
};
callback();
})
}
}, loadData);

return update;
Expand Down Expand Up @@ -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( );
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

///////////////////////////////////////////////////
16 changes: 8 additions & 8 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ <h1 class="customTitle">Nightscout</h1>
<div class="timebox">
<div id="currentTime">---</div>
<div class="timeOther">
<span id="lastEntry" class="pill"><em>-</em><label></label></span>
<span id="lastEntry" class="pill"><em></em><label></label></span>
<span id="uploaderBattery" class="pill"><em></em><label class="icon-battery-100"></label></span>
</div>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions static/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit 647dec2

Please sign in to comment.