def test_momentum_effect_for_too_few_glucose(self): (i_date_list, i_glucose_list, display_list, providence_list ) = self.load_input_fixture("momentum_effect_bouncing_glucose_input") glucose_effect_dates = linear_momentum_effect(i_date_list[0:1], i_glucose_list[0:1], display_list[0:1], providence_list[0:1])[0] self.assertEqual(0, len(glucose_effect_dates))
def test_momentum_effect_for_duplicate_glucose(self): (i_date_list, i_glucose_list, display_list, providence_list ) = self.load_input_fixture("momentum_effect_duplicate_glucose_input") glucose_effect_dates = linear_momentum_effect(i_date_list, i_glucose_list, display_list, providence_list)[0] self.assertEqual(0, len(glucose_effect_dates))
def test_momentum_effect_for_bouncing_glucose(self): (i_date_list, i_glucose_list, display_list, providence_list ) = self.load_input_fixture("momentum_effect_bouncing_glucose_input") (expected_date_list, expected_glucose_list) = self.load_output_fixture( "momentum_effect_bouncing_glucose_output") (glucose_effect_dates, glucose_effect_values) = linear_momentum_effect( i_date_list, i_glucose_list, display_list, providence_list) self.assertEqual(len(expected_date_list), len(glucose_effect_dates)) for i in range(0, len(expected_date_list)): self.assertEqual(expected_date_list[i], glucose_effect_dates[i]) self.assertAlmostEqual(glucose_effect_values[i], expected_glucose_list[i], 2)
def get_recent_momentum_effects(glucose_starts, glucose_values, start_date, now_date, momentum_data_interval=15, delta=5, display_list=None, provenances=None): """ Get glucose momentum 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 start calculating momentum effects now_date -- the date to assume as the "now" time (aka datetime.now()) momentum_data_interval -- time to generate momentum effects out to (mins) delta -- time between blood glucose measurements (mins) display_list -- list of display_only booleans provenances -- list of provenances (Strings) Output: Momentum effects in format (date_of_effect, value_of_effect) """ assert len(glucose_starts) == len(glucose_values),\ "expected input shapes to match" if not glucose_starts or not start_date: return ([], []) (filtered_dates, ends, filtered_values) = filter_date_range( glucose_starts, [], glucose_values, now_date - timedelta(minutes=momentum_data_interval), None) if not display_list: display_list = [False for i in filtered_dates] if not provenances: provenances = ["PyLoop" for i in filtered_dates] effects = linear_momentum_effect(filtered_dates, filtered_values, display_list, provenances, momentum_data_interval, delta) return effects
def test_momentum_effect_for_empty_glucose(self): glucose_effect_dates = linear_momentum_effect([], [], [], [])[0] self.assertEqual(0, len(glucose_effect_dates))