Exemple #1
0
    def test_sga_multi_bins(self):
        exp = self.getExperiment([self.derived_kpi_1['name']],
                                 [self.derived_kpi_1])
        dimension_to_bin = {
            "normal_same": [
                Bin("numerical", 1, 2, True, False),
                Bin("numerical", 2, 3, True, False)
            ]
        }
        sga_result = exp.sga(dimension_to_bin)

        self.assertEqual(len(sga_result), 2)
        dimension_name = find_list_of_dicts_element(sga_result, "segment",
                                                    "[1, 2)", "dimension")
        self.assertEqual(dimension_name, 'normal_same')
Exemple #2
0
 def test_sga_invalid_bin_list_type(self):
     exp = self.getExperiment([self.derived_kpi_1['name']],
                              [self.derived_kpi_1])
     dimension_to_bin = {"normal_same": Bin("numerical", 1, 10, True, True)}
     with self.assertRaisesRegexp(
             TypeError,
             "Value of the input dict needs to be a list of Bin objects."):
         exp.sga(dimension_to_bin)
 def test_sga_invalid_dimension_name(self):
     exp = self.getExperiment([self.derived_kpi_1['name']],
                              [self.derived_kpi_1])
     dimension_to_bin = {
         "dimension_does_not_exist": [Bin("numerical", 1, 10, True, True)]
     }
     with self.assertRaises(KeyError):
         exp.sga(dimension_to_bin)
Exemple #4
0
 def test_sga_invalid_dimension_type(self):
     exp = self.getExperiment([self.derived_kpi_1['name']],
                              [self.derived_kpi_1])
     dimension_to_bin = {123: [Bin("numerical", 1, 10, True, True)]}
     with self.assertRaisesRegexp(
             TypeError,
             "Key of the input dict needs to be string, indicating the name of dimension."
     ):
         exp.sga(dimension_to_bin)
Exemple #5
0
    def test_sga_one_bin(self):
        exp = self.getExperiment([self.derived_kpi_1['name']],
                                 [self.derived_kpi_1])
        dimension_to_bin = {
            "normal_same": [Bin("numerical", 1, 10, True, True)]
        }
        sga_result = exp.sga(dimension_to_bin)

        self.assertEqual(len(sga_result), 1)
        subgroup_res = sga_result[0]
        self.assertEqual(subgroup_res['dimension'], 'normal_same')
        self.assertEqual(subgroup_res['segment'], '[1, 10]')
        self.assertTrue("result" in subgroup_res)
Exemple #6
0
 def test_sga_not_valid_data_for_one_subgroup(self):
     '''
     It should not raise error if there is not enough data in one subgroup,
     which means one subgroup might contain zero or only one variant. (e.g. "browser" = "hack name")
     
     sga should ignore this subgroup and continue doing analysis with other subgroups.
     '''
     exp = self.getExperiment([self.derived_kpi_1['name']],
                              [self.derived_kpi_1])
     dimension_to_bin = {
         "normal_same": [
             Bin("numerical", 1, 2, True, False),
             Bin("numerical", 2, 3, True, False),
             Bin("numerical", 999998, 999999, False, False)
         ],  # bin which does not have any data
         "feature": [
             Bin("categorical", ["has"]),
             Bin("categorical", ["non"]),
             Bin("categorical", ["feature that only has one data point"
                                 ])  # bin which has only one data point
         ]
     }
     sga_result = exp.sga(dimension_to_bin)
     self.assertEqual(len(sga_result), 4)
 def test_sga_invalid_dimension_type(self):
     exp = self.getExperiment([self.derived_kpi_1['name']],
                              [self.derived_kpi_1])
     dimension_to_bin = {123: [Bin("numerical", 1, 10, True, True)]}
     with self.assertRaises(TypeError):
         exp.sga(dimension_to_bin)
 def test_sga_invalid_bin_list(self):
     exp = self.getExperiment([self.derived_kpi_1['name']],
                              [self.derived_kpi_1])
     dimension_to_bin = {"normal_same": Bin("numerical", 1, 10, True, True)}
     with self.assertRaises(TypeError):
         exp.sga(dimension_to_bin)