Пример #1
0
    def load_glucose_velocities(self, resource_name):
        """ Load effect-velocity json file

        Arguments:
        resource_name -- name of file without the extension

        Output:
        3 lists in (start_date, end_date, glucose_effects) format
        """
        fixture = load_fixture(resource_name, ".json")

        start_dates = [
            datetime.fromisoformat(
                dict_.get("startDate") if dict_.get("startDate") else dict_.
                get("start_at")) for dict_ in fixture
        ]
        end_dates = [
            datetime.fromisoformat(
                dict_.get("endDate") if dict_.get("endDate") else dict_.
                get("end_at")) for dict_ in fixture
        ]
        glucose_effects = [
            dict_.get("value") if dict_.get("value") else dict_.get("velocity")
            for dict_ in fixture
        ]
        assert len(start_dates) == len(end_dates) == len(glucose_effects),\
            "expected output shape to match"

        return (start_dates, end_dates, glucose_effects)
Пример #2
0
    def load_ice_input_fixture(self, name):
        """ Load insulin counteraction effects (ICE) from json file

        Arguments:
        name -- name of file without the extension

        Output:
        3 lists in (start_date, end_date, insulin_counteraction_value) format
        """
        fixture = load_fixture(name, ".json")

        start_dates = [
            datetime.fromisoformat(dict_.get("start_at"))
            for dict_ in fixture
        ]
        end_dates = [
            datetime.fromisoformat(dict_.get("end_at"))
            for dict_ in fixture
        ]
        ice_values = [dict_.get("velocity") for dict_ in fixture]

        assert len(start_dates) == len(end_dates) == len(ice_values),\
            "expected output shape to match"

        return (start_dates, end_dates, ice_values)
Пример #3
0
    def load_counteraction_input_fixture(self, name):
        """ Load insulin counteraction effects from json file

        Arguments:
        name -- name of file without the extension

        Output:
        3 lists in (start_date, end_date, insulin_counteraction_value) format
        """
        fixture = load_fixture(name, ".json")

        start_dates = [
            datetime.fromisoformat(dict_.get("startDate"))
            if "T" in dict_.get("startDate")
            else datetime.strptime(
                dict_.get("startDate"),
                "%Y-%m-%d %H:%M:%S %z"
            )
            for dict_ in fixture
        ]
        end_dates = [
            datetime.fromisoformat(dict_.get("endDate"))
            if "T" in dict_.get("endDate")
            else datetime.strptime(
                dict_.get("endDate"),
                "%Y-%m-%d %H:%M:%S %z"
            )
            for dict_ in fixture
        ]
        ice_values = [dict_.get("value") for dict_ in fixture]

        assert len(start_dates) == len(end_dates) == len(ice_values),\
            "expected output shape to match"

        return (start_dates, end_dates, ice_values)
Пример #4
0
    def load_sensitivities(self, resource_name):
        """ Load insulin sensitivity schedule from json file

        Arguments:
        resource_name -- name of file without the extension

        Output:
        3 lists in (sensitivity_start_time, sensitivity_end_time,
                    sensitivity_value (mg/dL/U)) format
        """
        data = load_fixture(resource_name, ".json")

        start_times = [
            datetime.strptime(dict_.get("start"), "%H:%M:%S").time()
            for dict_ in data
        ]
        end_times = [
            datetime.strptime(dict_.get("end"), "%H:%M:%S").time()
            for dict_ in data
        ]
        values = [dict_.get("value") for dict_ in data]

        assert len(start_times) == len(end_times) == len(values),\
            "expected output shape to match"

        return (start_times, end_times, values)
Пример #5
0
    def load_glucose_effect_fixture_normal_time(self, name):
        """ Load glucose effects from json file if dates are in format
            "%Y-%m-%d %H:%M:%S %z"

        Output:
        2 lists in (date, glucose_value) format
        """
        fixture = load_fixture(
            name,
            ".json"
        )

        dates = [
            datetime.strptime(
                dict_.get("date"),
                "%Y-%m-%d %H:%M:%S %z"
            )
            for dict_ in fixture
        ]
        glucose_values = [dict_.get("value") for dict_ in fixture]

        assert len(dates) == len(glucose_values),\
            "expected output shape to match"

        return (dates, glucose_values)
