Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92f23e6

Browse files
authored
Merge pull request nightscout#6004 from nightscout/dev
Release 14.0.2
2 parents 4f85e19 + fbe3e9b commit 92f23e6

File tree

9 files changed

+76
-36
lines changed

9 files changed

+76
-36
lines changed

app.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,22 @@ function create (env, ctx) {
9696
app.set('view engine', 'ejs');
9797
// this allows you to render .html files as templates in addition to .ejs
9898
app.engine('html', require('ejs').renderFile);
99-
app.engine('appcache', require('ejs').renderFile);
10099
app.set("views", path.join(__dirname, "views/"));
101100

102101
let cacheBuster = 'developmentMode';
102+
let lastModified = new Date();
103+
let busterPath = '/tmp/cacheBusterToken';
104+
103105
if (process.env.NODE_ENV !== 'development') {
104-
if (fs.existsSync(process.cwd() + '/tmp/cacheBusterToken')) {
105-
cacheBuster = fs.readFileSync(process.cwd() + '/tmp/cacheBusterToken').toString().trim();
106-
} else {
107-
cacheBuster = fs.readFileSync(__dirname + '/tmp/cacheBusterToken').toString().trim();
108-
}
106+
busterPath = process.cwd() + busterPath;
107+
} else {
108+
busterPath = __dirname + busterPath;
109+
}
110+
111+
if (fs.existsSync(busterPath)) {
112+
cacheBuster = fs.readFileSync(busterPath).toString().trim();
113+
var stats = fs.statSync(busterPath);
114+
lastModified = stats.mtime;
109115
}
110116
app.locals.cachebuster = cacheBuster;
111117

@@ -116,6 +122,9 @@ function create (env, ctx) {
116122

117123
app.get("/sw.js", (req, res) => {
118124
res.setHeader('Content-Type', 'application/javascript');
125+
if (process.env.NODE_ENV !== 'development') {
126+
res.setHeader('Last-Modified', lastModified.toUTCString());
127+
}
119128
res.send(ejs.render(fs.readFileSync(
120129
require.resolve(`${__dirname}/views/service-worker.js`),
121130
{ encoding: 'utf-8' }),
@@ -268,10 +277,6 @@ function create (env, ctx) {
268277
if (process.env.NODE_ENV === 'development') {
269278
maxAge = 1;
270279
console.log('Development environment detected, setting static file cache age to 1 second');
271-
272-
app.get('/nightscout.appcache', function(req, res) {
273-
res.sendStatus(404);
274-
});
275280
}
276281

277282
var staticFiles = express.static(env.static_files, {

lib/client/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var levels = require('../levels');
1515
var times = require('../times');
1616
var receiveDData = require('./receiveddata');
1717

18+
var brushing = false;
19+
1820
var client = {};
1921

2022
$('#loadingMessageText').html('Connecting to server');
@@ -421,6 +423,12 @@ client.load = function load (serverSettings, callback) {
421423
return;
422424
}
423425

426+
if (brushing) {
427+
return;
428+
}
429+
430+
brushing = true;
431+
424432
// default to most recent focus period
425433
var brushExtent = client.dataExtent();
426434
brushExtent[0] = new Date(brushExtent[1].getTime() - client.focusRangeMS);
@@ -605,6 +613,8 @@ client.load = function load (serverSettings, callback) {
605613
var top = (client.bottomOfPills() + 5);
606614
$('#chartContainer').css({ top: top + 'px', height: $(window).height() - top - 10 });
607615
container.removeClass('loading');
616+
617+
brushing = false;
608618
}
609619

610620
function sgvToColor (sgv) {

lib/constants.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@
99
"MMOL_TO_MGDL": 18,
1010
"ONE_DAY" : 86400000,
1111
"TWO_DAYS" : 172800000,
12-
"FIFTEEN_MINUTES": 900000
12+
"FIFTEEN_MINUTES": 900000,
13+
"THIRTY_MINUTES": 1800000,
14+
"ONE_HOUR": 3600000,
15+
"THREE_HOURS": 10800000,
16+
"FOUR_HOURS": 14400000,
17+
"SIX_HOURS": 21600000
1318
}

lib/data/dataloader.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,38 @@ const findLatestMills = (data) => {
3838

3939
function mergeProcessSort(oldData, newData, ageLimit) {
4040

41-
processForRuntime(newData);
41+
processForRuntime(newData);
4242

4343
var filtered = _.filter(newData, function hasId(object) {
4444
const hasId = !_.isEmpty(object._id);
4545
const isFresh = (ageLimit && object.mills >= ageLimit) || (!ageLimit);
4646
return isFresh && hasId;
4747
});
4848

49-
const merged = _.unionWith(oldData, filtered, function(a, b) {
50-
return a._id == b._id;
51-
});
49+
// Merge old and new data, preferring the new objects
50+
51+
let merged = [];
52+
if (oldData && filtered) {
53+
merged = filtered; // Start with the new / updated data
54+
for (let i = 0; i < oldData.length; i++) {
55+
const oldElement = oldData[i];
56+
let found = false;
57+
for (let j = 0; j < filtered.length; j++) {
58+
if (oldElement._id == filtered[j]._id) {
59+
found = true;
60+
break;
61+
}
62+
}
63+
if (!found) merged.push(oldElement); // Merge old object in, if it wasn't found in the new data
64+
}
65+
} else {
66+
merged = filtered;
67+
}
5268

5369
return _.sortBy(merged, function(item) {
5470
return item.mills;
5571
});
72+
5673
}
5774

5875
function init(env, ctx) {
@@ -78,13 +95,17 @@ function init(env, ctx) {
7895
}
7996
ddata.lastUpdated = opts.lastUpdated;
8097

81-
const convertIds = (obj) => {
98+
const normalizeTreatments = (obj) => {
8299
Object.keys(obj).forEach(key => {
83100
if (typeof obj[key] === 'object' && obj[key]) {
84-
if (obj[key].hasOwnProperty('_id')) {
85-
obj[key]._id = obj[key]._id.toString();
101+
const element = obj[key];
102+
if (element.hasOwnProperty('_id')) {
103+
element._id = element._id.toString();
104+
}
105+
if (element.hasOwnProperty('amount') && !element.hasOwnProperty('absolute')) {
106+
element.absolute = Number(element.amount);
86107
}
87-
convertIds(obj[key]);
108+
normalizeTreatments(obj[key]);
88109
}
89110
});
90111
}
@@ -93,18 +114,17 @@ function init(env, ctx) {
93114

94115
// convert all IDs to strings, as these are not used after load
95116

96-
convertIds(ddata);
117+
normalizeTreatments(ddata);
97118

98119
ddata.treatments = _.uniq(ddata.treatments, false, function(item) {
99120
return item._id;
100121
});
101122

102123
//sort treatments so the last is the most recent
103-
/*
124+
104125
ddata.treatments = _.sortBy(ddata.treatments, function(item) {
105126
return item.mills;
106127
});
107-
*/
108128

109129
fitTreatmentsToBGCurve(ddata, env, ctx);
110130
if (err) {
@@ -150,7 +170,7 @@ function init(env, ctx) {
150170
function loadEntries(ddata, ctx, callback) {
151171

152172
const withFrame = ddata.page && ddata.page.frame;
153-
const loadPeriod = ddata.sgvs && ddata.sgvs.length > 0 && !withFrame ? constants.FIFTEEN_MINUTES : constants.TWO_DAYS;
173+
const loadPeriod = ddata.sgvs && ddata.sgvs.length > 0 && !withFrame ? constants.ONE_HOUR : constants.TWO_DAYS;
154174
const latestEntry = ddata.sgvs && ddata.sgvs.length > 0 ? findLatestMills(ddata.sgvs)ddata.lastUpdated;
155175

156176
var dateRange = {
@@ -289,7 +309,7 @@ function loadTreatments(ddata, ctx, callback) {
289309
// Load 2.5 days to cover last 48 hours including overlapping temp boluses or temp targets for first load
290310
// Subsequently load at least 15 minutes of data, but if latest entry is older than 15 minutes, load until that entry
291311

292-
const loadPeriod = ddata.treatments && ddata.treatments.length > 0 && !withFrame ? constants.FIFTEEN_MINUTES : longLoad;
312+
const loadPeriod = ddata.treatments && ddata.treatments.length > 0 && !withFrame ? constants.SIX_HOURS : longLoad;
293313
const latestEntry = ddata.treatments && ddata.treatments.length > 0 ? findLatestMills(ddata.treatments)ddata.lastUpdated;
294314
const loadTime = Math.min(ddata.lastUpdated - loadPeriod, latestEntry);
295315

lib/server/websocket.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ function init (env, ctx, server) {
103103

104104
function emitData (delta) {
105105
if (lastData.cals) {
106-
console.log(LOG_WS + 'running websocket.emitData', ctx.ddata.lastUpdated);
106+
// console.log(LOG_WS + 'running websocket.emitData', ctx.ddata.lastUpdated);
107107
if (lastProfileSwitch !== ctx.ddata.lastProfileFromSwitch) {
108-
console.log(LOG_WS + 'profile switch detected OLD: ' + lastProfileSwitch + ' NEW: ' + ctx.ddata.lastProfileFromSwitch);
108+
// console.log(LOG_WS + 'profile switch detected OLD: ' + lastProfileSwitch + ' NEW: ' + ctx.ddata.lastProfileFromSwitch);
109109
delta.status = status(ctx.ddata.profiles);
110110
lastProfileSwitch = ctx.ddata.lastProfileFromSwitch;
111111
}
@@ -457,7 +457,7 @@ function init (env, ctx, server) {
457457
socket.emit('dataUpdate', data);
458458
}
459459
}
460-
console.log(LOG_WS + 'Authetication ID: ', socket.client.id, ' client: ', clientType, ' history: ' + history);
460+
// console.log(LOG_WS + 'Authetication ID: ', socket.client.id, ' client: ', clientType, ' history: ' + history);
461461
if (callback) {
462462
callback(socketAuthorization);
463463
}
@@ -471,7 +471,7 @@ function init (env, ctx, server) {
471471
socket.on('nsping', function ping (message, callback) {
472472
var clientTime = message.mills;
473473
timeDiff = new Date().getTime() - clientTime;
474-
console.log(LOG_WS + 'Ping from client ID: ',socket.client.id, ' client: ', clientType, ' timeDiff: ', (timeDiff/1000).toFixed(1) + 'sec');
474+
// console.log(LOG_WS + 'Ping from client ID: ',socket.client.id, ' client: ', clientType, ' timeDiff: ', (timeDiff/1000).toFixed(1) + 'sec');
475475
if (callback) {
476476
callback({ result: 'pong', mills: new Date().getTime(), authorization: socketAuthorization });
477477
}
@@ -480,14 +480,14 @@ function init (env, ctx, server) {
480480
}
481481

482482
websocket.update = function update ( ) {
483-
console.log(LOG_WS + 'running websocket.update');
483+
// console.log(LOG_WS + 'running websocket.update');
484484
if (lastData.sgvs) {
485485
var delta = calcData(lastData, ctx.ddata);
486486
if (delta.delta) {
487-
console.log('lastData full size', JSON.stringify(lastData).length,'bytes');
488-
if (delta.sgvs) { console.log('patientData update size', JSON.stringify(delta).length,'bytes'); }
487+
// console.log('lastData full size', JSON.stringify(lastData).length,'bytes');
488+
// if (delta.sgvs) { console.log('patientData update size', JSON.stringify(delta).length,'bytes'); }
489489
emitData(delta);
490-
} else { console.log('delta calculation indicates no new data is present'); }
490+
}; // else { console.log('delta calculation indicates no new data is present'); }
491491
}
492492
lastData = ctx.ddata.clone();
493493
};

npm-shrinkwrap.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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": "14.0.1",
3+
"version": "14.0.2",
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": "AGPL-3.0",
66
"author": "Nightscout Team",

swagger.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"info": {
99
"title": "Nightscout API",
1010
"description": "Own your DData with the Nightscout API",
11-
"version": "14.0.1",
11+
"version": "14.0.2",
1212
"license": {
1313
"name": "AGPL 3",
1414
"url": "https://www.gnu.org/licenses/agpl.txt"

swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ servers:
44
info:
55
title: Nightscout API
66
description: Own your DData with the Nightscout API
7-
version: 14.0.1
7+
version: 14.0.2
88
license:
99
name: AGPL 3
1010
url: 'https://www.gnu.org/licenses/agpl.txt'

0 commit comments

Comments
 (0)