Ejemplo n.º 1
0
    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,
            }
        )
Ejemplo n.º 2
0
    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"))
Ejemplo n.º 3
0
    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)"))
Ejemplo n.º 4
0
 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"
         }
     )
Ejemplo n.º 5
0
    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])
        ])
Ejemplo n.º 6
0
 def test_parse_basalsuspension_event_basalprofile_skipped(self):
     self.assertIsNone(
         TConnectEntry.parse_basalsuspension_event({
             'EventDateTime': '/Date(1638659343000-0000)/',
             'SuspendReason': 'basal-profile',
         })
     )
Ejemplo n.º 7
0
    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])
Ejemplo n.º 8
0
 def test_parse_basalsuspension_event_previous_skipped(self):
     self.assertIsNone(
         TConnectEntry.parse_basalsuspension_event({
             'Continuation': 'continuation',
             'EventDateTime': '/Date(1638604800000-0000)/',
             'SuspendReason': 'previous',
         })
     )
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
 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])
Ejemplo n.º 11
0
 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"
         }
     )
Ejemplo n.º 12
0
 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"
         }
     )
Ejemplo n.º 13
0
 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"
         }
     )
Ejemplo n.º 14
0
 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"
         }
     )
Ejemplo n.º 15
0
 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"
         }
     )
Ejemplo n.º 16
0
 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"
         }
     )
Ejemplo n.º 17
0
 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"
         }
     )
Ejemplo n.º 18
0
 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"
         }
     )
Ejemplo n.º 19
0
    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)
Ejemplo n.º 20
0
    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])
Ejemplo n.º 21
0
 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"
         }
     )
Ejemplo n.º 22
0
    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)
Ejemplo n.º 23
0
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])
Ejemplo n.º 24
0
 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"
         }
     )
Ejemplo n.º 25
0
 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"
         }
     )
Ejemplo n.º 26
0
 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
     })
Ejemplo n.º 27
0
 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
     })
Ejemplo n.º 28
0
 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
     })
Ejemplo n.º 29
0
 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
         })
Ejemplo n.º 30
0
    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
            }
        )