Пример #6
0
    def load_reservoir_fixture(self, resource_name):
        """ Load reservior data from json file

        Arguments:
        resource_name -- name of file without the extension

        Variable names:
        fixture -- list of dictionaries; each dictionary contains properties
        of a NewReserviorValue

        Output:
        2 lists in (date, units_given) format
        """
        fixture = load_fixture(resource_name, ".json")

        dates = [
            datetime.fromisoformat(dict_.get("date"))
            for dict_ in fixture
        ]
        unit_volumes = [dict_.get("amount") for dict_ in fixture]

        assert len(dates) == len(unit_volumes),\
            "expected output shape to match"

        return (dates, unit_volumes)
Пример #7
0
    def load_input_fixture(self, resource_name):
        """ Load input json file

        Arguments:
        resource_name -- name of file without the extension

        Variable names:
        fixture -- list of dictionaries; each dictionary contains properties
        of a GlucoseFixtureValue

        Output:
        4 lists in (date, glucose_value,
        display_only (for calibration purposes), providence_identifier) format
        """
        fixture = load_fixture(resource_name, ".json")

        dates = [
            datetime.fromisoformat(dict_.get("date")) for dict_ in fixture
        ]
        glucose_values = [dict_.get("amount") for dict_ in fixture]

        def get_boolean(dict_):
            return dict_.get("display_only") in ("yes", "true", "True")

        display_onlys = [get_boolean(dict_) for dict_ in fixture]
        providences = [
            dict_.get("provenance_identifier") or "com.loopkit.LoopKitTests"
            for dict_ in fixture
        ]

        assert len(dates) == len(glucose_values) == len(display_onlys) ==\
            len(providences), "expected output shape to match"

        return (dates, glucose_values, display_onlys, providences)
Пример #8
0
    def load_report_insulin_effects(self, report_name):
        """ Load the expected insulin effects from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("insulin_effect"),\
            "expected issue report to contain insulin effect information"

        return load_insulin_effects(report.get("insulin_effect"))
Пример #9
0
    def load_report_insulin_doses(self, report_name):
        """ Load the normalized dose entries from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("get_normalized_dose_entries"),\
            "expected issue report to contain dose information"

        return get_insulin_data(report.get("get_normalized_dose_entries"))
Пример #10
0
    def load_report_predicted_glucoses(self, report_name):
        """ Load the expected retrospective effects from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("predicted_glucose"),\
            "expected issue report to contain glucose prediction information"

        return load_insulin_effects(report.get("predicted_glucose"))
Пример #11
0
    def load_report_glucose_values(self, report_name):
        """ Load the cached glucose values from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("cached_glucose_samples"),\
            "expected issue report to contain glucose information"

        return get_glucose_data(report.get("cached_glucose_samples"))
Пример #12
0
    def load_report_basal_schedule(self, report_name):
        """ Load the basal schedule from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("basal_rate_schedule"),\
            "expected issue report to contain basal rate information"

        return get_basal_schedule(report.get("basal_rate_schedule"))
Пример #13
0
    def load_report_cr_schedule(self, report_name):
        """ Load the carb ratio schedule from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("carb_ratio_schedule"),\
            "expected issue report to contain carb ratio information"

        return get_carb_ratios(report.get("carb_ratio_schedule"))
Пример #14
0
    def load_report_momentum_effects(self, report_name):
        """ Load the expected momentum effects from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("glucose_momentum_effect"),\
            "expected issue report to contain momentum information"

        return load_momentum_effects(report.get("glucose_momentum_effect"))
Пример #15
0
    def load_report_retrospective_effects(self, report_name):
        """ Load the expected retrospective effects from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("retrospective_glucose_effect"),\
            "expected issue report to contain retrospective effect information"

        return get_retrospective_effects(
            report.get("retrospective_glucose_effect"))
Пример #16
0
    def load_carb_entry_fixture(self):
        """ Load carb entry

        Output:
        3 lists in (carb_values, carb_start_dates, carb_absorption_times)
        format
        """
        fixture = load_fixture("carb_entry_input", ".json")
        return self.carb_entries_from_fixture(fixture)
