Skip to content

Commit

Permalink
Merge pull request #399 from jasoncalabrese/wip/iob-cob-raw-update
Browse files Browse the repository at this point in the history
Update IOB-COB with raw updates and other changes from dev
  • Loading branch information
jasoncalabrese committed Feb 18, 2015
2 parents fdffde3 + 813cb63 commit 37d74a9
Show file tree
Hide file tree
Showing 15 changed files with 825 additions and 558 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Use the [autoconfigure tool][autoconfigure] to sync an uploader to your config.

#### Features/Labs

* `ENABLE` - Used to enable optional features, currently supports: `careportal`
* `ENABLE` - Used to enable optional features, expects a space delimited list such as: `careportal rawbg` (also `rawbg-on` to show raw data by default)
* `API_SECRET` - A secret passphrase that must be at least 12 characters long, required to enable `POST` and `PUT`; also required for the Care Portal
* `BG_HIGH` (`260`) - must be set using mg/dl units; the high BG outside the target range that is considered urgent
* `BG_TARGET_TOP` (`180`) - must be set using mg/dl units; the top of the target range, also used to draw the line on the chart
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout",
"version": "0.6.2",
"version": "0.6.4",
"dependencies": {
"angularjs": "1.3.0-beta.19",
"bootstrap": "~3.2.0",
Expand Down
1 change: 1 addition & 0 deletions lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function create (env, entries, settings, treatments, profile, devicestatus) {
}

if (env.enable) {
app.enabledOptions = env.enable || '';
env.enable.toLowerCase().split(' ').forEach(function (value) {
var enable = value.trim();
console.info("enabling feature:", enable);
Expand Down
1 change: 1 addition & 0 deletions lib/api/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function configure (app, wares) {
var info = { status: 'ok'
, apiEnabled: app.enabled('api')
, careportalEnabled: app.enabled('api') && app.enabled('careportal')
, enabledOptions: app.enabledOptions
, units: app.get('units')
, head: wares.get_head( )
, version: app.get('version')
Expand Down
72 changes: 46 additions & 26 deletions lib/pebble.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ function directionToTrend (direction) {
}

function pebble (req, res) {
var FORTY_MINUTES = 2400000;
var cgmData = [ ];
var ONE_DAY = 24 * 60 * 60 * 1000;
var uploaderBattery;
var treatmentResults;

Expand All @@ -43,33 +42,52 @@ function pebble (req, res) {

function get_latest (err, results) {
var now = Date.now();
var sgvData = [ ];
var calData = [ ];

results.forEach(function(element, index, array) {
var next = null;
if (index + 1 < results.length) {
next = results[index + 1];
}
if (element) {
var obj = {};
if (!element.sgv) return;
obj.sgv = scaleBg(element.sgv).toString( );
obj.bgdelta = (next ? (scaleBg(element.sgv) - scaleBg(next.sgv) ) : 0);
if (useMetricBg) {
obj.bgdelta = obj.bgdelta.toFixed(1);
}
if ('direction' in element) {
obj.trend = directionToTrend(element.direction);
obj.direction = element.direction;
if (element.sgv) {
var next = null;
var sgvs = results.filter(function(d) {
return !!d.sgv;
});
if (index + 1 < sgvs.length) {
next = sgvs[index + 1];
}
obj.sgv = scaleBg(element.sgv).toString();
obj.bgdelta = (next ? (scaleBg(element.sgv) - scaleBg(next.sgv) ) : 0);
if (useMetricBg) {
obj.bgdelta = obj.bgdelta.toFixed(1);
}
if ('direction' in element) {
obj.trend = directionToTrend(element.direction);
obj.direction = element.direction;
}
obj.datetime = element.date;
if (req.rawbg) {
obj.filtered = element.filtered;
obj.unfiltered = element.unfiltered;
obj.noise = element.noise;
obj.rssi = element.rssi;
}
// obj.date = element.date.toString( );
sgvData.push(obj);
} else if (req.rawbg && element.type == 'cal') {
calData.push(element);
}
// obj.y = element.sgv;
// obj.x = element.date;
obj.datetime = element.date;
obj.battery = uploaderBattery ? "" + uploaderBattery : undefined;
obj.iob = iobTotal(treatmentResults.slice(0, 20), now);
// obj.date = element.date.toString( );
cgmData.push(obj);
}
});
var result = { status: [ {now:now}], bgs: cgmData.slice(0, 1) };

var count = parseInt(req.query.count) || 1;

var bgs = sgvData.slice(0, count);
//for compatibility we're keeping battery here, but it would be better somewhere else
bgs[0].battery = uploaderBattery ? "" + uploaderBattery : undefined;
bgs[0].iob = iobTotal(treatmentResults.slice(0, 20), now);

var result = { status: [ {now:now}], bgs: bgs, cals: calData.slice(0, count) };
res.setHeader('content-type', 'application/json');
res.write(JSON.stringify(result));
res.end( );
Expand All @@ -82,20 +100,22 @@ function pebble (req, res) {
console.error("req.devicestatus.tail", err);
}

var earliest_data = Date.now() - (5 * 3600000);
var earliest_data = Date.now() - ONE_DAY;
var q = { find: {"date": {"$gte": earliest_data}} };
var tq = { find: {"created_at": {"$gte": new Date(earliest_data).toISOString()}} };
req.treatments.list(tq, function (err, trs) {
treatmentResults = trs;
req.entries.list({count: 2, find: { "sgv": { $exists: true }}}, get_latest);
req.entries.list(q, get_latest);
});
});
}

function configure (entries, treatments, devicestatus) {
function configure (entries, treatments, devicestatus, env) {
function middle (req, res, next) {
req.entries = entries;
req.treatments = treatments;
req.devicestatus = devicestatus;
req.rawbg = true;
next( );
}
return [middle, pebble];
Expand Down
1 change: 1 addition & 0 deletions lib/treatments.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function storage (collection, storage, pushover) {
if (!obj.glucose) {
delete obj.glucose;
delete obj.glucoseType;
delete obj.units;
}

api( ).insert(obj, function (err, doc) {
Expand Down
21 changes: 9 additions & 12 deletions lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var ONE_HOUR = 3600000,
ONE_MINUTE = 60000,
FIVE_MINUTES = 300000,
FORTY_MINUTES = 2400000,
ONE_DAY = 86400000;
ONE_DAY = 86400000,
TWO_DAYS = 172800000;

var dataRange = 4 * ONE_DAY;

Expand Down Expand Up @@ -57,6 +58,7 @@ var dir2Char = {
// reduce logging
io.set('log level', 0);

//TODO: make websockets support an option
io.configure(function () {
io.set('transports', ['xhr-polling']);
});
Expand Down Expand Up @@ -172,6 +174,7 @@ function update() {
obj.direction = directionToChar(element.direction);
obj.filtered = element.filtered;
obj.unfiltered = element.unfiltered;
obj.noise = element.noise;
obj.rssi = element.rssi;
cgmData.push(obj);
} else if (element.slope) {
Expand Down Expand Up @@ -229,12 +232,6 @@ function loadData() {
});

actualCurrent = actual.length > 0 ? actual[actual.length - 1].y : null;

// sgv less than or equal to 10 means error code
// or warm up period code, so ignore
actual = actual.filter(function (a) {
return (a.y > 39 || a.unfiltered > 0) ;
})
}

if (treatmentData) {
Expand Down Expand Up @@ -297,8 +294,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, errorCode, profile, cal);
patientData = [actual, predicted, mbg, treatment, errorCode, profile, cal];
var shouldEmit = is_different(actual, predicted, mbg, treatment, cal);
patientData = [actual, predicted, mbg, treatment, profile, cal];
console.log('patientData', patientData.length);
if (shouldEmit) {
emitData( );
Expand Down Expand Up @@ -353,7 +350,7 @@ function loadData() {
}
}

function is_different (actual, predicted, mbg, treatment, errorCode) {
function is_different (actual, predicted, mbg, treatment, cal) {
if (patientData && patientData.length < 3) {
return true;
}
Expand All @@ -362,14 +359,14 @@ function loadData() {
, predicted: patientData[1].slice(-1).pop( )
, mbg: patientData[2].slice(-1).pop( )
, treatment: patientData[3].slice(-1).pop( )
, errorCode: patientData.length >= 5 ? patientData[4] : 0
, cal: patientData[4].slice(-1).pop( )
};
var last = {
actual: actual.slice(-1).pop( )
, predicted: predicted.slice(-1).pop( )
, mbg: mbg.slice(-1).pop( )
, treatment: treatment.slice(-1).pop( )
, errorCode: errorCode
, cal: cal.slice(-1).pop( )
};

// textual diff of objects
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Nightscout",
"version": "0.6.2",
"version": "0.6.4",
"description": "Nightscout acts as a web-based CGM (Continuous Glucose Montinor) to allow multiple caregivers to remotely view a patients glucose data in realtime.",
"license": "AGPL3",
"author": "Nightscout Team",
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ app.enable('trust proxy'); // Allows req.secure test on heroku https connections
app.use('/api/v1', api);

// pebble data
app.get('/pebble', pebble(entriesStorage, treatmentsStorage, devicestatusStorage));
app.get('/pebble', pebble(entriesStorage, treatmentsStorage, devicestatusStorage, env));

//app.get('/package.json', software);

Expand Down
56 changes: 33 additions & 23 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ body {
.bgStatus .currentBG {
text-decoration: line-through;
}

.bgStatus .currentBG.error-code {
font-size: 80%;
}

.bgStatus .currentBG.bg-limit {
font-size: 80%;
}

.bgStatus .currentDetails {
font-size: 25%;
text-decoration: line-through;
Expand Down Expand Up @@ -161,7 +170,6 @@ body {
cursor: default;
font-size: 75%;
margin-top: 15px;
margin-right: 37px;
width: auto;

user-select: none;
Expand Down Expand Up @@ -244,11 +252,9 @@ div.tooltip {

.bgStatus {
width: 50%;
font-size: 650%;
}

#bgButton {
font-size: 120%;
}
.dropdown-menu {
font-size: 60% !important;
}
Expand All @@ -257,10 +263,7 @@ div.tooltip {
}
}

@media (max-width: 700px) {
#bgButton {
font-size: 120%;
}
@media (max-width: 750px) {
.dropdown-menu {
font-size: 60% !important;
}
Expand All @@ -284,10 +287,6 @@ div.tooltip {
font-size: 70%;
}

#notification {
margin-top: 148px;
}

.status {
text-align: center;
margin-bottom: 0;
Expand All @@ -299,18 +298,15 @@ div.tooltip {
#bgButton {display:block;} */

.bgStatus {
font-size: 750%;
font-size: 700%;
float: none;
margin: 0 auto;
padding: 0;
padding: 20px 0 0 0;
text-align: center;
width: 100vw;
}
#bgButton {
font-size: 120%;
height: 142px;
margin-top: 1vw;
width: 98vw;
font-size: 100%;
}
.dropdown-menu {
font-size: 60% !important;
Expand All @@ -327,6 +323,11 @@ div.tooltip {
margin-left: 0;
width: 100%;
}

#container.alarming .time {
display: none;
}

.timebox {
text-align: none;
width: auto;
Expand Down Expand Up @@ -370,16 +371,12 @@ div.tooltip {
padding-bottom: 20px;
}

#bgButton {
font-size: 70% !important;
}

#currentTime {
font-size: 85%;
}

#chartContainer {
top: 130px;
top: 140px;
font-size: 80%;
}
#chartContainer svg {
Expand All @@ -391,10 +388,23 @@ div.tooltip {
.container .status {
font-size: 70%;
}

.bgStatus {
padding-top: 20px;
}

}

@media (max-height: 480px) and (max-width: 400px) {
.container .status {
font-size: 80% !important;
}
}

@media (min-height: 480px) and (max-width: 400px) {
#toolbar #iob-cob h1 {
left: 60px;
right: auto;
position: relative;
}
}

0 comments on commit 37d74a9

Please sign in to comment.