예제 #1
0
 def test_set_filtered_scif_and_matches_for_specific_kpi_additionally_filter_scif_and_matches(
         self):
     self.mock_scene_item_facts(
         pd.read_excel(DataTestUnitPEPSICOUK.test_case_rollout,
                       sheetname='scif'))
     self.mock_match_product_in_scene(
         pd.read_excel(DataTestUnitPEPSICOUK.test_case_rollout,
                       sheetname='matches'))
     self.mock_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     scif, matches = tool_box.set_filtered_scif_and_matches_for_specific_kpi(
         tool_box.filtered_scif, tool_box.filtered_matches, 'Brand SOS')
     matches_excluded_kpi_specific = set(tool_box.filtered_matches['probe_match_fk'].values.tolist()) - \
                                         set(matches['probe_match_fk'].values.tolist())
     self.assertEquals(len(matches), 30)
     self.assertNotEqual(len(matches), len(tool_box.filtered_matches))
     included_matches_expected = [
         3, 4, 5, 6, 7, 8, 14, 15, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27,
         28, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43
     ]
     excluded_matches_expected = [
         11, 12, 13, 20, 29, 30, 31, 32, 44, 45, 46, 47, 48, 49, 50, 51
     ]
     self.assertItemsEqual(matches_excluded_kpi_specific,
                           excluded_matches_expected)
     matches_positive_check = tool_box.filtered_matches[tool_box.filtered_matches['probe_match_fk']. \
         isin(included_matches_expected)]
     self.assertItemsEqual(
         included_matches_expected,
         matches_positive_check['probe_match_fk'].values.tolist())
     self.assertEquals(len(scif), 5)
     self.assertNotEqual(len(scif), len(tool_box.filtered_scif))
예제 #2
0
 def test_filters_for_scif_and_matches_return_empty_dict_if_template_empty(
         self):
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     expected_result = {}
     template_filters = tool_box.get_filters_dictionary(
         DataTestUnitPEPSICOUK.empty_exclusion_template)
     self.assertDictEqual(expected_result, template_filters)
     self.assertIsInstance(template_filters, dict)
예제 #3
0
 def test_filters_for_scif_and_matches_return_empty_dict_with_ommitted_action_field(
         self):
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     expected_result = {
         'category': (['Cat 1', 'Cat 2'], 0),
         'location_type': ['Primary Shelf']
     }
     template_filters = tool_box.get_filters_dictionary(
         DataTestUnitPEPSICOUK.exclusion_template_missing_action)
     self.assertDictEqual(expected_result, template_filters)
예제 #4
0
 def test_unpack_all_external_targets_forms_data_frame_with_all_relevant_columns_and_all_records(
         self):
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     columns = tool_box.all_targets_unpacked.columns.values.tolist()
     expected_columns_in_output_df = DataTestUnitPEPSICOUK.external_targets_columns
     validation_list = [
         col in columns for col in expected_columns_in_output_df
     ]
     self.assertTrue(all(validation_list))
     self.assertEquals(len(tool_box.all_targets_unpacked), 32)
