diff --git a/test/fixtures.js b/test/fixtures.js index de3dc4b..a0207b3 100644 --- a/test/fixtures.js +++ b/test/fixtures.js @@ -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, @@ -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" : "", "activeInsulin" : { diff --git a/test/transform.js b/test/transform.js index cec38f4..0433ce2 100644 --- a/test/transform.js +++ b/test/transform.js @@ -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); + }); }); diff --git a/transform.js b/transform.js index 217ff6b..98b38bb 100644 --- a/transform.js +++ b/transform.js @@ -40,13 +40,24 @@ 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]; @@ -54,7 +65,7 @@ function pumpStatusEntry(data) { }); if(data['activeInsulin'] && data['activeInsulin']['amount'] >= 0) { - entry['activeInsulin'] = data['activeInsulin']['amount']; + entry['iob'] = data['activeInsulin']['amount']; } return addTimeToEntry(data['lastMedicalDeviceDataUpdateServerTime'], entry);