Ejemplo n.º 1
0
 def test_facet_score(self):
     """
     Tests Scorer.facet_score
     :return:
     """
     wildcards = ["Unspecified", "Wildcard"]
     warn_value = "Fred"
     gsr_value = "Ethel"
     expected = 0
     result = Scorer.facet_score(warn_value, gsr_value, wildcards)
     self.assertEqual(result, expected)
     gsr_value = wildcards[0]
     expected = 1
     result = Scorer.facet_score(warn_value, gsr_value, wildcards)
     self.assertEqual(result, expected)
     gsr_value = wildcards[1]
     expected = 1
     result = Scorer.facet_score(warn_value, gsr_value, wildcards)
     self.assertEqual(result, expected)
     warn_value = wildcards[0]
     gsr_value = "Ethel"
     expected = 0
     result = Scorer.facet_score(warn_value, gsr_value, wildcards)
     self.assertEqual(result, expected)
     warn_value = "Fred"
     gsr_value = ["Ethel", "Fred"]
     expected = 1
     result = Scorer.facet_score(warn_value, gsr_value, wildcards)
     self.assertEqual(result, expected)
Ejemplo n.º 2
0
    def test_date_score(self):

        date_diffs = range(-6, 7)
        results = [Scorer.date_score(dd) for dd in date_diffs]
        expected = [0, 0, 0, .25, .5, .75, 1, .75, .5, .25, 0, 0, 0]
        for i, e in enumerate(expected):
            self.assertAlmostEqual(results[i], e, 3)
        max_date_diff = 5
        results = [Scorer.date_score(dd, max_date_diff) for dd in date_diffs]
        expected = [0, 0, .2, .4, .6, .8, 1, .8, .6, .4, .2, 0, 0]
        for i, e in enumerate(expected):
            self.assertAlmostEqual(results[i], e, 3)
Ejemplo n.º 3
0
 def test_make_index_mats(self):
     """
     Tests Scorer.make_index_mats method
     :return:
     """
     row_names = ["a", "b", "c", "d"]
     row_indices = list(range(len(row_names)))
     col_names = ["x", "y", "z"]
     col_indices = list(range(len(col_names)))
     row_array = np.array(row_indices * 3).reshape(3, 4).T
     col_array = np.array(col_indices * 4).reshape(4, 3)
     results = Scorer.make_index_mats(row_names, col_names)
     try:
         np.testing.assert_equal(row_array, results[0])
         test_res = True
     except AssertionError as e:
         test_res = False
         print(repr(e))
     self.assertTrue(test_res)
     try:
         np.testing.assert_equal(col_array, results[1])
         test_res = True
     except AssertionError as e:
         test_res = False
         print(repr(e))
     self.assertTrue(test_res)
Ejemplo n.º 4
0
    def test_date_diff(self):

        # Test when both are 0
        warn_date = "2018-06-22"
        gsr_date_range = pd.date_range("2018-06-17", "2018-06-27")
        gsr_dates = [d.strftime("%Y-%m-%d") for d in gsr_date_range]
        expected_values = range(-5, 6)
        for i, d in enumerate(gsr_dates):
            result = Scorer.date_diff(warn_date, d)
            expected = expected_values[i]
            self.assertAlmostEqual(result, expected)
Ejemplo n.º 5
0
 def test_slope_score(self):
     min_value = 0
     max_value = 100
     too_low = -5
     too_high = 105
     just_right = 50
     result = Scorer.slope_score(too_low, min_value, max_value)
     self.assertAlmostEqual(result, 1)
     result = Scorer.slope_score(min_value, min_value, max_value)
     self.assertAlmostEqual(result, 1)
     result = Scorer.slope_score(just_right, min_value, max_value)
     self.assertAlmostEqual(result, 0.5)
     result = Scorer.slope_score(max_value, min_value, max_value)
     self.assertAlmostEqual(result, 0)
     result = Scorer.slope_score(too_high, min_value, max_value)
     self.assertAlmostEqual(result, 0)
     self.assertRaises(ValueError, Scorer.slope_score, just_right,
                       min_value, min_value)
     self.assertRaises(ValueError, Scorer.slope_score, just_right,
                       max_value, min_value)
Ejemplo n.º 6
0
    def test_f1(self):
        """
        Tests Scorer.f1
        :return:
        """
        p, r = (0, 0)
        expected = 0
        result = Scorer.f1(p, r)
        self.assertAlmostEqual(result, expected, 3)

        p, r = (1, 1)
        expected = 1
        result = Scorer.f1(p, r)
        self.assertAlmostEqual(result, expected, 3)

        p, r = (1, 1)
        expected = 1
        result = Scorer.f1(p, r)
        self.assertAlmostEqual(result, expected, 3)

        p, r = (.5, .5)
        expected = .5
        result = Scorer.f1(p, r)
        self.assertAlmostEqual(result, expected, 3)

        p, r = (0, 1)
        expected = 0
        result = Scorer.f1(p, r)
        self.assertAlmostEqual(result, expected, 3)

        p, r = (.25, .75)
        expected = 0.375
        result = Scorer.f1(p, r)
        self.assertAlmostEqual(result, expected, 3)

        p, r = (-.5, 1)
        self.assertRaises(ValueError, Scorer.f1, p, r)

        p, r = (2, 1)
        self.assertRaises(ValueError, Scorer.f1, p, r)

        p, r = (.5, -.1)
        self.assertRaises(ValueError, Scorer.f1, p, r)

        p, r = (.5, 2)
        self.assertRaises(ValueError, Scorer.f1, p, r)