Esempio n. 1
0
 def __init__(self, data_provider, output):
     self.data_provider = data_provider
     self.output = output
     self.project_name = data_provider.project_name
     self.session_uid = self.data_provider.session_uid
     self.tool_box = PEPSICOUKToolBox(self.data_provider, self.output)
     self.common = Common(data_provider)
Esempio n. 2
0
 def test_get_relevant_sos_vs_target_kpi_targets_get_relevant_rows_for_brand_vs_brand(self):
     self.mock_scene_item_facts(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='scif'))
     self.mock_match_product_in_scene(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='matches'))
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     targets = tool_box.get_relevant_sos_vs_target_kpi_targets(brand_vs_brand=True)
     expected_list_of_target_rows = [28, 29]
     self.assertItemsEqual(expected_list_of_target_rows, targets['pk'].values.tolist())
Esempio n. 3
0
 def test_calculate_hero_sku_stacking_layer_more_than_one_if_sku_not_stacked(self):
     matches, scif = self.create_scif_matches_data_mocks_selected_scenes(DataTestUnitPEPSICOUK.test_case_1, [2])
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     sku = 2
     kpi_fk = 315
     tool_box.calculate_hero_sku_stacking_layer_more_than_one(sku, kpi_fk)
     expected_list = list()
     expected_list.append({'kpi_fk': 315, 'numerator': 2, 'result': 0, 'score': 0})
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(self.check_kpi_results(tool_box.kpi_results_check, expected_result) == 1)
     self.assertTrue(all(test_result_list))
Esempio n. 4
0
 def test_calculate_hero_sku_stacking_by_sequence_number_returns_zero_results_if_no_stacked_products(self):
     matches, scif = self.create_scif_matches_data_mocks_selected_scenes(DataTestUnitPEPSICOUK.test_case_1, [2])
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     tool_box.calculate_hero_sku_stacking_by_sequence_number()
     expected_skus_in_results = [1, 2]
     self.assertItemsEqual(tool_box.kpi_results_check['numerator'].unique().tolist(), expected_skus_in_results)
     self.assertEquals(len(tool_box.kpi_results_check), 2)
     expected_list = list()
     expected_list.append({'kpi_fk': 315, 'numerator': 1, 'result': 5, 'score': 0})
     expected_list.append({'kpi_fk': 315, 'numerator': 2, 'result': 5, 'score': 0})
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(self.check_kpi_results(tool_box.kpi_results_check, expected_result) == 1)
     self.assertTrue(all(test_result_list))
Esempio n. 5
0
 def test_calculate_hero_sku_stacking_by_sequence_number(self):
     self.mock_scene_item_facts(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='scif'))
     self.mock_match_product_in_scene(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='matches'))
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     tool_box.calculate_hero_sku_stacking_by_sequence_number()
     expected_skus_in_results = [1, 2]
     self.assertItemsEqual(tool_box.kpi_results_check['numerator'].unique().tolist(), expected_skus_in_results)
     self.assertEquals(len(tool_box.kpi_results_check), 2)
     expected_list = list()
     expected_list.append({'kpi_fk': 315, 'numerator': 1, 'result': 4, 'score': 1})
     expected_list.append({'kpi_fk': 315, 'numerator': 2, 'result': 4, 'score': 1})
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(self.check_kpi_results(tool_box.kpi_results_check, expected_result) == 1)
     self.assertTrue(all(test_result_list))
Esempio n. 6
0
 def test_sos_brand_vs_brand(self):
     self.mock_scene_item_facts(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='scif'))
     self.mock_match_product_in_scene(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='matches'))
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     tool_box.calculate_linear_brand_vs_brand_index()
     expected_list = list()
     expected_list.append({'kpi_fk': 301, 'numerator': 194, 'denominator': 183, 'score': 0})
     expected_list.append({'kpi_fk': 302, 'numerator': 136, 'denominator': 189, 'score':
                                                                                     round((float(60)/195)/(float(135)/195), 5)})
     expected_list.append({'kpi_fk': 303, 'numerator': 2, 'score': 1})
     kpi_results = tool_box.kpi_results_check
     kpi_results['score'] = kpi_results['score'].apply(lambda x: round(x, 5))
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(self.check_kpi_results(kpi_results, expected_result) == 1)
     self.assertTrue(all(test_result_list))
