Example #1
0
 def test_eA1c_mmol_equal_mg(self):
     self.simple_df[GLUCOSE] = len(self.simple_df) * [100]
     simple_df_mmol = self.simple_df.copy()
     simple_df_mmol[GLUCOSE] = simple_df_mmol[GLUCOSE] / 18.02
     index_mg = indices.GVeA1c(df=self.simple_df,
                               calc_config=self.mock_5_mg_config)
     index_mmol = indices.GVeA1c(df=simple_df_mmol,
                                 calc_config=self.mock_5_mmol_config)
     self.assertAlmostEqual(
         index_mg.calculate(),
         index_mmol.calculate(),
         msg="\neA1c based on mg: {}. eA1c based on mmol: {}\n".format(
             index_mg.calculate(), index_mmol.calculate()))
Example #2
0
 def test_mage_join_extremas_minimas_first(self):
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     minimas = [1, 3, 5]
     maximas = [2, 4, 6]
     self.assertListEqual(list1=[1, 2, 3, 4, 5, 6],
                          list2=index._join_extremas(minimas, maximas))
Example #3
0
 def test_mage_moving_average_window_not_int(self):
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     arr = pd.Series([1, 3, 4, 6, 7])
     window_size = "test"
     with self.assertRaises(ValueError):
         index._moving_average(arr, window_size)
Example #4
0
 def test_mage_moving_average_arr_not_series(self):
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     arr = [1, 3, 4, 6, 7]
     window_size = 2
     with self.assertRaises(ValueError):
         index._moving_average(arr, window_size)
Example #5
0
 def test_mage_moving_average_simple_array(self):
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     arr = pd.Series([1, 3, 4, 6, 7])
     window_size = 2
     self.assertTrue(
         np.array_equal(index._moving_average(arr, window_size),
                        np.array([2, 3.5, 5, 6.5])))
Example #6
0
 def test_mage_join_extremas_util_maximas_first(self):
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     minimas = [2, 4, 6]
     maximas = [1, 3, 5]
     joined = [1]
     minimas_turn = True
     index._join_extremas_util(joined, minimas, maximas, 0, 1, minimas_turn)
     self.assertListEqual(list1=[1, 2, 3, 4, 5, 6], list2=joined)
Example #7
0
 def test_mage_join_extremas_util_different_lengths_arrays(self):
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     minimas = [1, 3, 5]
     maximas = [2, 4, 6, 7]
     joined = [1]
     minimas_turn = False
     index._join_extremas_util(joined, minimas, maximas, 1, 0, minimas_turn)
     self.assertListEqual(list1=[1, 2, 3, 4, 5, 6], list2=joined)
Example #8
0
 def test_mean_hypo_event_duration_no_hypo(self):
     self.simple_df = pd.DataFrame({
         DT:
         pd.date_range(start="27-07-2020 12:00", periods=8, freq="5min"),
         GLUCOSE: [10, 10, 10, 0, 0, 10, 10, 10]
     })
     index = indices.GVmean_hypo_event_duration(
         df=self.simple_df, calc_config=self.mock_5_mg_config)
     self.assertEqual(first=index.calculate(threshold=9,
                                            records_duration=15),
                      second=0)
Example #9
0
 def test_conga_all_values_the_same(self):
     # Variance should obviously be 0 for a measurement
     # made up of all the same values
     dates = pd.date_range("12:00 2020/09/11", periods=500, freq="5min")
     values = np.repeat(100, repeats=500)
     test_df = pd.DataFrame({GLUCOSE: values}, index=dates)
     index = indices.GVcongaX(df=test_df, calc_config=self.mock_5_mg_config)
     self.assertEqual(
         0,
         index.calculate(2),
         msg="Returned: {}. Expected 0".format(index.calculate(2)),
     )
Example #10
0
 def test_mage_join_extremas_minimas_doubled(self):
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     minimas = [1, 3, 5]
     maximas = [2, 6]
     self.assertListEqual(
         list1=[1, 2, 3, 6],
         list2=index._join_extremas(minimas, maximas),
         msg="_join_extremas returned: {}, expected: {}".format(
             index._join_extremas(minimas, maximas),
             [1, 2, 3, 6],
         ))
Example #11
0
 def test_mage_runtime_error(self):
     # integration test in fact
     self.simple_df = pd.DataFrame({
         DT:
         pd.date_range(start="27-07-2020 12:00", periods=50, freq="5min"),
         GLUCOSE:
         50 * [100]
     })
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     with self.assertRaises(RuntimeError):
         index.calculate()
