Skip to content

Commit

Permalink
Merge 41ca6b9 into 8a635e7
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncalabrese committed Feb 14, 2015
2 parents 8a635e7 + 41ca6b9 commit 44370b3
Show file tree
Hide file tree
Showing 15 changed files with 819 additions and 469 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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.3",
"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, 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
69 changes: 45 additions & 24 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;

function requestMetric() {
Expand All @@ -42,32 +41,51 @@ 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.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;

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 @@ -80,13 +98,16 @@ function pebble (req, res) {
console.error("req.devicestatus.tail", err);
}

req.entries.list({count: 2, find: { "sgv": { $exists: true }}}, get_latest);
var earliest_data = Date.now() - ONE_DAY;
var q = { find: {"date": {"$gte": earliest_data}} };
req.entries.list(q, get_latest);
});
}
function configure (entries, devicestatus) {
function configure (entries, devicestatus, env) {
function middle (req, res, next) {
req.entries = entries;
req.devicestatus = devicestatus;
req.rawbg = env.enable.indexOf('rawbg') > -1;
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
37 changes: 26 additions & 11 deletions lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var dir2Char = {
var cgmData = [],
treatmentData = [],
mbgData = [],
calData = [],
patientData = [];

function start ( ) {
Expand Down Expand Up @@ -164,7 +165,19 @@ function update() {
obj.d = element.dateString;
obj.device = element.device;
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) {
var obj = {};
obj.x = element.date;
obj.d = element.dateString;
obj.scale = element.scale;
obj.intercept = element.intercept;
obj.slope = element.slope;
calData.push(obj);
}
}
});
Expand All @@ -191,6 +204,7 @@ function loadData() {
actualCurrent,
treatment = [],
mbg = [],
cal = [],
errorCode;

if (cgmData) {
Expand All @@ -200,12 +214,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 > 10;
})
}

if (treatmentData) {
Expand All @@ -222,6 +230,13 @@ function loadData() {
});
}

if (calData) {
cal = calData.slice(calData.length-200, calData.length);
cal.sort(function(a, b) {
return a.x - b.x;
});
}

if (actualCurrent && actualCurrent < 39) errorCode = actualCurrent;

var actualLength = actual.length - 1;
Expand Down Expand Up @@ -255,8 +270,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);
patientData = [actual, predicted, mbg, treatment, errorCode];
var shouldEmit = is_different(actual, predicted, mbg, treatment, cal);
patientData = [actual, predicted, mbg, treatment, cal];
console.log('patientData', patientData.length);
if (shouldEmit) {
emitData( );
Expand Down Expand Up @@ -311,7 +326,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 @@ -320,14 +335,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.3",
"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 @@ -71,7 +71,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, devicestatusStorage));
app.get('/pebble', pebble(entriesStorage, devicestatusStorage, env));

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

Expand Down
41 changes: 19 additions & 22 deletions static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ body {
.bgStatus .currentBG {
text-decoration: line-through;
}
.bgStatus .currentDelta {

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

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

.bgStatus .currentDetails {
font-size: 25%;
text-decoration: line-through;
display: block;
Expand All @@ -67,7 +76,7 @@ body {
.bgStatus.current .currentBG {
text-decoration: none;
}
.bgStatus.current .currentDelta {
.bgStatus.current .currentDetails {
font-size: 25%;
text-decoration: none;
display: block;
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 @@ -307,10 +306,7 @@ div.tooltip {
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 @@ -365,10 +366,6 @@ div.tooltip {
padding-bottom: 20px;
}

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

#currentTime {
font-size: 85%;
}
Expand Down

0 comments on commit 44370b3

Please sign in to comment.