Skip to content

Commit 1b5fc82

Browse files
Merge branch 'release/0.6.3'
2 parents 8a635e7 + 41ca6b9 commit 1b5fc82

File tree

15 files changed

+819
-469
lines changed

15 files changed

+819
-469
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Use the [autoconfigure tool][autoconfigure] to sync an uploader to your config.
9292

9393
#### Features/Labs
9494

95-
* `ENABLE` - Used to enable optional features, currently supports: `careportal`
95+
* `ENABLE` - Used to enable optional features, expects a space delimited list such as: `careportal rawbg` (also `rawbg-on` to show raw data by default)
9696
* `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
9797
* `BG_HIGH` (`260`) - must be set using mg/dl units; the high BG outside the target range that is considered urgent
9898
* `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

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nightscout",
3-
"version": "0.6.2",
3+
"version": "0.6.3",
44
"dependencies": {
55
"angularjs": "1.3.0-beta.19",
66
"bootstrap": "~3.2.0",

lib/api/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function create (env, entries, settings, treatments, devicestatus) {
2424
}
2525

2626
if (env.enable) {
27+
app.enabledOptions = env.enable || '';
2728
env.enable.toLowerCase().split(' ').forEach(function (value) {
2829
var enable = value.trim();
2930
console.info("enabling feature:", enable);

lib/api/status.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function configure (app, wares) {
1313
var info = { status: 'ok'
1414
, apiEnabled: app.enabled('api')
1515
, careportalEnabled: app.enabled('api') && app.enabled('careportal')
16+
, enabledOptions: app.enabledOptions
1617
, units: app.get('units')
1718
, head: wares.get_head( )
1819
, version: app.get('version')

lib/pebble.js

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ function directionToTrend (direction) {
2020
}
2121

2222
function pebble (req, res) {
23-
var FORTY_MINUTES = 2400000;
24-
var cgmData = [ ];
23+
var ONE_DAY = 24 * 60 * 60 * 1000;
2524
var uploaderBattery;
2625

2726
function requestMetric() {
@@ -42,32 +41,51 @@ function pebble (req, res) {
4241

4342
function get_latest (err, results) {
4443
var now = Date.now();
44+
var sgvData = [ ];
45+
var calData = [ ];
46+
4547
results.forEach(function(element, index, array) {
46-
var next = null;
47-
if (index + 1 < results.length) {
48-
next = results[index + 1];
49-
}
5048
if (element) {
5149
var obj = {};
52-
if (!element.sgv) return;
53-
obj.sgv = scaleBg(element.sgv).toString( );
54-
obj.bgdelta = (next ? (scaleBg(element.sgv) - scaleBg(next.sgv) ) : 0);
55-
if (useMetricBg) {
56-
obj.bgdelta = obj.bgdelta.toFixed(1);
57-
}
58-
if ('direction' in element) {
59-
obj.trend = directionToTrend(element.direction);
60-
obj.direction = element.direction;
50+
if (element.sgv) {
51+
var next = null;
52+
var sgvs = results.filter(function(d) {
53+
return !!d.sgv;
54+
});
55+
if (index + 1 < sgvs.length) {
56+
next = sgvs[index + 1];
57+
}
58+
obj.sgv = scaleBg(element.sgv).toString();
59+
obj.bgdelta = (next ? (scaleBg(element.sgv) - scaleBg(next.sgv) ) : 0);
60+
if (useMetricBg) {
61+
obj.bgdelta = obj.bgdelta.toFixed(1);
62+
}
63+
if ('direction' in element) {
64+
obj.trend = directionToTrend(element.direction);
65+
obj.direction = element.direction;
66+
}
67+
obj.datetime = element.date;
68+
if (req.rawbg) {
69+
obj.filtered = element.filtered;
70+
obj.unfiltered = element.unfiltered;
71+
obj.noise = element.noise;
72+
obj.rssi = element.rssi;
73+
}
74+
// obj.date = element.date.toString( );
75+
sgvData.push(obj);
76+
} else if (req.rawbg && element.type == 'cal') {
77+
calData.push(element);
6178
}
62-
// obj.y = element.sgv;
63-
// obj.x = element.date;
64-
obj.datetime = element.date;
65-
obj.battery = uploaderBattery ? "" + uploaderBattery : undefined;
66-
// obj.date = element.date.toString( );
67-
cgmData.push(obj);
6879
}
6980
});
70-
var result = { status: [ {now:now}], bgs: cgmData.slice(0, 1) };
81+
82+
var count = parseInt(req.query.count) || 1;
83+
84+
var bgs = sgvData.slice(0, count);
85+
//for compatibility we're keeping battery here, but it would be better somewhere else
86+
bgs[0].battery = uploaderBattery ? "" + uploaderBattery : undefined;
87+
88+
var result = { status: [ {now:now}], bgs: bgs, cals: calData.slice(0, count) };
7189
res.setHeader('content-type', 'application/json');
7290
res.write(JSON.stringify(result));
7391
res.end( );
@@ -80,13 +98,16 @@ function pebble (req, res) {
8098
console.error("req.devicestatus.tail", err);
8199
}
82100

83-
req.entries.list({count: 2, find: { "sgv": { $exists: true }}}, get_latest);
101+
var earliest_data = Date.now() - ONE_DAY;
102+
var q = { find: {"date": {"$gte": earliest_data}} };
103+
req.entries.list(q, get_latest);
84104
});
85105
}
86-
function configure (entries, devicestatus) {
106+
function configure (entries, devicestatus, env) {
87107
function middle (req, res, next) {
88108
req.entries = entries;
89109
req.devicestatus = devicestatus;
110+
req.rawbg = env.enable.indexOf('rawbg') > -1;
90111
next( );
91112
}
92113
return [middle, pebble];

lib/treatments.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function storage (collection, storage, pushover) {
3030
if (!obj.glucose) {
3131
delete obj.glucose;
3232
delete obj.glucoseType;
33+
delete obj.units;
3334
}
3435

3536
api( ).insert(obj, function (err, doc) {

lib/websocket.js

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var dir2Char = {
2828
var cgmData = [],
2929
treatmentData = [],
3030
mbgData = [],
31+
calData = [],
3132
patientData = [];
3233

3334
function start ( ) {
@@ -164,7 +165,19 @@ function update() {
164165
obj.d = element.dateString;
165166
obj.device = element.device;
166167
obj.direction = directionToChar(element.direction);
168+
obj.filtered = element.filtered;
169+
obj.unfiltered = element.unfiltered;
170+
obj.noise = element.noise;
171+
obj.rssi = element.rssi;
167172
cgmData.push(obj);
173+
} else if (element.slope) {
174+
var obj = {};
175+
obj.x = element.date;
176+
obj.d = element.dateString;
177+
obj.scale = element.scale;
178+
obj.intercept = element.intercept;
179+
obj.slope = element.slope;
180+
calData.push(obj);
168181
}
169182
}
170183
});
@@ -191,6 +204,7 @@ function loadData() {
191204
actualCurrent,
192205
treatment = [],
193206
mbg = [],
207+
cal = [],
194208
errorCode;
195209

196210
if (cgmData) {
@@ -200,12 +214,6 @@ function loadData() {
200214
});
201215

202216
actualCurrent = actual.length > 0 ? actual[actual.length - 1].y : null;
203-
204-
// sgv less than or equal to 10 means error code
205-
// or warm up period code, so ignore
206-
actual = actual.filter(function (a) {
207-
return a.y > 10;
208-
})
209217
}
210218

211219
if (treatmentData) {
@@ -222,6 +230,13 @@ function loadData() {
222230
});
223231
}
224232

233+
if (calData) {
234+
cal = calData.slice(calData.length-200, calData.length);
235+
cal.sort(function(a, b) {
236+
return a.x - b.x;
237+
});
238+
}
239+
225240
if (actualCurrent && actualCurrent < 39) errorCode = actualCurrent;
226241

227242
var actualLength = actual.length - 1;
@@ -255,8 +270,8 @@ function loadData() {
255270
//TODO: need to consider when data being sent has less than the 2 day minimum
256271

257272
// consolidate and send the data to the client
258-
var shouldEmit = is_different(actual, predicted, mbg, treatment, errorCode);
259-
patientData = [actual, predicted, mbg, treatment, errorCode];
273+
var shouldEmit = is_different(actual, predicted, mbg, treatment, cal);
274+
patientData = [actual, predicted, mbg, treatment, cal];
260275
console.log('patientData', patientData.length);
261276
if (shouldEmit) {
262277
emitData( );
@@ -311,7 +326,7 @@ function loadData() {
311326
}
312327
}
313328

314-
function is_different (actual, predicted, mbg, treatment, errorCode) {
329+
function is_different (actual, predicted, mbg, treatment, cal) {
315330
if (patientData && patientData.length < 3) {
316331
return true;
317332
}
@@ -320,14 +335,14 @@ function loadData() {
320335
, predicted: patientData[1].slice(-1).pop( )
321336
, mbg: patientData[2].slice(-1).pop( )
322337
, treatment: patientData[3].slice(-1).pop( )
323-
, errorCode: patientData.length >= 5 ? patientData[4] : 0
338+
, cal: patientData[4].slice(-1).pop( )
324339
};
325340
var last = {
326341
actual: actual.slice(-1).pop( )
327342
, predicted: predicted.slice(-1).pop( )
328343
, mbg: mbg.slice(-1).pop( )
329344
, treatment: treatment.slice(-1).pop( )
330-
, errorCode: errorCode
345+
, cal: cal.slice(-1).pop( )
331346
};
332347

333348
// textual diff of objects

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Nightscout",
3-
"version": "0.6.2",
3+
"version": "0.6.3",
44
"description": "Nightscout acts as a web-based CGM (Continuous Glucose Montinor) to allow multiple caregivers to remotely view a patients glucose data in realtime.",
55
"license": "AGPL3",
66
"author": "Nightscout Team",

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ app.enable('trust proxy'); // Allows req.secure test on heroku https connections
7171
app.use('/api/v1', api);
7272

7373
// pebble data
74-
app.get('/pebble', pebble(entriesStorage, devicestatusStorage));
74+
app.get('/pebble', pebble(entriesStorage, devicestatusStorage, env));
7575

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

static/css/main.css

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,16 @@ body {
5757
.bgStatus .currentBG {
5858
text-decoration: line-through;
5959
}
60-
.bgStatus .currentDelta {
60+
61+
.bgStatus .currentBG.error-code {
62+
font-size: 80%;
63+
}
64+
65+
.bgStatus .currentBG.bg-limit {
66+
font-size: 80%;
67+
}
68+
69+
.bgStatus .currentDetails {
6170
font-size: 25%;
6271
text-decoration: line-through;
6372
display: block;
@@ -67,7 +76,7 @@ body {
6776
.bgStatus.current .currentBG {
6877
text-decoration: none;
6978
}
70-
.bgStatus.current .currentDelta {
79+
.bgStatus.current .currentDetails {
7180
font-size: 25%;
7281
text-decoration: none;
7382
display: block;
@@ -161,7 +170,6 @@ body {
161170
cursor: default;
162171
font-size: 75%;
163172
margin-top: 15px;
164-
margin-right: 37px;
165173
width: auto;
166174

167175
user-select: none;
@@ -244,11 +252,9 @@ div.tooltip {
244252

245253
.bgStatus {
246254
width: 50%;
255+
font-size: 650%;
247256
}
248257

249-
#bgButton {
250-
font-size: 120%;
251-
}
252258
.dropdown-menu {
253259
font-size: 60% !important;
254260
}
@@ -257,10 +263,7 @@ div.tooltip {
257263
}
258264
}
259265

260-
@media (max-width: 700px) {
261-
#bgButton {
262-
font-size: 120%;
263-
}
266+
@media (max-width: 750px) {
264267
.dropdown-menu {
265268
font-size: 60% !important;
266269
}
@@ -284,10 +287,6 @@ div.tooltip {
284287
font-size: 70%;
285288
}
286289

287-
#notification {
288-
margin-top: 148px;
289-
}
290-
291290
.status {
292291
text-align: center;
293292
margin-bottom: 0;
@@ -307,10 +306,7 @@ div.tooltip {
307306
width: 100vw;
308307
}
309308
#bgButton {
310-
font-size: 120%;
311-
height: 142px;
312-
margin-top: 1vw;
313-
width: 98vw;
309+
font-size: 100%;
314310
}
315311
.dropdown-menu {
316312
font-size: 60% !important;
@@ -327,6 +323,11 @@ div.tooltip {
327323
margin-left: 0;
328324
width: 100%;
329325
}
326+
327+
#container.alarming .time {
328+
display: none;
329+
}
330+
330331
.timebox {
331332
text-align: none;
332333
width: auto;
@@ -365,10 +366,6 @@ div.tooltip {
365366
padding-bottom: 20px;
366367
}
367368

368-
#bgButton {
369-
font-size: 70% !important;
370-
}
371-
372369
#currentTime {
373370
font-size: 85%;
374371
}

0 commit comments

Comments
 (0)