Пример #17
0
    def load_report_sensitivity_schedule(self, report_name):
        """ Load the insulin sensitivity schedule from an issue report """
        report = load_fixture(report_name, ".json")

        assert report.get("insulin_sensitivity_factor_schedule"),\
            "expected issue report to contain insulin sensitivity information"

        return get_sensitivities(
            report.get("insulin_sensitivity_factor_schedule"))
Пример #18
0
    def load_report_carb_values(self, report_name):
        """ Load the carb entries from an issue report """
        report = load_fixture(report_name, ".json")

        if not report.get("cached_carb_entries"):
            print("Issue report contains no carb information")
            return ([], [])

        return get_carb_data(report.get("cached_carb_entries"))
Пример #19
0
    def load_history_fixture(self, name):
        """ Load carb history from json file

        Argument:
        name -- name of file, without .json extension

        Output:
        3 lists in (carb_values, carb_start_dates, carb_absorption_times)
        format
        """
        fixture = load_fixture(name, ".json")
        return self.carb_entries_from_fixture(fixture)
Пример #20
0
    def load_carb_ratios(self):
        """ Load carb ratios from json file

        Output:
        2 lists in (ratio_start_time, ratio (in units/insulin),
                    length_of_rate) format
        """
        schedule = load_fixture("read_carb_ratios", ".json").get("schedule")

        carb_sched_starts = [
            time.fromisoformat(dict_.get("start")) for dict_ in schedule
        ]
        carb_sched_ratios = [dict_.get("ratio") for dict_ in schedule]

        return (carb_sched_starts, carb_sched_ratios)
Пример #21
0
    def load_schedules(self):
        """ Load the carb schedule

        Output:
        2 lists in (schedule_offsets, carb_ratios) format
        """
        schedule = load_fixture("read_carb_ratios", ".json").get("schedule")

        carb_sched_starts = [
            time.fromisoformat(dict_.get("start"))
            for dict_ in schedule
        ]
        carb_sched_ratios = [dict_.get("ratio") for dict_ in schedule]

        return (carb_sched_starts, carb_sched_ratios)
Пример #22
0
    def load_glucose_value_fixture(self, name):
        """ Load glucose effects from json file

        Output:
        2 lists in (date, glucose_value) format
        """
        fixture = load_fixture(name, ".json")

        dates = [
            datetime.fromisoformat(dict_.get("date")) for dict_ in fixture
        ]
        glucose_values = [dict_.get("amount") for dict_ in fixture]

        assert len(dates) == len(glucose_values),\
            "expected output shape to match"

        return (dates, glucose_values)
Пример #23
0
    def load_dose_fixture(self, resource_name):
        """ Load dose from json file

        Arguments:
        resource_name -- name of file without the extension

        Output:
        5 lists in (dose_type (basal/bolus), start_dates, end_dates,
                    values (in units/insulin), scheduled_basal_rates) format
        """
        fixture = load_fixture(resource_name, ".json")

        dose_types = [
            DoseType.from_str(
                dict_.get("type")
            ) or "!" for dict_ in fixture
        ]
        start_dates = [
            datetime.fromisoformat(dict_.get("start_at"))
            for dict_ in fixture
        ]
        end_dates = [
            datetime.fromisoformat(dict_.get("end_at"))
            for dict_ in fixture
        ]
        values = [dict_.get("amount") for dict_ in fixture]
        # not including description, unit, and raw bc not relevent
        scheduled_basal_rates = [
            dict_.get("scheduled") or 0 for dict_ in fixture
        ]

        assert len(dose_types) == len(start_dates) == len(end_dates) ==\
            len(values) == len(scheduled_basal_rates),\
            "expected output shape to match"
        # if dose_type doesn't exist (meaning there's an "!"), remove entry
        if "!" in dose_types:
            for i in range(0, len(dose_types)):
                if dose_types[i] == "!":
                    del dose_types[i]
                    del start_dates[i]
                    del end_dates[i]
                    del values[i]
                    del scheduled_basal_rates[i]

        return (dose_types, start_dates, end_dates, values,
                scheduled_basal_rates)
