コード例 #1
0
    def test_iob_from_no_doses(self):
        model = self.WALSH_MODEL

        (dates,
         insulin_values
         ) = insulin_on_board([], [], [], [], [], model)

        self.assertEqual(0, len(dates))
コード例 #2
0
def generate_iob_fixture(dose_fixture, previous_iob_fixture=False,
                         model_type="Exponential"):
    """ Generate an IOB fixture given a dose fixture and an
    optional fixture (for comparison purposes)

    Arguments:
    dose_fixture -- the dose fixture to use to generate the glucose effect
                    (without the ".json" ending)
    previous_iob_fixture -- an old IOB fixture to compare with the new
                            IOB fixture (without the ".json" ending)
    model -- the model to use to generate the IOB (either Walsh or
             Exponential); Walsh has a DIA of 4 hours (modify "WALSH_MODEL"
             if you want to change that), Exponential has DIA of 360 mins and
             peak at 75 mins (modify "MODEL" to change)
    """
    (i_types, i_start_dates, i_end_dates, i_values, i_scheduled_basal_rates
     ) = load_dose_fixture(dose_fixture)

    if model_type.lower() in ["walsh", "w", "walsh model"]:
        model = WALSH_MODEL
    else:
        model = MODEL

    (dates, insulin_values) = insulin_on_board(
        i_types, i_start_dates, i_end_dates, i_values,
        i_scheduled_basal_rates, model)

    if previous_iob_fixture:
        (out_dates, out_insulin_values) = load_insulin_value_fixture(
            previous_iob_fixture)

        for i in range(0, len(out_insulin_values)):
            print(out_dates[i], dates[i])
            print(out_insulin_values[i], insulin_values[i])
            print()

        answer = input("Look OK? (y/n) ")
        if answer in ("no", "n"):
            return

    output = []
    for i in range(0, len(insulin_values)):
        effect_dict = {}
        effect_dict["date"] = dates[i].isoformat()
        effect_dict["unit"] = "U"
        effect_dict["value"] = insulin_values[i]
        output.append(effect_dict)

    json.dump(output, open((str(previous_iob_fixture) if previous_iob_fixture
                            else model_type.lower() + "_iob_fixture")
                           + "_new.json", "w"))
コード例 #3
0
    def test_iob_from_reservoir_doses(self):
        (i_types,
         i_start_dates,
         i_end_dates,
         i_values,
         i_scheduled_basal_rates
         ) = self.load_dose_fixture("normalized_reservoir_history_output")

        (expected_dates,
         expected_insulin_values
         ) = self.load_insulin_value_fixture("iob_from_reservoir_output")

        model = self.WALSH_MODEL

        (dates,
         insulin_values
         ) = insulin_on_board(
             i_types,
             i_start_dates,
             i_end_dates,
             i_values,
             i_scheduled_basal_rates,
             model
             )

        self.assertEqual(
            len(expected_dates), len(dates)
        )

        for i in range(0, len(expected_dates)):
            self.assertEqual(
                expected_dates[i], dates[i]
            )
            self.assertTrue(
                -0.4 < expected_insulin_values[i] - insulin_values[i] < 0.4
            )

        """ Tests for percent_effect_remaining """
コード例 #4
0
    def test_iob_from_bolus_exponential(self):
        (i_types,
         i_start_dates,
         i_end_dates,
         i_values,
         i_scheduled_basal_rates
         ) = self.load_dose_fixture("bolus_dose")

        (expected_dates,
         expected_insulin_values
         ) = self.load_insulin_value_fixture(
             "iob_from_bolus_exponential_output"
             )

        model = self.MODEL

        (dates,
         insulin_values
         ) = insulin_on_board(
             i_types,
             i_start_dates,
             i_end_dates,
             i_values,
             i_scheduled_basal_rates,
             model
             )

        self.assertEqual(
            len(expected_dates), len(dates)
        )

        for i in range(0, len(expected_dates)):
            self.assertEqual(
                expected_dates[i], dates[i]
            )
            self.assertAlmostEqual(
                expected_insulin_values[i], insulin_values[i], 2
            )