Esempio n. 7
0
 def test_calculate_brand_full_bay_if_relevant_scenes_exist_in_session(self):
     self.mock_scene_item_facts(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='scif'))
     self.mock_match_product_in_scene(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='matches'))
     # self.mock_scene_info(DataTestUnitPEPSICOUK.scene_info)
     # self.mock_scene_kpi_results(DataTestUnitPEPSICOUK.scene_kpi_results_test_case_1)
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     tool_box.calculate_brand_full_bay()
     expected_list = list()
     expected_list.append({'kpi_fk': 316, 'numerator': 167, 'score': 0})
     expected_list.append({'kpi_fk': 327, 'numerator': 167, 'score': 1})
     expected_list.append({'kpi_fk': 316, 'numerator': 168, 'score': 0})
     expected_list.append({'kpi_fk': 327, 'numerator': 168, 'score': 0})
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(self.check_kpi_results(tool_box.kpi_results_check, expected_result) == 1)
     self.assertTrue(all(test_result_list))
     self.assertTrue(len(tool_box.kpi_results_check), 4)
Esempio n. 8
0
 def test_assortment_kpi_is_calculated_correctly(self):
     self.mock_scene_item_facts(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='scif'))
     self.mock_match_product_in_scene(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='matches'))
     self.mock_scene_info(DataTestUnitPEPSICOUK.scene_info)
     self.mock_scene_kpi_results(DataTestUnitPEPSICOUK.scene_kpi_results_test_case_1)
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     tool_box.calculate_assortment()
     expected_list = []
     expected_list.append({'kpi_fk': 290, 'numerator': 1, 'result': 4, 'score': 100})
     expected_list.append({'kpi_fk': 290, 'numerator': 2, 'result': 4, 'score': 100})
     expected_list.append({'kpi_fk': 290, 'numerator': 5, 'result': 5, 'score': 0})
     expected_list.append({'kpi_fk': 289, 'numerator': 2, 'result': round(2.0 / 3 * 100, 5), 'score': 0})
     kpi_results = tool_box.kpi_results_check
     kpi_results['result'] = kpi_results['result'].apply(lambda x: round(x, 5))
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(self.check_kpi_results(kpi_results, expected_result) == 1)
     self.assertTrue(all(test_result_list))
Esempio n. 9
0
 def test_assortment_result_is_calculated(self):
     self.mock_scene_item_facts(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='scif'))
     self.mock_match_product_in_scene(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='matches'))
     self.mock_scene_info(DataTestUnitPEPSICOUK.scene_info)
     self.mock_scene_kpi_results(DataTestUnitPEPSICOUK.scene_kpi_results_test_case_1)
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     # tool_box.calculate_assortment() # complete mock data later
     expected_result = pd.DataFrame.from_records([
         {'in_store': 1, 'product_fk': 1}, {'in_store': 1, 'product_fk': 2}, {'in_store': 0, 'product_fk': 5}
     ])
     assert_frame_equal(expected_result, tool_box.lvl3_ass_result[['in_store', 'product_fk']])
Esempio n. 10
0
class Generator:
    def __init__(self, data_provider, output):
        self.data_provider = data_provider
        self.output = output
        self.project_name = data_provider.project_name
        self.session_uid = self.data_provider.session_uid
        self.tool_box = PEPSICOUKToolBox(self.data_provider, self.output)
        self.common = Common(data_provider)

    @log_runtime('Total Calculations', log_start=True)
    def main_function(self):
        """
        This is the main KPI calculation function.
        It calculates the score for every KPI set and saves it to the DB.
        """
        if self.tool_box.scif.empty:
            Log.warning('Scene item facts is empty for this session')
        else:
            self.tool_box.main_calculation()
            self.tool_box.common.commit_results_data()
