def test_parse_ciq_basal_entry(self): self.assertEqual( TConnectEntry.parse_ciq_basal_entry({ "y": 0.8, "duration": 1221, "x": 1615878000 }), { "time": "2021-03-16 00:00:00-04:00", "delivery_type": "", "duration_mins": 1221/60, "basal_rate": 0.8, } ) self.assertEqual( TConnectEntry.parse_ciq_basal_entry({ "y": 0.797, "duration": 300, "x": 1615879521 }, delivery_type="algorithmDelivery"), { "time": "2021-03-16 00:25:21-04:00", "delivery_type": "algorithmDelivery", "duration_mins": 5, "basal_rate": 0.797, } )
def test_process_ciq_basal_events_with_manual_suspension(self): data = TestBasalSync.get_example_ciq_basal_events_with_manual_suspension( ) basalEvents = process_ciq_basal_events(data) self.assertEqual(len(basalEvents), 4) self.assertEqual( basalEvents[0], TConnectEntry.parse_ciq_basal_entry( data["basal"]["algorithmDeliveryEvents"][0], delivery_type="algorithmDelivery")) self.assertEqual( basalEvents[1], TConnectEntry.parse_ciq_basal_entry( data["basal"]["algorithmDeliveryEvents"][1], delivery_type="algorithmDelivery")) self.assertEqual( basalEvents[2], TConnectEntry.manual_suspension_to_basal_entry( TConnectEntry.parse_suspension_entry( data["suspensionDeliveryEvents"][0]), seconds=2112, # 2112 seconds between 12:07:35 and 12:42:47 )) self.assertEqual( basalEvents[3], TConnectEntry.parse_ciq_basal_entry( data["basal"]["algorithmDeliveryEvents"][2], delivery_type="algorithmDelivery"))
def test_process_ciq_basal_events(self): data = TestBasalSync.get_example_ciq_basal_events() basalEvents = process_ciq_basal_events(data) self.assertEqual(len(basalEvents), 4) self.assertEqual( basalEvents[0], TConnectEntry.parse_ciq_basal_entry( data["basal"]["tempDeliveryEvents"][0], delivery_type="tempDelivery")) self.assertEqual( basalEvents[1], TConnectEntry.parse_ciq_basal_entry( data["basal"]["profileDeliveryEvents"][0], delivery_type="profileDelivery")) self.assertEqual( basalEvents[2], TConnectEntry.parse_ciq_basal_entry( data["basal"]["algorithmDeliveryEvents"][0], delivery_type="algorithmDelivery")) self.assertEqual( basalEvents[3], TConnectEntry.parse_ciq_basal_entry( data["basal"]["algorithmDeliveryEvents"][1], delivery_type="algorithmDelivery (control-iq suspension)"))
def test_parse_suspension_entry(self): self.assertEqual( TConnectEntry.parse_suspension_entry({ "suspendReason": "control-iq", "continuation": None, "x": 1615879821 }), { "time": "2021-03-16 00:30:21-04:00", "continuation": None, "suspendReason": "control-iq" } ) self.assertEqual( TConnectEntry.parse_suspension_entry({ "suspendReason": "control-iq", "continuation": "previous", "x": 1634022000 }), { "time": "2021-10-12 00:00:00-04:00", "continuation": "previous", "suspendReason": "control-iq" } )
def test_process_bolus_events(self): bolusData = TestBolusSync.get_example_csv_bolus_events() bolusEvents = process_bolus_events(bolusData) self.assertEqual(len(bolusEvents), 3) self.assertListEqual(bolusEvents, [ TConnectEntry.parse_bolus_entry(bolusData[0]), TConnectEntry.parse_bolus_entry(bolusData[1]), TConnectEntry.parse_bolus_entry(bolusData[2]) ])
def test_parse_basalsuspension_event_basalprofile_skipped(self): self.assertIsNone( TConnectEntry.parse_basalsuspension_event({ 'EventDateTime': '/Date(1638659343000-0000)/', 'SuspendReason': 'basal-profile', }) )
def test_process_iob_events(self): iobData = TestIOBSync.get_example_csv_iob_events() iobEvents = process_iob_events(iobData) self.assertEqual(len(iobEvents), len(iobData)) self.assertListEqual( iobEvents, [TConnectEntry.parse_iob_entry(d) for d in iobData])
def test_parse_basalsuspension_event_previous_skipped(self): self.assertIsNone( TConnectEntry.parse_basalsuspension_event({ 'Continuation': 'continuation', 'EventDateTime': '/Date(1638604800000-0000)/', 'SuspendReason': 'previous', }) )
def test_process_bolus_events_skip_zero(self): stdData = [ TestTConnectEntryBolus.entryStdCorrection, TestTConnectEntryBolus.entryStd, TestTConnectEntryBolus.entryStdAutomatic ] zeroData = [TestTConnectEntryBolus.entryStdIncompleteZero] bolusData = stdData + zeroData bolusEvents = process_bolus_events(bolusData) self.assertEqual(len(bolusEvents), len(stdData)) self.assertListEqual( bolusEvents, [TConnectEntry.parse_bolus_entry(d) for d in stdData]) for d in zeroData: self.assertNotIn(TConnectEntry.parse_bolus_entry(d), bolusEvents)
def test_process_cgm_events(self): rawReadings = [ TestTConnectEntryReading.entry1, TestTConnectEntryReading.entry2, TestTConnectEntryReading.entry3, TestTConnectEntryReading.entry4 ] self.assertListEqual( process_cgm_events(rawReadings), [TConnectEntry.parse_reading_entry(r) for r in rawReadings])
def test_parse_iob_entry2(self): self.assertEqual( TConnectEntry.parse_iob_entry(self.entry2), { "time": "2021-10-12 00:10:30-04:00", "iob": "6.80", "event_id": "9" } )
def test_parse_iob_entry1(self): self.assertEqual( TConnectEntry.parse_iob_entry(self.entry1), { "time": "2021-10-12 00:00:30-04:00", "iob": "6.91", "event_id": "81" } )
def test_parse_reading_entry4(self): self.assertEqual( TConnectEntry.parse_reading_entry(self.entry4), { "time": "2021-10-23 16:25:52-04:00", "bg": "107", "type": "EGV" } )
def test_parse_reading_entry1(self): self.assertEqual( TConnectEntry.parse_reading_entry(self.entry1), { "time": "2021-10-23 12:55:53-04:00", "bg": "135", "type": "EGV" } )
def test_parse_basalsuspension_event_tempprofile(self): self.assertEqual( TConnectEntry.parse_basalsuspension_event({ 'EventDateTime': '/Date(1640541521000-0000)/', 'SuspendReason': 'temp-profile' }), { "time": "2021-12-26 09:58:41-05:00", "event_type": "Basal Rate Change" } )
def test_parse_basalsuspension_event_manual(self): self.assertEqual( TConnectEntry.parse_basalsuspension_event({ 'EventDateTime': '/Date(1638662852000-0000)/', 'SuspendReason': 'manual' }), { "time": "2021-12-04 16:07:32-05:00", "event_type": "User Suspended" } )
def test_parse_basalsuspension_event_alarm(self): self.assertEqual( TConnectEntry.parse_basalsuspension_event({ 'EventDateTime': '/Date(1637863616000-0000)/', 'SuspendReason': 'alarm' }), { "time": "2021-11-25 10:06:56-05:00", "event_type": "Empty Cartridge/Pump Shutdown" } )
def test_parse_basalsuspension_event_sitecart(self): self.assertEqual( TConnectEntry.parse_basalsuspension_event({ 'EventDateTime': '/Date(1638663490000-0000)/', 'SuspendReason': 'site-cart' }), { "time": "2021-12-04 16:18:10-05:00", "event_type": "Site/Cartridge Change" } )
def test_process_bolus_events_cgmevents_not_matching(self): bolusData = [ TestTConnectEntryBolus.entryStdCorrection, TestTConnectEntryBolus.entryStd, TestTConnectEntryBolus.entryStdAutomatic ] cgmEvents = [ TConnectEntry.parse_reading_entry(TestTConnectEntryReading.entry1), TConnectEntry.parse_reading_entry(TestTConnectEntryReading.entry2), TConnectEntry.parse_reading_entry(TestTConnectEntryReading.entry3) ] bolusEvents = process_bolus_events(bolusData, cgmEvents=cgmEvents) self.assertEqual(len(bolusEvents), len(bolusData)) def set_bg_type(entry, type): entry["bg_type"] = type return entry # Expect FINGER for bolus entries with a BG because there's no matching event with the same BG expected = [ set_bg_type(TConnectEntry.parse_bolus_entry(bolusData[0]), NightscoutEntry.FINGER), set_bg_type(TConnectEntry.parse_bolus_entry(bolusData[1]), NightscoutEntry.FINGER), # No BG specified for the automatic bolus TConnectEntry.parse_bolus_entry(bolusData[2]) ] self.assertListEqual(bolusEvents, expected)
def test_process_bolus_events_standard(self): bolusData = [ TestTConnectEntryBolus.entryStdCorrection, TestTConnectEntryBolus.entryStd, TestTConnectEntryBolus.entryStdAutomatic ] bolusEvents = process_bolus_events(bolusData) self.assertEqual(len(bolusEvents), len(bolusData)) self.assertListEqual( bolusEvents, [TConnectEntry.parse_bolus_entry(d) for d in bolusData])
def test_parse_cgm_entry(self): self.assertEqual( TConnectEntry.parse_cgm_entry({ "DeviceType": "t:slim X2 Insulin Pump", "SerialNumber": "11111111", "Description": "EGV", "EventDateTime": "2021-10-12T00:01:12", "Readings (CGM / BGM)": "131" }), { "time": "2021-10-12 00:01:12-04:00", "reading": "131", "reading_type": "EGV" } )
def test_process_bolus_events_update_partial_description(self): stdData = [ TestTConnectEntryBolus.entryStdCorrection, TestTConnectEntryBolus.entryStd, TestTConnectEntryBolus.entryStdAutomatic ] partialData = [TestTConnectEntryBolus.entryStdIncompletePartial] bolusData = stdData + partialData bolusEvents = process_bolus_events(bolusData) self.assertEqual(len(bolusEvents), len(bolusData)) partialEntries = [ TConnectEntry.parse_bolus_entry(e) for e in partialData ] for e in partialEntries: e["description"] += " (%s: requested %s units)" % ( e["completion"], e["requested_insulin"]) self.assertListEqual( bolusEvents, [TConnectEntry.parse_bolus_entry(d) for d in stdData] + partialEntries)
class TestFindEventAt(unittest.TestCase): readingData = [ TConnectEntry.parse_reading_entry(TestTConnectEntryReading.entry1), TConnectEntry.parse_reading_entry(TestTConnectEntryReading.entry2), TConnectEntry.parse_reading_entry(TestTConnectEntryReading.entry3), TConnectEntry.parse_reading_entry(TestTConnectEntryReading.entry4) ] def test_find_event_at_exact(self): for r in self.readingData: self.assertEqual(find_event_at(self.readingData, r["time"]), r) def test_find_event_at_before_not_found(self): self.assertEqual( find_event_at(self.readingData, "2021-10-22 10:30:00-04:00"), None) def test_find_event_at_large_gap(self): self.assertEqual( find_event_at(self.readingData, "2021-10-23 13:30:00-04:00"), self.readingData[0]) def test_find_event_at_between_close(self): self.assertEqual( find_event_at(self.readingData, "2021-10-23 16:17:52-04:00"), self.readingData[1]) self.assertEqual( find_event_at(self.readingData, "2021-10-23 16:21:52-04:00"), self.readingData[2]) self.assertEqual( find_event_at(self.readingData, "2021-10-23 16:25:59-04:00"), self.readingData[3]) def test_find_event_at_most_recent(self): self.assertEqual( find_event_at(self.readingData, "2021-10-23 18:00:00-04:00"), self.readingData[3])
def test_parse_ciq_activity_event_sleep(self): self.assertEqual( TConnectEntry.parse_ciq_activity_event({ "continuation": None, "duration": 30661, "eventType": 1, "timeZoneId": "America/Los_Angeles", "x": 1638091836 }), { "time": "2021-11-28 01:30:36-05:00", "duration_mins": (30661 / 60), "event_type": "Sleep" } )
def test_parse_ciq_activity_event_exercise(self): self.assertEqual( TConnectEntry.parse_ciq_activity_event({ "duration": 1200, "eventType": 2, "continuation": None, "timeZoneId": "America/Los_Angeles", "x": 1619901912 }), { "time": "2021-05-01 13:45:12-04:00", "duration_mins": 20, "event_type": "Exercise" } )
def test_parse_bolus_entry_std_correction(self): self.assertEqual( TConnectEntry.parse_bolus_entry(self.entryStdCorrection), { "description": "Standard/Correction", "complete": "1", "completion": "Completed", "request_time": "2021-04-01 12:53:36-04:00", "completion_time": "2021-04-01 12:58:26-04:00", "insulin": "13.53", "carbs": "75", "user_override": "0", "extended_bolus": "", "bolex_completion_time": None, "bolex_start_time": None })
def test_parse_bolus_entry_std(self): self.assertEqual( TConnectEntry.parse_bolus_entry(self.entryStd), { "description": "Standard", "complete": "1", "completion": "Completed", "request_time": "2021-04-01 23:21:58-04:00", "completion_time": "2021-04-01 23:23:17-04:00", "insulin": "1.25", "carbs": "0", "user_override": "1", "extended_bolus": "", "bolex_completion_time": None, "bolex_start_time": None })
def test_parse_bolus_entry_std_automatic(self): self.assertEqual( TConnectEntry.parse_bolus_entry(self.entryStdAutomatic), { "description": "Automatic Bolus/Correction", "complete": "1", "completion": "Completed", "request_time": "2021-04-02 00:59:13-04:00", "completion_time": "2021-04-02 01:00:47-04:00", "insulin": "1.70", "carbs": "0", "user_override": "0", "extended_bolus": "", "bolex_completion_time": None, "bolex_start_time": None })
def test_parse_bolus_entry_std_incomplete_partial(self): self.assertEqual( TConnectEntry.parse_bolus_entry(self.entryStdIncompletePartial), { "description": "Standard/Correction", "complete": "", "completion": "Terminated by Alarm", "request_time": "2021-09-06 12:23:23-04:00", "completion_time": "2021-09-06 12:24:47-04:00", "insulin": "1.82", "requested_insulin": "2.63", "carbs": "0", "bg": "189", "user_override": "0", "extended_bolus": "", "bolex_completion_time": None, "bolex_start_time": None })
def test_manual_suspension_to_basal_entry(self): suspension = { "time": "2021-03-16 00:30:21-04:00", "continuation": None, "suspendReason": "manual" } self.assertEqual( TConnectEntry.manual_suspension_to_basal_entry( suspension, seconds=300 ), { "time": "2021-03-16 00:30:21-04:00", "delivery_type": "manual suspension", "duration_mins": 5.0, "basal_rate": 0.0 } )