コード例 #5
0
    def test_iob_from_bolus(self):
        (i_types,
         i_start_dates,
         i_end_dates,
         i_values,
         i_scheduled_basal_rates
         ) = self.load_dose_fixture("bolus_dose")

        for hour in [2, 3, 4, 5, 5.2, 6, 7]:
            model = [hour]
            (expected_dates,
             expected_insulin_values
             ) = self.load_insulin_value_fixture(
                 "iob_from_bolus_" + str(int(hour*60)) + "min_output"
                 )

            (dates,
             insulin_values
             ) = insulin_on_board(
                 i_types,
                 i_start_dates,
                 i_end_dates,
                 i_values,
                 i_scheduled_basal_rates,
                 model
                 )

            self.assertEqual(
                len(expected_dates), len(dates)
            )

            for i in range(0, len(expected_dates)):
                self.assertEqual(
                    expected_dates[i], dates[i]
                )
                self.assertAlmostEqual(
                    expected_insulin_values[i], insulin_values[i], 2
                )
コード例 #6
0
    def test_iob_from_doses_exponential(self):
        (i_types,
         i_start_dates,
         i_end_dates,
         i_values,
         i_scheduled_basal_rates
         ) = self.load_dose_fixture("normalized_doses")

        (expected_dates,
         expected_insulin_values
         ) = self.load_insulin_value_fixture(
             "iob_from_doses_exponential_output_new"
             )

        model = self.MODEL

        (dates,
         insulin_values
         ) = insulin_on_board(
             i_types,
             i_start_dates,
             i_end_dates,
             i_values,
             i_scheduled_basal_rates,
             model
             )

        self.assertEqual(
            len(expected_dates), len(dates)
        )

        for i in range(0, len(expected_dates)):
            self.assertEqual(
                expected_dates[i], dates[i]
            )
            self.assertTrue(
                -0.5 < expected_insulin_values[i] - insulin_values[i] < 0.5
            )
コード例 #7
0
    def test_iob_from_suspend(self):
        (i_types,
         i_start_dates,
         i_end_dates,
         i_values
         ) = self.load_dose_fixture("suspend_dose")[0:4]

        (r_types,
         r_start_dates,
         r_end_dates,
         r_values,
         r_scheduled_basal_rates
         ) = self.load_dose_fixture("suspend_dose_reconciled")

        (n_types,
         n_start_dates,
         n_end_dates,
         n_values,
         n_scheduled_basal_rates
         ) = self.load_dose_fixture("suspend_dose_reconciled_normalized")

        (out_dates,
         out_insulin_values
         ) = self.load_insulin_value_fixture(
             "suspend_dose_reconciled_normalized_iob"
             )

        (start_times,
         rates,
         minutes
         ) = self.load_basal_rate_schedule_fixture("basal")

        model = self.WALSH_MODEL

        (r_out_types,
         r_out_start_dates,
         r_out_end_dates,
         r_out_values
         ) = reconciled(
             i_types,
             i_start_dates,
             i_end_dates,
             i_values
             )

        self.assertEqual(
            len(r_types), len(r_out_types)
        )
        for i in range(0, len(r_types)):
            self.assertEqual(
                r_start_dates[i], r_out_start_dates[i]
            )
            self.assertEqual(
                r_end_dates[i], r_out_end_dates[i]
            )
            self.assertAlmostEqual(
                r_values[i], r_out_values[i], 2
            )

        (n_out_types,
         n_out_start_dates,
         n_out_end_dates,
         n_out_values,
         n_out_scheduled_rates) = annotated(
             r_out_types,
             r_out_start_dates,
             r_out_end_dates,
             r_out_values,
             start_times,
             rates,
             minutes
             )

        self.assertEqual(
            len(n_types), len(n_out_types)
        )
        for i in range(0, len(r_types)):
            self.assertEqual(
                n_start_dates[i], n_out_start_dates[i]
            )
            self.assertEqual(
                n_end_dates[i], n_out_end_dates[i]
            )
            self.assertAlmostEqual(
                n_values[i],
                n_out_values[i] - n_out_scheduled_rates[i], 2
            )

        (dates,
         insulin_values
         ) = insulin_on_board(
             n_out_types,
             n_out_start_dates,
             n_out_end_dates,
             n_out_values,
             n_out_scheduled_rates,
             model
             )

        self.assertEqual(
            len(out_dates), len(dates)
        )
        for i in range(0, len(out_dates)):
            self.assertEqual(
                out_dates[i], dates[i]
            )
            self.assertAlmostEqual(
                out_insulin_values[i], insulin_values[i], 2
            )