예제 #5
0
 def test_do_exclusion_rules_apply_to_store_returns_false_if_kpi_in_store_policy_tab_and_store_attr_do_not_match_policy(
         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_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     result = tool_box.do_exclusion_rules_apply_to_store('Some KPI')
     self.assertFalse(result)
예제 #6
0
 def test_unpack_all_external_targets_kpi_relevant_columns_are_filled(self):
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     targets = tool_box.all_targets_unpacked
     shelf_placement_targets = targets[targets['operation_type'] ==
                                       tool_box.SHELF_PLACEMENT]
     data_with_null_values = shelf_placement_targets[shelf_placement_targets \
                                         ['Shelves From Bottom To Include (data)'].isnull()]
     self.assertEquals(len(data_with_null_values), 0)
     keys_with_null_values = shelf_placement_targets[shelf_placement_targets \
                 ['No of Shelves in Fixture (per bay) (key)'].isnull()]
     self.assertEquals(len(keys_with_null_values), 0)
예제 #7
0
 def test_do_exclusion_rules_apply_to_store_returns_true_if_kpi_in_store_policy_tab_and_store_attributes_comply_and_values_with_comma(
         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_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     result = tool_box.do_exclusion_rules_apply_to_store('Hero SKU SOS')
     self.assertTrue(result)
예제 #8
0
 def test_empty_scene_details(self):
     self.mock_scene_item_facts(
         pd.read_excel(DataTestUnitPEPSICOUK.test_case_2, sheetname='scif'))
     self.mock_match_product_in_scene(
         pd.read_excel(DataTestUnitPEPSICOUK.test_case_2,
                       sheetname='matches'))
     self.mock_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     self.assertTrue(tool_box.scif.empty)
     self.assertTrue(tool_box.match_product_in_scene.empty)
     self.assertTrue(tool_box.filtered_matches.empty)
     self.assertTrue(tool_box.filtered_scif.empty)
예제 #9
0
 def test_unpack_external_targets_json_fields_to_df_returns_empty_df_if_input_empty(
         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_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     result_df = tool_box.unpack_external_targets_json_fields_to_df(
         DataTestUnitPEPSICOUK.data_json_empty, 'json_field')
     self.assertTrue(result_df.empty)
예제 #10
0
 def test_filters_for_scif_and_matches_are_retrieved_in_the_right_format(
         self):
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     expected_result = {
         'smart_attribute_state': (['additional display'], 0),
         'product_name': (['General Empty'], 0)
     }
     excl_template_all_kpis = tool_box.exclusion_template[
         tool_box.exclusion_template['KPI'].str.upper() == 'ALL']
     template_filters = tool_box.get_filters_dictionary(
         excl_template_all_kpis)
     self.assertDictEqual(expected_result, template_filters)
예제 #11
0
 def test_unpack_external_targets_json_fields_to_df_returns_df_with_pk_field_only(
         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_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     result_df = tool_box.unpack_external_targets_json_fields_to_df(
         DataTestUnitPEPSICOUK.data_json_empty_with_pks, 'json_field')
     self.assertItemsEqual(result_df.columns.values.tolist(), ['pk'])
예제 #12
0
 def test_set_filtered_scif_and_matches_for_specific_kpi_does_not_change_filtered_scif_and_matches_if_no_policy_applies(
         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_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     scif, matches = tool_box.set_filtered_scif_and_matches_for_specific_kpi(
         tool_box.filtered_scif, tool_box.filtered_matches,
         'PepsiCo Segment Space to Sales Index')
     self.assertEquals(len(matches), len(tool_box.filtered_matches))
     self.assertEquals(len(scif), len(tool_box.filtered_scif))
     assert_frame_equal(scif, tool_box.filtered_scif)
     assert_frame_equal(matches, tool_box.filtered_matches)
예제 #13
0
 def test_get_filters_for_scif_and_matches_returns_values_with_product_and_scene_pks(
         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_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     excl_template_all_kpis = tool_box.exclusion_template[
         tool_box.exclusion_template['KPI'].str.upper() == 'ALL']
     template_filters = tool_box.get_filters_dictionary(
         excl_template_all_kpis)
     filters = tool_box.get_filters_for_scif_and_matches(template_filters)
     expected_result = {'product_fk': [1, 2, 3, 4, 5]}
     self.assertDictEqual(filters, expected_result)
예제 #14
0
 def test_filtered_scif_facings_and_gross_length_reduced_following_matches(
         self):
     self.mock_scene_item_facts(
         pd.read_excel(DataTestUnitPEPSICOUK.test_case_rollout,
                       sheetname='scif'))
     self.mock_match_product_in_scene(
         pd.read_excel(DataTestUnitPEPSICOUK.test_case_rollout,
                       sheetname='matches'))
     self.mock_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     for i, row in tool_box.filtered_scif.iterrows():
         expected_facings = len(tool_box.filtered_matches[
             (tool_box.filtered_matches['scene_fk'] == row['scene_fk'])
             & (tool_box.filtered_matches['product_fk'] == row['product_fk']
                )])
         expected_len = tool_box.filtered_matches[(tool_box.filtered_matches['scene_fk'] == row['scene_fk']) &
                                                  (tool_box.filtered_matches['product_fk'] == row['product_fk'])] \
                                                 ['width_mm_advance'].sum()
         self.assertEquals(row['facings'], expected_facings)
         self.assertEquals(row['gross_len_add_stack'], expected_len)
예제 #15
0
 def test_excluded_matches_are_not_present_in_filtered_matches_and_included_are_present(
         self):
     self.mock_scene_item_facts(
         pd.read_excel(DataTestUnitPEPSICOUK.test_case_rollout,
                       sheetname='scif'))
     self.mock_match_product_in_scene(
         pd.read_excel(DataTestUnitPEPSICOUK.test_case_rollout,
                       sheetname='matches'))
     self.mock_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     excluded_matches = tool_box.match_product_in_scene[~(
         tool_box.match_product_in_scene['Out'].isnull()
     )]['probe_match_fk'].values.tolist()
     matches_negative_check = tool_box.filtered_matches[tool_box.filtered_matches['probe_match_fk'].\
                                             isin(excluded_matches)]
     self.assertTrue(matches_negative_check.empty)
     included_matches = tool_box.match_product_in_scene[
         tool_box.match_product_in_scene['Out'].isnull(
         )]['probe_match_fk'].values.tolist()
     matches_positive_check = tool_box.filtered_matches[tool_box.filtered_matches['probe_match_fk'].\
                                             isin(included_matches)]
     self.assertItemsEqual(
         included_matches,
         matches_positive_check['probe_match_fk'].values.tolist())
예제 #16
0
 def test_unpack_external_targets_json_fields_to_df_gets_all_fields_from_json_and_matches_correct_pks(
         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_store_area(DataTestUnitPEPSICOUK.store_area_map_neutral)
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     expected_result = pd.DataFrame.from_records([
         {
             'pk': 2,
             u'store_type': u'CORE',
             u'additional_attribute_2': np.nan,
             u'additional_attribute_1': u'ALL'
         },
         {
             'pk': 3,
             u'store_type': u'ALL',
             u'additional_attribute_2': np.nan,
             u'additional_attribute_1': u'OT'
         },
         {
             'pk': 10,
             u'store_type': u'CORE',
             u'additional_attribute_2': u'SAINSBURY',
             u'additional_attribute_1': np.nan
         },
     ])
     result_df = tool_box.unpack_external_targets_json_fields_to_df(
         DataTestUnitPEPSICOUK.data_json_1, 'json_field')
     self.assertItemsEqual([
         'pk', 'store_type', 'additional_attribute_1',
         'additional_attribute_2'
     ], result_df.columns.values.tolist())
     assert_frame_equal(expected_result, result_df)
예제 #17
0
 def test_get_yes_no_score_type_fk_if_score_value_zero(self):
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     expected_res = 5
     result_fk = tool_box.get_yes_no_score(0)
     self.assertEquals(result_fk, expected_res)
예제 #18
0
    def __init__(self, output, data_provider):
        super(PepsicoUtil, self).__init__(data_provider)
        self.output = output
        self.common = Common(self.data_provider)
        # self.common_v1 = CommonV1(self.data_provider)
        self.project_name = self.data_provider.project_name
        self.session_uid = self.data_provider.session_uid
        self.products = self.data_provider[Data.PRODUCTS]
        self.all_products = self.data_provider[Data.ALL_PRODUCTS]
        self.match_product_in_scene = self.data_provider[Data.MATCHES]
        self.visit_date = self.data_provider[Data.VISIT_DATE]
        self.session_info = self.data_provider[Data.SESSION_INFO]
        self.scene_info = self.data_provider[Data.SCENES_INFO]
        self.store_id = self.data_provider[Data.STORE_FK] if self.data_provider[Data.STORE_FK] is not None \
                                                            else self.session_info['store_fk'].values[0]
        self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
        self.rds_conn = PSProjectConnector(self.project_name,
                                           DbUsers.CalculationEng)
        self.display_scene = self.get_match_display_in_scene()
        self.kpi_static_data = self.common.get_kpi_static_data()
        self.kpi_results_queries = []

        self.probe_groups = self.get_probe_group()
        self.match_product_in_scene = self.match_product_in_scene.merge(
            self.probe_groups, on='probe_match_fk', how='left')

        self.toolbox = GENERALToolBox(self.data_provider)
        self.commontools = PEPSICOUKCommonToolBox(self.data_provider,
                                                  self.rds_conn)

        self.all_templates = self.commontools.all_templates
        self.custom_entities = self.commontools.custom_entities
        self.on_display_products = self.commontools.on_display_products
        self.exclusion_template = self.commontools.exclusion_template
        self.filtered_scif = self.commontools.filtered_scif.copy()
        self.filtered_matches = self.commontools.filtered_matches.copy()
        self.filtered_matches = self.filtered_matches.merge(
            self.probe_groups, on='probe_match_fk', how='left')

        self.filtered_scif_secondary = self.commontools.filtered_scif_secondary.copy(
        )
        self.filtered_matches_secondary = self.commontools.filtered_matches_secondary.copy(
        )

        self.scene_bay_shelf_product = self.commontools.scene_bay_shelf_product
        self.ps_data = PsDataProvider(self.data_provider, self.output)
        self.full_store_info = self.commontools.full_store_info.copy()
        self.external_targets = self.commontools.external_targets
        self.assortment = Assortment(self.commontools.data_provider,
                                     self.output)
        self.lvl3_ass_result = self.get_lvl3_relevant_assortment_result()
        self.own_manuf_fk = self.all_products[
            self.all_products['manufacturer_name'] ==
            self.PEPSICO]['manufacturer_fk'].values[0]

        self.scene_kpi_results = self.get_results_of_scene_level_kpis()
        self.kpi_results_check = pd.DataFrame(columns=[
            'kpi_fk', 'numerator', 'denominator', 'result', 'score', 'context'
        ])
        self.sos_vs_target_targets = self.construct_sos_vs_target_base_df()

        self.all_targets_unpacked = self.commontools.all_targets_unpacked.copy(
        )
        self.block_results = pd.DataFrame(columns=['Group Name', 'Score'])
        self.hero_type_custom_entity_df = self.get_hero_type_custom_entity_df()
예제 #19
0
 def test_get_kpi_score_value_pk_by_value_returns_none_if_value_does_not_exist(
         self):
     tool_box = PEPSICOUKCommonToolBox(self.data_provider_mock, self.output)
     result_fk = tool_box.get_kpi_score_value_pk_by_value(
         'non_existing_value')
     self.assertIsNone(result_fk)