Exemple #1
0
    def test_counteraction_effects_for_no_glucose(self):
        (effect_dates, effect_glucoses) = self.load_output_fixture(
            "counteraction_effect_falling_glucose_insulin")

        (start_dates, end_dates,
         velocities) = counteraction_effects([], [], [], [], effect_dates,
                                             effect_glucoses)

        self.assertEqual(0, len(start_dates))
Exemple #2
0
def get_counteraction_effects(glucose_starts,
                              glucose_values,
                              start_date,
                              effect_starts,
                              effect_values,
                              display_list=None,
                              provenances=None):
    """ Get counteraction effects

    Arguments:
    glucose_starts -- list of datetime objects of times of glucose values
    glucose_values -- list of glucose values (unit: mg/dL)

    start_date -- date to begin using glucose data (datetime)

    effect_dates -- list of datetime objects associated with a glucose effect
    effect_values -- list of values associated with a glucose effect

    display_list -- list of display_only booleans
    provenances -- list of provenances (Strings)

    Output:
    Counteraction effects in form (effect start, effect end, effect value)
    """
    assert len(glucose_starts) == len(glucose_values),\
        "expected input shapes to match"

    if not glucose_starts or not start_date:
        return ([], [])

    (filtered_starts, ends,
     filtered_values) = filter_date_range(glucose_starts, [], glucose_values,
                                          start_date, None)

    if not display_list:
        display_list = [False for i in filtered_starts]
    if not provenances:
        provenances = ["PyLoop" for i in filtered_starts]

    counteractions = counteraction_effects(filtered_starts, filtered_values,
                                           display_list, provenances,
                                           effect_starts, effect_values)

    return counteractions
Exemple #3
0
    def test_counteraction_effects_for_falling_glucose_duplicates(self):
        (i_dates, i_glucoses, displays, provenances) = self.load_input_fixture(
            "counteraction_effect_falling_glucose_double_entries_input")

        (effect_dates, effect_glucoses) = self.load_output_fixture(
            "counteraction_effect_falling_glucose_insulin")

        (expected_start_dates, expected_end_dates,
         expected_velocities) = self.load_effect_velocity_fixture(
             "counteraction_effect_falling_glucose_output")

        (start_dates, end_dates,
         velocities) = counteraction_effects(i_dates, i_glucoses, displays,
                                             provenances, effect_dates,
                                             effect_glucoses)

        self.assertEqual(len(expected_start_dates), len(start_dates))
        for i in range(0, len(expected_start_dates)):
            self.assertEqual(expected_start_dates[i], start_dates[i])
            self.assertAlmostEqual(expected_velocities[i], velocities[i], 2)