예제 #1
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))
예제 #2
0
    def test_wizard_format_no_iob(self):
        """ Test that wizard events meet format requirements"""
        start_time = datetime(2015, 1, 1, 0, 0, 0)
        # populate gluc list with some fake glucose values
        gluc = [100, 217, 49]
        # populate carb list with some fake carb values (corresponding to a
        # meal)
        carbs = [90, 31, 61]
        # populate timesteps with some fake time values later than start_time
        timesteps = [
            tools.convert_ISO_to_epoch('2015-01-01 15:00:00',
                                       '%Y-%m-%d %H:%M:%S'),
            tools.convert_ISO_to_epoch('2015-01-02 19:30:00',
                                       '%Y-%m-%d %H:%M:%S'),
            tools.convert_ISO_to_epoch('2015-01-03 09:12:00',
                                       '%Y-%m-%d %H:%M:%S')
        ]
        # test that wizard events formats correctly even when no bolus and
        # no_wizard data is given
        bolus_data = []
        no_wizard = []
        zonename = 'US/Pacific'
        pump_name = 'Medtronic'
        res_dict, iob_dict = wizard.wizard(start_time, gluc, carbs, timesteps,
                                           bolus_data, no_wizard, zonename,
                                           pump_name)
        # make sure that for every wizrd event, a bolus event is also created
        # (ie there shold be 6 total events)
        self.assertEqual(len(res_dict), 6)

        # check that the reccomendation of the wizard calculates correctly
        carb_ratio1 = res_dict[1]["insulinCarbRatio"]
        carb_input1 = res_dict[1]["carbInput"]  # should match carbs[0] = 90
        units1 = res_dict[1]["units"]
        net_reccomendation1 = res_dict[1]["recommended"]["net"]
        expected_reccomendation1 = tools.round_to(carb_input1 / carb_ratio1)
        self.assertEqual(net_reccomendation1, expected_reccomendation1)
        self.assertEqual(units1, "mmol/L")

        carb_ratio2 = res_dict[3]["insulinCarbRatio"]
        carb_input2 = res_dict[3]["carbInput"]  # should match carbs[0] = 90
        units2 = res_dict[3]["units"]
        net_reccomendation2 = res_dict[3]["recommended"]["net"]

        expected_reccomendation2 = tools.round_to(carb_input2 / carb_ratio2)
        self.assertEqual(net_reccomendation2, expected_reccomendation2)
        self.assertEqual(units2, "mmol/L")

        carb_ratio3 = res_dict[5]["insulinCarbRatio"]
        carb_input3 = res_dict[5]["carbInput"]  # should match carbs[0] = 90
        units3 = res_dict[5]["units"]
        net_reccomendation3 = res_dict[5]["recommended"]["net"]
        expected_reccomendation3 = tools.round_to(carb_input3 / carb_ratio3)
        self.assertEqual(net_reccomendation3, expected_reccomendation3)
        self.assertEqual(units3, "mmol/L")
예제 #3
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))
예제 #4
0
    def test_wizard_format_with_iob(self):
        """ Test insulin on board calculations are taken into account when
            giving a wizard reccomendation"""
        start_time = datetime(2015, 1, 1, 0, 0, 0)
        gluc = [100]
        carbs = [90]
        timesteps = [
            tools.convert_ISO_to_epoch('2015-01-01 00:00:00',
                                       '%Y-%m-%d %H:%M:%S')
        ]
        bolus_data = [{
            "deviceId": "DemoData-123456789",
            "deviceTime": "2015-01-01T07:59:29",
            "id": "3db26422-e731-429e-ab14-7dfc78a399f3",
            "normal": 10,  # should correspond to iob value!
            "subType": "normal",
            "time": "2015-01-01T00:00:00.000Z",  # same as wizard
            "timezoneOffset": -480.0,
            "type": "bolus",
            "uploadId": "upid_abcdefghijklmnop"
        }]
        no_wizard = []
        zonename = 'US/Pacific'
        pump_name = 'Medtronic'
        res_dict, iob_dict = wizard.wizard(start_time, gluc, carbs, timesteps,
                                           bolus_data, no_wizard, zonename,
                                           pump_name)

        # check that insulin on board value is correct
        expected_iob = tools.convert_to_mmol(10)
        iob = res_dict[1]["insulinOnBoard"]
        self.assertEqual(expected_iob, iob)

        # check that net reccomendationt takes into account insulin on board
        carb_ratio = res_dict[1]["insulinCarbRatio"]
        carb_input = res_dict[1]["carbInput"]  # should match carbs[0] = 90
        net_reccomendation = res_dict[1]["recommended"]["net"]
        expected_reccomendation = (tools.round_to(carb_input / carb_ratio) -
                                   tools.round_to(iob))

        self.assertEqual(net_reccomendation, expected_reccomendation)
예제 #5
0
    def test_float_rounding(self):
        """ Test rounding floats to specified percision """
        #Note, the round_to function always trunctuates the result to three decimal points
        positive_float = 6.124849333
        negative_float = -7.89209123
        low_precision = 0.5
        medium_precision = 0.05
        high_precision = 0.0005

        #expected results for each percision:
        lp_positive, lp_negative = 6.0, -8.0
        md_positive, md_negative = 6.10, -7.90
        hp_positive, hp_negative = 6.125, -7.892

        self.assertEqual(lp_positive, tools.round_to(positive_float, low_precision))
        self.assertEqual(lp_negative, tools.round_to(negative_float, low_precision))
        
        self.assertEqual(md_positive, tools.round_to(positive_float, medium_precision))
        self.assertEqual(md_negative, tools.round_to(negative_float, medium_precision))

        self.assertEqual(hp_positive, tools.round_to(positive_float, high_precision))
        self.assertEqual(hp_negative, tools.round_to(negative_float, high_precision))