Esempio n. 11
0
    def test_reset_filtered_scif_and_matches_to_exclusion_all_state(self):
        self.mock_scene_item_facts(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='scif'))
        self.mock_match_product_in_scene(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='matches'))
        tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
        initial_filtered_matches_l = len(tool_box.filtered_matches)
        initial_filtered_scif_l = len(tool_box.filtered_scif)
        tool_box.filtered_scif, tool_box.filtered_matches = \
            tool_box.commontools.set_filtered_scif_and_matches_for_specific_kpi(tool_box.filtered_scif, tool_box.filtered_matches,
                                                                                'Brand Space to Sales Index')
        kpi_filtered_matches_l = len(tool_box.filtered_matches)
        kpi_filtered_scif_l = len(tool_box.filtered_scif)
        tool_box.reset_filtered_scif_and_matches_to_exclusion_all_state()
        reset_to_initial_filtered_matches_l = len(tool_box.filtered_matches)
        reset_to_initial_filtered_scif_l = len(tool_box.filtered_scif)

        self.assertEquals(kpi_filtered_matches_l, 30)
        self.assertEquals(initial_filtered_matches_l, reset_to_initial_filtered_matches_l)
        self.assertEquals(reset_to_initial_filtered_matches_l, 39)
        self.assertEquals(kpi_filtered_scif_l, 5)
        self.assertEquals(initial_filtered_scif_l, reset_to_initial_filtered_scif_l)
        self.assertEquals(reset_to_initial_filtered_scif_l, 7)
Esempio n. 12
0
    def test_calculate_hero_shelf_placement_horizontal(self):
        self.mock_scene_item_facts(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='scif'))
        self.mock_match_product_in_scene(pd.read_excel(DataTestUnitPEPSICOUK.test_case_1, sheetname='matches'))
        self.mock_scene_info(DataTestUnitPEPSICOUK.scene_info)
        self.mock_scene_kpi_results(DataTestUnitPEPSICOUK.scene_kpi_results_test_case_1)
        tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
        tool_box.calculate_shelf_placement_hero_skus()
        expected_list = []
        expected_list.append({'kpi_fk': 311, 'numerator': 1, 'result': round(7.0*100 / 12, 5)})
        expected_list.append({'kpi_fk': 312, 'numerator': 1, 'result': round(3.0*100 / 12, 5)})
        expected_list.append({'kpi_fk': 314, 'numerator': 1, 'result': round(2.0*100 / 12, 5)})
        expected_list.append({'kpi_fk': 314, 'numerator': 2, 'result': round(2.0*100 / 12, 5)})
        expected_list.append({'kpi_fk': 313, 'numerator': 2, 'result': round(2.0*100 / 12, 5)})
        expected_list.append({'kpi_fk': 312, 'numerator': 2, 'result': round(8.0*100 / 12, 5)})
        expected_list.append({'kpi_fk': 310, 'numerator': 1, 'result': 1*100})
        expected_list.append({'kpi_fk': 310, 'numerator': 2, 'result': 1*100})
        expected_list.append({'kpi_fk': 309, 'numerator': 2, 'result': 2})

        kpi_results = tool_box.kpi_results_check
        kpi_results['result'] = kpi_results['result'].apply(lambda x: round(x, 5))
        test_result_list = []
        for expected_result in expected_list:
            test_result_list.append(self.check_kpi_results(kpi_results, expected_result) == 1)
        self.assertTrue(all(test_result_list))
Esempio n. 13
0
 def test_calculate_brand_full_bay_calculates_no_kpi_results_if_no_relevant_scenes_in_session(self):
     matches, scif = self.create_scif_matches_data_mocks_selected_scenes(DataTestUnitPEPSICOUK.test_case_1, [3])
     tool_box = PEPSICOUKToolBox(self.data_provider_mock, self.output)
     tool_box.calculate_brand_full_bay()
     self.assertTrue(tool_box.kpi_results_check.empty)
     self.assertFalse(tool_box.match_product_in_scene.empty)