示例#1
0
    def test_basal(self):
        self.assertEqual(
            NightscoutEntry.basal(value=1.05,
                                  duration_mins=30,
                                  created_at="2021-03-16 00:25:21-04:00"),
            {
                "eventType": "Temp Basal",
                "reason": "",
                "duration": 30,
                "absolute": 1.05,
                "rate": 1.05,
                "created_at": "2021-03-16 00:25:21-04:00",
                "carbs": None,
                "insulin": None,
                "enteredBy": "Pump (tconnectsync)"
            })

        self.assertEqual(
            NightscoutEntry.basal(value=0.95,
                                  duration_mins=5,
                                  created_at="2021-03-16 12:25:21-04:00",
                                  reason="Correction"),
            {
                "eventType": "Temp Basal",
                "reason": "Correction",
                "duration": 5,
                "absolute": 0.95,
                "rate": 0.95,
                "created_at": "2021-03-16 12:25:21-04:00",
                "carbs": None,
                "insulin": None,
                "enteredBy": "Pump (tconnectsync)"
            })
示例#2
0
    def test_new_ciq_basal_data(self):
        tconnect = TConnectApi()

        # datetimes are unused by the API fake
        start = datetime.datetime(2021, 4, 20, 12, 0)
        end = datetime.datetime(2021, 4, 21, 12, 0)

        def fake_therapy_timeline(time_start, time_end):
            self.assertEqual(time_start, start)
            self.assertEqual(time_end, end)

            return TestBasalSync.get_example_ciq_basal_events()

        tconnect.controliq.therapy_timeline = fake_therapy_timeline
        tconnect.ws2.therapy_timeline_csv = self.stub_therapy_timeline_csv

        nightscout = NightscoutApi()

        nightscout.last_uploaded_entry = self.stub_last_uploaded_entry
        nightscout.last_uploaded_activity = self.stub_last_uploaded_activity

        process_time_range(tconnect, nightscout, start, end, pretend=False, features=[BOLUS, BASAL])

        self.assertEqual(len(nightscout.uploaded_entries["treatments"]), 4)
        self.assertDictEqual(dict(nightscout.uploaded_entries), {
            "treatments": [
                NightscoutEntry.basal(0.8, 20.35, "2021-03-16 00:00:00-04:00", reason="tempDelivery"),
                NightscoutEntry.basal(0.799, 5.0, "2021-03-16 00:20:21-04:00", reason="profileDelivery"),
                NightscoutEntry.basal(0.797, 5.0, "2021-03-16 00:25:21-04:00", reason="algorithmDelivery"),
                NightscoutEntry.basal(0, 2693/60, "2021-03-16 00:30:21-04:00", reason="algorithmDelivery (control-iq suspension)")
        ]})
        self.assertDictEqual(nightscout.put_entries, {})
        self.assertListEqual(nightscout.deleted_entries, [])
示例#3
0
    def test_with_updated_duration_ciq_basal_data(self):
        tconnect = TConnectApi()

        start = datetime.datetime(2021, 4, 20, 12, 0)
        end = datetime.datetime(2021, 4, 21, 12, 0)

        def fake_therapy_timeline(time_start, time_end):
            self.assertEqual(time_start, start)
            self.assertEqual(time_end, end)

            return TestBasalSync.get_example_ciq_basal_events()

        tconnect.controliq.therapy_timeline = fake_therapy_timeline
        tconnect.ws2.therapy_timeline_csv = self.stub_therapy_timeline_csv

        nightscout = NightscoutApi()

        def fake_last_uploaded_entry(event_type):
            if event_type == "Temp Basal":
                return {
                    "created_at": "2021-03-16 00:20:21-04:00",
                    "duration": 3,
                    "_id": "nightscout_id"
                }

        nightscout.last_uploaded_entry = fake_last_uploaded_entry
        nightscout.last_uploaded_activity = self.stub_last_uploaded_activity

        process_time_range(tconnect, nightscout, start, end, pretend=False)

        self.assertEqual(len(nightscout.uploaded_entries["treatments"]), 2)
        self.assertDictEqual(
            nightscout.uploaded_entries, {
                "treatments": [
                    NightscoutEntry.basal(0.797,
                                          5.0,
                                          "2021-03-16 00:25:21-04:00",
                                          reason="algorithmDelivery"),
                    NightscoutEntry.basal(0,
                                          2693 / 60,
                                          "2021-03-16 00:30:21-04:00",
                                          reason="algorithmDelivery")
                ]
            })
        self.assertEqual(len(nightscout.put_entries["treatments"]), 1)
        self.assertDictEqual(
            dict(nightscout.put_entries), {
                "treatments": [{
                    "_id":
                    "nightscout_id",
                    **NightscoutEntry.basal(0.799,
                                            5.0,
                                            "2021-03-16 00:20:21-04:00",
                                            reason="profileDelivery")
                }]
            })
        self.assertDictEqual(nightscout.deleted_entries, {})