def test_simple_iob_dict_creation(self): """ Check a single insulin dose distribution over action_time = one hour""" expected_input = [{ "deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:00:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 6, "subType": "normal", "time": "2015-03-03T00:00:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop" }] res_dict = insulin_on_board.create_iob_dict(expected_input, action_time=1) half_way = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:30:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #30 mins later three_fourth = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:45:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #45 mins later #test that halfway through the action time, IOB is half the original bolus self.assertEqual(tools.round_to(half_way), float(expected_input[0]['normal'] / 2)) #test that 75% through the action time, IOB is one fourth the original bolus self.assertEqual(tools.round_to(three_fourth), float(expected_input[0]['normal'] / 4))
def test_complex_iob_dict_creation(self): """ Check two insulin doses five minutes apart, action_time = 10 minutes""" expected_input = [{"deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:00:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:00:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop"}, {"deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:05:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:05:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop"}] res_dict = insulin_on_board.create_iob_dict(expected_input, action_time=10/60) initial_iob = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:00:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] five_min = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:05:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] ten_min = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:10:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #At time = 0 min, IOB should be 10 self.assertEqual(initial_iob, 10.0) #At time = 5 min, initial IOB = 5 + second IOB = 10 --> 15 total self.assertEqual(five_min, 15.0) #At time = 10 min, initial IOB = 0, and second IOB should have 5 units left self.assertEqual(ten_min, 5.0)
def test_simple_iob_dict_creation(self): """ Check a single insulin dose distribution over action_time = one hour""" expected_input = [{"deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:00:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 6, "subType": "normal", "time": "2015-03-03T00:00:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop"}] res_dict = insulin_on_board.create_iob_dict(expected_input, action_time=1) half_way = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:30:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #30 mins later three_fourth = res_dict[tools.convert_ISO_to_epoch('2015-03-03T00:45:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #45 mins later #test that halfway through the action time, IOB is half the original bolus self.assertEqual(tools.round_to(half_way), float(expected_input[0]['normal'] / 2)) #test that 75% through the action time, IOB is one fourth the original bolus self.assertEqual(tools.round_to(three_fourth), float(expected_input[0]['normal'] / 4))
def test_complex_iob_dict_creation(self): """ Check two insulin doses five minutes apart, action_time = 10 minutes""" expected_input = [{ "deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:00:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:00:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop" }, { "deviceId": "DemoData-123456789", "deviceTime": "2015-03-03T00:05:00", "id": "002650eb-3d53-4a3d-b39f-6cd0c1ce58f2", "normal": 10, "subType": "normal", "time": "2015-03-03T00:05:00.000Z", "timezoneOffset": -480.0, "type": "bolus", "uploadId": "upid_abcdefghijklmnop" }] res_dict = insulin_on_board.create_iob_dict(expected_input, action_time=10 / 60) initial_iob = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:00:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] five_min = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:05:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] ten_min = res_dict[tools.convert_ISO_to_epoch( '2015-03-03T00:10:00.000Z', '%Y-%m-%dT%H:%M:%S.000Z')] #At time = 0 min, IOB should be 10 self.assertEqual(initial_iob, 10.0) #At time = 5 min, initial IOB = 5 + second IOB = 10 --> 15 total self.assertEqual(five_min, 15.0) #At time = 10 min, initial IOB = 0, and second IOB should have 5 units left self.assertEqual(ten_min, 5.0)