Skip to content

Commit

Permalink
Store more CareLink fields, activeInsulin -> iob
Browse files Browse the repository at this point in the history
  • Loading branch information
mddub committed Oct 21, 2015
1 parent b6d0b17 commit 16d9dfe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
12 changes: 3 additions & 9 deletions test/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ var makeSGs = module.exports.makeSGs = function(count) {

var data = module.exports.data = function(overrides) {
overrides = overrides || {};
var sgs = makeSGs(288);
return extend(true, {
"sgs" : makeSGs(300),
"sgs" : sgs,
"lastSG" : sgs[sgs.length - 1],
"conduitSerialNumber" : "0",
"conduitMedicalDeviceInRange" : true,
"version" : 1,
Expand Down Expand Up @@ -56,14 +58,6 @@ var data = module.exports.data = function(overrides) {
"lastConduitTime" : 0,
"medicalDeviceBatteryLevelPercent" : 100,
"reservoirLevelPercent" : 50,
// We don't look at this; otherwise it should match "sgs"
"lastSG" : {
"kind" : "SG",
"datetime" : "Oct 17, 2015 09:08:00",
"version" : 1,
"timeChange" : false,
"sg" : 180
},
"lastSensorTSAsString" : "Oct 17, 2015 09:08:00",
"lastName" : "<redacted>",
"activeInsulin" : {
Expand Down
26 changes: 26 additions & 0 deletions test/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,30 @@ describe('transform()', function() {
).length
).to.be(0);
});

it('should include active insulin as "iob"', function() {
var pumpStatus = transform(
f.data({'activeInsulin': {
'datetime' : 'Oct 17, 2015 09:09:14',
'version' : 1,
'amount' : 1.275,
'kind' : 'Insulin'
}})
).filter(function(e) { return e['type'] === 'pump_status'; })[0];

expect(pumpStatus['iob']).to.be(1.275);
});

it('should ignore activeInsulin values of -1', function() {
var pumpStatus = transform(
f.data({'activeInsulin': {
'datetime' : 'Oct 17, 2015 09:09:14',
'version' : 1,
'amount' : -1,
'kind' : 'Insulin'
}})
).filter(function(e) { return e['type'] === 'pump_status'; })[0];

expect(pumpStatus['iob']).to.be(undefined);
});
});
17 changes: 14 additions & 3 deletions transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,32 @@ var guessPumpOffset = (function() {
function pumpStatusEntry(data) {
var entry = {'type': PUMP_STATUS_ENTRY_TYPE};

// For the values these can take, see:
// https://gist.github.com/mddub/5e4a585508c93249eb51
[
'conduitBatteryLevel',
// booleans
'conduitInRange',
'conduitMedicalDeviceInRange',
'conduitSensorInRange',
'medicalDeviceSuspended',
// numbers
'conduitBatteryLevel',
'reservoirLevelPercent',
'reservoirAmount',
'medicalDeviceBatteryLevelPercent'
'medicalDeviceBatteryLevelPercent',
'sensorDurationHours',
'timeToNextCalibHours',
// strings
'sensorState',
'calibStatus'
].forEach(function(key) {
if(data[key] !== undefined) {
entry[key] = data[key];
}
});

if(data['activeInsulin'] && data['activeInsulin']['amount'] >= 0) {
entry['activeInsulin'] = data['activeInsulin']['amount'];
entry['iob'] = data['activeInsulin']['amount'];
}

return addTimeToEntry(data['lastMedicalDeviceDataUpdateServerTime'], entry);
Expand Down

0 comments on commit 16d9dfe

Please sign in to comment.