-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
Remove Jellyfish (UPLOAD-1, UPLOAD-1399) #1599
base: master
Are you sure you want to change the base?
Changes from 59 commits
119e856
697acf6
c33d91d
19927eb
39085e0
a6242b4
0fed1a2
cff3376
3b582bc
723b1af
0075985
cbe7f87
415418e
f36a705
952c2a8
a871728
6954de5
12c8803
ac6be98
0fd3fe9
2dd9436
381b68a
6f6213f
7fcb40f
6f00437
13ecb5b
c528c8c
bca5b19
152ac43
482a529
09e7b36
5af7457
01a6c6f
717f2a7
a1f014f
c1c267c
f5e16ce
e582910
8819fae
cf107b8
d1eddbb
d51bc5c
fce7888
27dee49
357437b
c6ec73a
7c6871e
a7167a5
5d7cfb3
0d8b379
d6c3af7
81d7817
f8501ca
9f687c8
226e492
7c02d34
c3a1274
37c2e1f
667d594
df02a50
f79f6c1
7d6b959
4540826
d35882b
9f97bc6
633f019
f0454b6
ebcf82d
2c29b51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ var annotate = require('./eventAnnotations'); | |
var api = require('./core/api.js'); | ||
var rollbar =require('../app/utils/rollbar'); | ||
var isBrowser = typeof window !== 'undefined'; | ||
var moment = require('moment'); | ||
var _ = require('lodash'); | ||
|
||
var GLUCOSE_MM = 18.01559; | ||
|
||
|
@@ -177,3 +177,129 @@ exports.addDurationToDeviceTime = function (event, duration) { | |
}; | ||
|
||
exports.fixFloatingPoint = (n) => Math.floor(n * 100 + 0.5) / 100; | ||
|
||
Number.prototype.toFixedNumber = function(significant){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's not exported but is there a test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test. |
||
var pow = Math.pow(10,significant); | ||
return +( Math.round(this*pow) / pow ); | ||
}; | ||
|
||
exports.updateDuration = function(event, lastEvent) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a corresponding test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a test. |
||
|
||
const withAnnotation = function(event) { | ||
if(_.find(event.annotations || [], function(ann) { | ||
return ann.code === 'final-basal/fabricated-from-schedule' || | ||
ann.code === 'basal/unknown-duration' || | ||
ann.code === 'status/incomplete-tuple' || | ||
ann.code === 'bolus/extended-in-progress' || | ||
ann.code === 'tandem/pumpSettingsOverride/estimated-duration'; | ||
})) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
let updatedDuration = Date.parse(event.time) - Date.parse(lastEvent.time); | ||
|
||
if (event.extended && event.duration) { | ||
// for extended boluses we don't have to calculate the duration | ||
updatedDuration = event.duration; | ||
} | ||
|
||
if (updatedDuration >= 0) { | ||
debug('Updating duration of last event from previous upload'); | ||
if((lastEvent.subType !== 'pumpSettingsOverride') && lastEvent.duration > 0) { | ||
lastEvent.expectedDuration = lastEvent.duration; | ||
} | ||
lastEvent.duration = updatedDuration; | ||
|
||
if (withAnnotation(lastEvent)) { | ||
// if the event was previously annotated because of the missing event, | ||
// we can now remove the annotations | ||
lastEvent = _.omit(lastEvent, 'annotations'); | ||
} | ||
|
||
return lastEvent; | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
exports.stripUnwantedFields = function(record) { | ||
debugger; | ||
const stripped = _.omit(record, | ||
'createdTime', 'id', 'guid', 'modifiedTime', 'revision', 'uploadId', | ||
'_active', '_deduplicator', '_id', '_schemaVersion', '_userId', | ||
); | ||
|
||
debug(`Last ${stripped.type} (${stripped.subType || stripped.deliveryType}) from previous upload was: ${JSON.stringify(stripped, null, 4)}`); | ||
return stripped; | ||
}; | ||
|
||
exports.updatePreviousDurations = async function(data, cfg, cb) { | ||
|
||
|
||
try { | ||
// update last basal | ||
const lastBasal = this.stripUnwantedFields(await api.getLatestRecord(cfg.groupId, cfg.deviceInfo.deviceId, 'basal')); | ||
let datum = _.find(data.post_records, {type: 'basal'}); | ||
if (datum != null) { | ||
const updatedBasal = this.updateDuration(datum, lastBasal); | ||
if (updatedBasal) { | ||
data.post_records.push(updatedBasal); | ||
} | ||
} | ||
|
||
// update last suspend event | ||
if (lastBasal.deliveryType === 'suspend') { | ||
const lastDeviceEvent = this.stripUnwantedFields(await api.getLatestRecord(cfg.groupId, cfg.deviceInfo.deviceId, 'deviceEvent', 'status')); | ||
if (lastDeviceEvent.subType === 'status') { | ||
const index = _.findIndex(data.post_records, {type: 'deviceEvent', subType: 'status'}); | ||
datum = data.post_records[index]; | ||
|
||
if (index > -1) { | ||
const updatedStatus = this.updateDuration(datum, lastDeviceEvent); | ||
|
||
if (updatedStatus) { | ||
updatedStatus.reason.resumed = datum.reason.resumed; | ||
|
||
if (lastDeviceEvent.payload && lastDeviceEvent.payload.reason != null) { | ||
updatedStatus.payload.suspended = lastDeviceEvent.payload.reason; | ||
delete updatedStatus.payload.reason; | ||
} | ||
if (datum.payload && datum.payload.reason != null) { | ||
updatedStatus.payload.resumed = datum.payload.reason; | ||
} | ||
|
||
data.post_records.push(updatedStatus); | ||
data.post_records.splice(index, 1); // remove resume event that is now combined | ||
} | ||
} | ||
} | ||
} | ||
|
||
// update last pump settings override | ||
const lastPumpSettingsOverride = this.stripUnwantedFields(await api.getLatestRecord(cfg.groupId, cfg.deviceInfo.deviceId, 'deviceEvent', 'pumpSettingsOverride')); | ||
|
||
if (annotate.isAnnotated(lastPumpSettingsOverride, 'tandem/pumpSettingsOverride/estimated-duration')) { | ||
const index = _.findIndex(data.post_records, {type: 'deviceEvent', subType: 'pumpSettingsOverride'}); | ||
datum = data.post_records[index]; | ||
if (datum != null) { | ||
const updatedOverride = this.updateDuration(datum, lastPumpSettingsOverride); | ||
if (updatedOverride) { | ||
data.post_records.push(updatedOverride); | ||
} else { | ||
debug('Not updating pump settings override as duration could not be calculated'); | ||
} | ||
if (datum.overrideType === 'normal') { | ||
// remove override active at beginning that was stopped | ||
data.post_records.splice(index, 1); | ||
} | ||
} else { | ||
debug('Pump settings override should still be active'); | ||
} | ||
} | ||
return cb (null, data); | ||
} catch (error) { | ||
return cb (error); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it appears we aren't doing anything with the
err
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is an error we already dispatch an error message in
fetchInfo
itself, so I'll just log it to the console.