Example #12
0
 def test_mage_basic_df(self):
     # integration test in fact
     self.simple_df = pd.DataFrame({
         DT:
         pd.date_range(start="27-07-2020 12:00", periods=50, freq="5min"),
         GLUCOSE:
         50 * [100]
     })
     self.simple_df.iloc[10, 1] = 50
     self.simple_df.iloc[20, 1] = 50
     self.simple_df.iloc[30, 1] = 300
     self.simple_df.iloc[40, 1] = 200
     index = indices.GVmage(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     self.assertEqual(first=index.calculate(), second=0)
Example #13
0
    def test_modd_simple_examples(self):
        same_values = pd.DataFrame({
            DT:
            pd.date_range(start="10/11/2020 12:00",
                          periods=3 * 256,
                          freq="5min"),
            GLUCOSE:
            3 * 256 * [100],
        })

        index = indices.GVmodd(df=same_values,
                               calc_config=self.mock_5_mg_config)
        self.assertEqual(
            index.calculate(),
            0,
            msg="Expected 0 for the array of all equal values. Returned: {}\n".
            format(index.calculate()))
Example #14
0
 def test_set_calc_config_not_calcconfig(self):
     with self.assertRaises(ValueError):
         indices.GVIndex(df=self.simple_df, calc_config="wrong_class")
Example #15
0
 def test_call_df_not_pandas(self):
     with self.assertRaises(ValueError):
         test_ind = indices.GVIndex(df=self.simple_df,
                                    calc_config=self.mock_5_mg_config)
         indices.GVIndex.__call__(test_ind, df="test")
Example #16
0
 def test_set_df_not_pandas(self):
     with self.assertRaises(ValueError):
         indices.GVIndex(df="test", calc_config=self.mock_5_mg_config)
Example #17
0
 def test_calculate_not_implemented(self):
     with self.assertRaises(NotImplementedError):
         indices.GVIndex(df=self.simple_df,
                         calc_config=self.mock_5_mg_config).calculate()
Example #18
0
 def test_hbgi(self):
     index = indices.GVhbgi(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     self.assertAlmostEqual(first=0, second=index.calculate())
Example #19
0
 def test_lbgi(self):
     index = indices.GVlbgi(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     self.assertAlmostEqual(first=567.362808824868,
                            second=index.calculate())
Example #20
0
 def test_mean_hypo_event_duration_records_duration(self):
     index = indices.GVmean_hypo_event_duration(
         df=self.simple_df, calc_config=self.mock_5_mg_config)
     with self.assertRaises(ValueError):
         index.calculate(threshold=0, records_duration="wrong_type")
Example #21
0
 def test_time_in_hypo_value_error(self):
     index = indices.GVtime_in_hypo(df=self.simple_df,
                                    calc_config=self.mock_5_mg_config)
     with self.assertRaises(ValueError):
         index.calculate(threshold="test")
Example #22
0
 def test_time_in_hypo(self):
     index = indices.GVtime_in_hypo(df=self.simple_df,
                                    calc_config=self.mock_5_mg_config)
     self.assertEqual(first=index.calculate(threshold=3), second=10)
Example #23
0
 def test_hypo_events_count_threshold_duration_not_int(self):
     index = indices.GVhypo_events_count(df=self.simple_df,
                                         calc_config=self.mock_5_mg_config)
     with self.assertRaises(ValueError):
         index.calculate(threshold=0, threshold_duration="test")
Example #24
0
 def test_call_self_calculate_on_call(self):
     with self.assertRaises(NotImplementedError):
         base_index = indices.GVIndex(calc_config=self.mock_5_mg_config)
         base_index(self.simple_df)
Example #25
0
 def test_eA1c_simple_df(self):
     self.simple_df[GLUCOSE] = len(self.simple_df) * [100]
     index = indices.GVeA1c(df=self.simple_df,
                            calc_config=self.mock_5_mg_config)
     self.assertAlmostEqual(first=index.calculate(),
                            second=5.09752973287909)
Example #26
0
 def test_grade_hyper_mmol(self):
     self.simple_df[GLUCOSE] = len(self.simple_df) * [15]
     index = indices.GVgrade_hyper(df=self.simple_df,
                                   calc_config=self.mock_5_mmol_config)
     self.assertAlmostEqual(first=index.calculate(), second=1)
Example #27
0
 def test_auc_simple_df_no_stand(self):
     # test on a df with all 1s
     self.simple_df[GLUCOSE] = len(self.simple_df) * [1]
     index = indices.GVauc(df=self.simple_df,
                           calc_config=self.mock_5_mg_config)
     self.assertEqual(index.calculate(standardize=False), 20)
Example #28
0
 def test_time_in_range_value_error2(self):
     index = indices.GVtime_in_range(df=self.simple_df,
                                     calc_config=self.mock_5_mg_config)
     with self.assertRaises(ValueError):
         index.calculate(lower_bound="test", upper_bound=1)
Example #29
0
 def test_hypo_events_count_simple_df(self):
     self.simple_df[GLUCOSE] = [1, 1, 3, 2, 2]
     index = indices.GVhypo_events_count(df=self.simple_df,
                                         calc_config=self.mock_5_mg_config)
     self.assertEqual(index.calculate(threshold=3, threshold_duration=10),
                      2)
Example #30
0
 def test_time_in_range_accept_floats(self):
     index = indices.GVtime_in_range(df=self.simple_df,
                                     calc_config=self.mock_5_mg_config)
     self.assertEqual(index.calculate(lower_bound=1.0, upper_bound=5.0),
                      0.6)