Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #13

Merged
merged 13 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
* Remove unnecessary logging to help with Papertrail limits
* Load more treatments and entries to fix caching issues (need to add better cache invalidation to really fix this)
  • Loading branch information
sulkaharo committed Sep 15, 2020
commit 5f0b77bc210a97a2199416a204f9b723eb151a66
4 changes: 3 additions & 1 deletion lib/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
"MMOL_TO_MGDL": 18,
"ONE_DAY" : 86400000,
"TWO_DAYS" : 172800000,
"FIFTEEN_MINUTES": 900000
"FIFTEEN_MINUTES": 900000,
"THREE_HOURS": 10800000,
"ONE_HOUR": 3600000
}
4 changes: 2 additions & 2 deletions lib/data/dataloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function init(env, ctx) {
function loadEntries(ddata, ctx, callback) {

const withFrame = ddata.page && ddata.page.frame;
const loadPeriod = ddata.sgvs && ddata.sgvs.length > 0 && !withFrame ? constants.FIFTEEN_MINUTES : constants.TWO_DAYS;
const loadPeriod = ddata.sgvs && ddata.sgvs.length > 0 && !withFrame ? constants.ONE_HOUR : constants.TWO_DAYS;
const latestEntry = ddata.sgvs && ddata.sgvs.length > 0 ? findLatestMills(ddata.sgvs) : ddata.lastUpdated;

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

const loadPeriod = ddata.treatments && ddata.treatments.length > 0 && !withFrame ? constants.FIFTEEN_MINUTES : longLoad;
const loadPeriod = ddata.treatments && ddata.treatments.length > 0 && !withFrame ? constants.THREE_HOURS : longLoad;
const latestEntry = ddata.treatments && ddata.treatments.length > 0 ? findLatestMills(ddata.treatments) : ddata.lastUpdated;
const loadTime = Math.min(ddata.lastUpdated - loadPeriod, latestEntry);

Expand Down
16 changes: 8 additions & 8 deletions lib/server/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ function init (env, ctx, server) {

function emitData (delta) {
if (lastData.cals) {
console.log(LOG_WS + 'running websocket.emitData', ctx.ddata.lastUpdated);
// console.log(LOG_WS + 'running websocket.emitData', ctx.ddata.lastUpdated);
if (lastProfileSwitch !== ctx.ddata.lastProfileFromSwitch) {
console.log(LOG_WS + 'profile switch detected OLD: ' + lastProfileSwitch + ' NEW: ' + ctx.ddata.lastProfileFromSwitch);
// console.log(LOG_WS + 'profile switch detected OLD: ' + lastProfileSwitch + ' NEW: ' + ctx.ddata.lastProfileFromSwitch);
delta.status = status(ctx.ddata.profiles);
lastProfileSwitch = ctx.ddata.lastProfileFromSwitch;
}
Expand Down Expand Up @@ -457,7 +457,7 @@ function init (env, ctx, server) {
socket.emit('dataUpdate', data);
}
}
console.log(LOG_WS + 'Authetication ID: ', socket.client.id, ' client: ', clientType, ' history: ' + history);
// console.log(LOG_WS + 'Authetication ID: ', socket.client.id, ' client: ', clientType, ' history: ' + history);
if (callback) {
callback(socketAuthorization);
}
Expand All @@ -471,7 +471,7 @@ function init (env, ctx, server) {
socket.on('nsping', function ping (message, callback) {
var clientTime = message.mills;
timeDiff = new Date().getTime() - clientTime;
console.log(LOG_WS + 'Ping from client ID: ',socket.client.id, ' client: ', clientType, ' timeDiff: ', (timeDiff/1000).toFixed(1) + 'sec');
// console.log(LOG_WS + 'Ping from client ID: ',socket.client.id, ' client: ', clientType, ' timeDiff: ', (timeDiff/1000).toFixed(1) + 'sec');
if (callback) {
callback({ result: 'pong', mills: new Date().getTime(), authorization: socketAuthorization });
}
Expand All @@ -480,14 +480,14 @@ function init (env, ctx, server) {
}

websocket.update = function update ( ) {
console.log(LOG_WS + 'running websocket.update');
// console.log(LOG_WS + 'running websocket.update');
if (lastData.sgvs) {
var delta = calcData(lastData, ctx.ddata);
if (delta.delta) {
console.log('lastData full size', JSON.stringify(lastData).length,'bytes');
if (delta.sgvs) { console.log('patientData update size', JSON.stringify(delta).length,'bytes'); }
// console.log('lastData full size', JSON.stringify(lastData).length,'bytes');
// if (delta.sgvs) { console.log('patientData update size', JSON.stringify(delta).length,'bytes'); }
emitData(delta);
} else { console.log('delta calculation indicates no new data is present'); }
}; // else { console.log('delta calculation indicates no new data is present'); }
}
lastData = ctx.ddata.clone();
};
Expand Down