def load_glucose_effect_fixture(resource_name):
    """ Load glucose effects from json file

    Arguments:
    resource_name -- name of file without the extension

    Output:
    2 lists in (date, glucose_value) format
    """
    fixture = load_fixture(resource_name, ".json")

    dates = [datetime.fromisoformat(dict_.get("date"))
             for dict_ in fixture]
    glucose_values = [dict_.get("amount") for dict_ in fixture]

    assert len(dates) == len(glucose_values),\
        "expected output shape to match"
    return (dates, glucose_values)
def load_insulin_value_fixture(resource_name):
    """ Load insulin values from json file

    Arguments:
    resource_name -- name of file without the extension

    Output:
    2 lists in (start_date, insulin_amount) format
    """
    fixture = load_fixture(resource_name, ".json")

    start_dates = [datetime.fromisoformat(dict_.get("date"))
                   for dict_ in fixture]
    insulin_values = [dict_.get("value") for dict_ in fixture]

    assert len(start_dates) == len(insulin_values),\
        "expected output shape to match"

    return (start_dates, insulin_values)
Пример #26
0
    def basal_rate_schedule(self):
        """ Load basal schedule

        Output:
        3 lists in (rate_start_time, rate (in Units/insulin),
                    length_of_rate) format
        """
        fixture = load_fixture("read_selected_basal_profile", ".json")

        start_times = [
            datetime.strptime(dict_.get("start"), "%H:%M:%S").time()
            for dict_ in fixture
        ]
        rates = [dict_.get("rate") for dict_ in fixture]
        minutes = [dict_.get("minutes") for dict_ in fixture]

        assert len(start_times) == len(rates) == len(minutes),\
            "expected output shape to match"

        return (start_times, rates, minutes)
Пример #27
0
    def load_cob_output_fixture(self, name):
        """ Load COB from json file

        Arguments:
        name -- name of file without the extension

        Output:
        2 lists in (date, cob_value) format
        """
        fixture = load_fixture(name, ".json")

        dates = [
            datetime.fromisoformat(dict_.get("date"))
            for dict_ in fixture
        ]
        cob_values = [dict_.get("amount") for dict_ in fixture]

        assert len(dates) == len(cob_values),\
            "expected output shape to match"

        return (dates, cob_values)
Пример #28
0
    def load_carb_data(self, resource_name):
        """ Load carb entries data from json file

        Arguments:
        resource_name -- name of file without the extension

        Output:
        3 lists in (carb_values, carb_start_dates, carb_absorption_times)
        format
        """
        data = load_fixture(resource_name, ".json")

        carb_values = [dict_.get("amount") for dict_ in data]
        start_dates = [
            datetime.fromisoformat(dict_.get("start_at")) for dict_ in data
        ]
        absorption_times = [
            dict_.get("absorption_time")
            if dict_.get("absorption_time") else None for dict_ in data
        ]

        return (start_dates, carb_values, absorption_times)
Пример #29
0
    def load_basal_rate_schedule_fixture(self, resource_name):
        """ Load basal schedule from json file

        Arguments:
        resource_name -- name of file without the extension

        Output:
        3 lists in (rate_start_time, rate (in units/insulin),
                    length_of_rate) format
        """
        fixture = load_fixture(resource_name, ".json")

        start_times = [
            datetime.strptime(dict_.get("start"), "%H:%M:%S").time()
            for dict_ in fixture
        ]
        rates = [dict_.get("rate") for dict_ in fixture]
        minutes = [dict_.get("minutes") for dict_ in fixture]

        assert len(start_times) == len(rates) == len(minutes),\
            "expected output shape to match"

        return (start_times, rates, minutes)
Пример #30
0
    def load_sample_value_fixture(self, name):
        """ Load sample values from json file

        Output:
        2 lists in (date, glucose_value) format
        """
        fixture = load_fixture(
            name,
            ".json"
        )

        dates = [
            datetime.strptime(
                dict_.get("startDate"),
                "%Y-%m-%dT%H:%M:%S%z"
            )
            for dict_ in fixture
        ]
        glucose_values = [dict_.get("value") for dict_ in fixture]

        assert len(dates) == len(glucose_values),\
            "expected output shape to match"

        return (dates, glucose_values)