示例#1
0
 def test_calculate_shelf_placement_vertical_mm_does_not_calculate_kpis_if_all_matches_excluded(
         self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 3)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.calculate_shelf_placement_vertical_mm()
     self.assertTrue(scene_tb.kpi_results.empty)
示例#2
0
 def test_main_calculation_does_not_happen_if_location_secondary_shelf(
         self):
     probe_group, matches, scene = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 3)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.main_function()
     self.assertTrue(scene_tb.kpi_results.empty)
示例#3
0
 def test_adjacency_no_results_if_no_blocks_pass(self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 1)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.block_results = DataTestUnitPEPSICOUK.blocks_none_passes
     scene_tb.calculate_adjacency_new()
     self.assertTrue(scene_tb.kpi_results.empty)
示例#4
0
 def test_get_group_pairs_1_pass_out_of_3(self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 1)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.block_results = DataTestUnitPEPSICOUK.blocks_combinations_1_pass_of_3
     pairs = scene_tb.get_group_pairs()
     self.assertEquals(len(pairs), 0)
示例#5
0
 def __init__(self, data_provider, output=None):
     self.data_provider = data_provider
     self.output = output
     self.project_name = data_provider.project_name
     self.session_uid = self.data_provider.session_uid
     self.common = Common(data_provider)
     self.scene_tool_box = PEPSICOUKSceneToolBox(self.data_provider,
                                                 self.output, self.common)
示例#6
0
 def test_get_group_pairs_2_pass_out_of_3(self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 1)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.block_results = DataTestUnitPEPSICOUK.blocks_combinations_2_pass_of_3
     pairs = scene_tb.get_group_pairs()
     expected_result = [frozenset(['Group 2', 'Group 1'])]
     self.assertEquals(len(pairs), 1)
     self.assertItemsEqual(pairs, expected_result)
示例#7
0
 def test_get_scene_bay_max_shelves_retrieves_empty_df_in_case_of_excluded_shelves(
         self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 3)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     external_targets = scene_tb.commontools.all_targets_unpacked
     shelf_placmnt_targets = external_targets[
         external_targets['operation_type'] == scene_tb.SHELF_PLACEMENT]
     if not shelf_placmnt_targets.empty:
         bay_max_shelves = scene_tb.get_scene_bay_max_shelves(
             shelf_placmnt_targets)
         self.assertTrue(bay_max_shelves.empty)
示例#8
0
    def test_block_together_vertical_and_horizontal(self):
        probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
            DataTestUnitPEPSICOUK.test_case_1, 1)

        self.mock_block_results([
            DataTestUnitPEPSICOUK.block_results,
            DataTestUnitPEPSICOUK.block_results_2
        ])
        scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
        scene_tb.calculate_product_blocking_new()
        kpi_result = pd.DataFrame(scene_tb.kpi_results)
        self.assertEquals(len(kpi_result), 2)
        expected_list = list()
        expected_list.append({
            'kpi_fk': 319,
            'numerator': 165,
            'result': 4,
            'score': 7
        })
        expected_list.append({
            'kpi_fk': 319,
            'numerator': 166,
            'result': 4,
            'score': 6
        })
        test_result_list = []
        for expected_result in expected_list:
            test_result_list.append(
                self.check_kpi_results(kpi_result, expected_result) == 1)
        self.assertTrue(all(test_result_list))

        expected_util_result = list()
        expected_util_result.append({
            'Group Name': 'Pringles_FTT_Tubes',
            'Score': 1
        })
        expected_util_result.append({
            'Group Name': 'Hula Hoops_LMP_Snacks',
            'Score': 1
        })
        test_result_list = list()
        for exp_res in expected_util_result:
            test_result_list.append(
                len(scene_tb.block_results[
                    (scene_tb.block_results['Group Name'] ==
                     exp_res['Group Name'])
                    & (scene_tb.block_results['Score'] == exp_res['Score'])])
                == 1)
        self.assertTrue(all(test_result_list))
        self.assertItemsEqual(scene_tb.passed_blocks.keys(),
                              ['Pringles_FTT_Tubes', 'Hula Hoops_LMP_Snacks'])
示例#9
0
 def test_calculate_number_of_bays_and_shelves(self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 1)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.calculate_number_of_bays_and_shelves()
     expected_list = []
     expected_list.append({'kpi_fk': 323, 'numerator': 2, 'result': 2})
     expected_list.append({'kpi_fk': 324, 'numerator': 2, 'result': 6})
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(
             self.check_kpi_results(scene_tb.kpi_results, expected_result)
             == 1)
     self.assertTrue(all(test_result_list))
示例#10
0
 def test_excluded_matches(self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 1)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     expected_result = set(matches[~(matches['Out'].isnull())]
                           ['probe_match_fk'].values.tolist())
     self.assertItemsEqual(expected_result, scene_tb.excluded_matches)
示例#11
0
class SceneGenerator:
    def __init__(self, data_provider, output=None):
        self.data_provider = data_provider
        self.output = output
        self.project_name = data_provider.project_name
        self.session_uid = self.data_provider.session_uid
        self.common = Common(data_provider)
        self.scene_tool_box = PEPSICOUKSceneToolBox(self.data_provider,
                                                    self.output, self.common)

    @log_runtime('Total Calculations', log_start=True)
    def scene_score(self):
        if self.scene_tool_box.match_product_in_scene.empty:
            Log.warning('Match product in scene is empty for this scene')
        else:
            self.scene_tool_box.main_function()
            self.scene_tool_box.common.commit_results_data(
                result_entity='scene')
示例#12
0
 def test_get_group_pairs_4_pass_out_of_4(self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 1)
     self.mock_object('PositionGraphs',
                      path='KPIUtils_v2.Calculations.AdjacencyCalculations')
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.block_results = DataTestUnitPEPSICOUK.blocks_combinations_4_pass_of_4
     pairs = scene_tb.get_group_pairs()
     expected = [
         frozenset(['Group 3', 'Group 1']),
         frozenset(['Group 4', 'Group 2']),
         frozenset(['Group 4', 'Group 3']),
         frozenset(['Group 2', 'Group 3']),
         frozenset(['Group 4', 'Group 1']),
         frozenset(['Group 2', 'Group 1'])
     ]
     self.assertEquals(len(pairs), 6)
     self.assertItemsEqual(pairs, expected)
示例#13
0
 def test_adjacency_passes(self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 1)
     self.mock_adjacency_results(
         [DataTestUnitPEPSICOUK.adjacency_results_true])
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.passed_blocks = {
         'Pringles_FTT_Tubes': DataTestUnitPEPSICOUK.block_results,
         'Hula Hoops_LMP_Snacks': DataTestUnitPEPSICOUK.block_results_2
     }
     scene_tb.block_results = DataTestUnitPEPSICOUK.blocks_all_pass
     scene_tb.calculate_adjacency_new()
     kpi_result = scene_tb.kpi_results
     self.assertEquals(len(kpi_result), 1)
     expected_list = list()
     expected_list.append({
         'kpi_fk': 320,
         'numerator': 166,
         'denominator': 165,
         'result': 4,
         'score': 1
     })
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(
             self.check_kpi_results(kpi_result, expected_result) == 1)
     self.assertTrue(all(test_result_list))
示例#14
0
 def test_calculate_horizontal_placement(self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 2)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     expected_list = []
     expected_list.append({
         'kpi_fk': 304,
         'numerator': 1,
         'result': 5.0 / 5 * 100
     })
     expected_list.append({
         'kpi_fk': 307,
         'numerator': 2,
         'result': round(2.0 / 6 * 100, 5)
     })
     expected_list.append({
         'kpi_fk': 306,
         'numerator': 2,
         'result': round(2.0 / 6 * 100, 5)
     })
     expected_list.append({
         'kpi_fk': 305,
         'numerator': 2,
         'result': round(2.0 / 6 * 100, 5)
     })
     expected_list.append({
         'kpi_fk': 307,
         'numerator': 3,
         'result': 1.0 * 100 / 1
     })
     scene_tb.calculate_shelf_placement_horizontal()
     kpi_results = scene_tb.kpi_results
     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(scene_tb.kpi_results, expected_result)
             == 1)
     self.assertTrue(all(test_result_list))
示例#15
0
 def test_calculate_shelf_placement_vertical_mm_correcly_places_products_if_no_excluded_matches(
         self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 2)
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     scene_tb.calculate_shelf_placement_vertical_mm()
     expected_list = []
     expected_list.append({
         'kpi_fk': 327,
         'numerator': 1,
         'result': 1.0 / 5 * 100
     })
     expected_list.append({
         'kpi_fk': 326,
         'numerator': 1,
         'result': 2.0 / 5 * 100
     })
     expected_list.append({
         'kpi_fk': 325,
         'numerator': 1,
         'result': 2.0 / 5 * 100
     })
     expected_list.append({
         'kpi_fk': 325,
         'numerator': 2,
         'result': 6.0 / 6 * 100
     })
     expected_list.append({
         'kpi_fk': 326,
         'numerator': 3,
         'result': 1.0 / 1 * 100
     })
     test_result_list = []
     for expected_result in expected_list:
         test_result_list.append(
             self.check_kpi_results(scene_tb.kpi_results, expected_result)
             == 1)
     self.assertTrue(all(test_result_list))
示例#16
0
    def test_calculate_shelf_placement_vertical_mm_in_case_excluded_matches_exist_and_different_stitch_groups(
            self):
        probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
            DataTestUnitPEPSICOUK.test_case_1, 1)
        scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
        scene_tb.calculate_shelf_placement_vertical_mm()
        kpi_results = scene_tb.kpi_results
        kpi_results['result'] = kpi_results['result'].apply(
            lambda x: round(x, 5))
        expected_list = []
        expected_list.append({
            'kpi_fk': 327,
            'numerator': 4,
            'result': round(1.0 / 6 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 326,
            'numerator': 4,
            'result': round(2.0 / 6 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 325,
            'numerator': 4,
            'result': round(3.0 / 6 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 325,
            'numerator': 1,
            'result': round(5.0 / 7 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 326,
            'numerator': 1,
            'result': round(2.0 / 7 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 325,
            'numerator': 2,
            'result': round(4.0 / 6 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 326,
            'numerator': 2,
            'result': round(2.0 / 6 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 325,
            'numerator': 3,
            'result': round(4.0 / 8 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 326,
            'numerator': 3,
            'result': round(3.0 / 8 * 100, 5)
        })
        expected_list.append({
            'kpi_fk': 327,
            'numerator': 3,
            'result': round(1.0 / 8 * 100, 5)
        })
        test_result_list = []
        for expected_result in expected_list:
            test_result_list.append(
                self.check_kpi_results(scene_tb.kpi_results, expected_result)
                == 1)
        self.assertTrue(all(test_result_list))

        non_expected_results = []
        non_expected_results.append({'kpi_fk': 325, 'numerator': 0})
        non_expected_results.append({'kpi_fk': 326, 'numerator': 0})
        non_expected_results.append({'kpi_fk': 327, 'numerator': 0})
        test_result_list = []
        for result in non_expected_results:
            test_result_list.append(
                self.check_kpi_results(scene_tb.kpi_results, result) == 0)
        self.assertTrue(all(test_result_list))
示例#17
0
 def test_get_scene_bay_max_shelves_retrieves_expected_df_in_case_of_several_bays(
         self):
     probe_group, matches, scif = self.create_scene_scif_matches_stitch_groups_data_mocks(
         DataTestUnitPEPSICOUK.test_case_1, 1)
     expected_result = pd.DataFrame([{
         u'kpi_level_2_fk':
         304,
         u'type':
         PEPSICOUKSceneToolBox.PLACEMENT_BY_SHELF_NUMBERS_TOP,
         u'No of Shelves in Fixture (per bay) (key)':
         6,
         u'Shelves From Bottom To Include (data)':
         '6',
         u'shelves_all_placements':
         '6,4,5,2,3,1'
     }, {
         u'kpi_level_2_fk':
         305,
         u'type':
         'Placement by shelf numbers_Eye',
         u'No of Shelves in Fixture (per bay) (key)':
         6,
         u'Shelves From Bottom To Include (data)':
         '4,5',
         u'shelves_all_placements':
         '6,4,5,2,3,1'
     }, {
         u'kpi_level_2_fk':
         306,
         u'type':
         'Placement by shelf numbers_Middle',
         u'No of Shelves in Fixture (per bay) (key)':
         6,
         u'Shelves From Bottom To Include (data)':
         '2,3',
         u'shelves_all_placements':
         '6,4,5,2,3,1'
     }, {
         u'kpi_level_2_fk':
         307,
         u'type':
         'Placement by shelf numbers_Bottom',
         u'No of Shelves in Fixture (per bay) (key)':
         6,
         u'Shelves From Bottom To Include (data)':
         '1',
         u'shelves_all_placements':
         '6,4,5,2,3,1'
     }, {
         u'kpi_level_2_fk':
         304,
         u'type':
         PEPSICOUKSceneToolBox.PLACEMENT_BY_SHELF_NUMBERS_TOP,
         u'No of Shelves in Fixture (per bay) (key)':
         3,
         u'Shelves From Bottom To Include (data)':
         '3',
         u'shelves_all_placements':
         '3,2,1'
     }, {
         u'kpi_level_2_fk':
         305,
         u'type':
         'Placement by shelf numbers_Eye',
         u'No of Shelves in Fixture (per bay) (key)':
         3,
         u'Shelves From Bottom To Include (data)':
         '2',
         u'shelves_all_placements':
         '3,2,1'
     }, {
         u'kpi_level_2_fk':
         307,
         u'type':
         'Placement by shelf numbers_Bottom',
         u'No of Shelves in Fixture (per bay) (key)':
         3,
         u'Shelves From Bottom To Include (data)':
         '1',
         u'shelves_all_placements':
         '3,2,1'
     }])
     scene_tb = PEPSICOUKSceneToolBox(self.data_provider_mock, self.output)
     external_targets = scene_tb.commontools.all_targets_unpacked
     shelf_placmnt_targets = external_targets[
         external_targets['operation_type'] == scene_tb.SHELF_PLACEMENT]
     if not shelf_placmnt_targets.empty:
         bay_max_shelves = scene_tb.get_scene_bay_max_shelves(
             shelf_placmnt_targets)
         bay_max_shelves = bay_max_shelves[[
             'kpi_level_2_fk', 'type',
             'No of Shelves in Fixture (per bay) (key)',
             'Shelves From Bottom To Include (data)',
             'shelves_all_placements'
         ]]
         assert_frame_equal(expected_result.sort_index(axis=1),
                            bay_max_shelves.sort_index(axis=1),
                            check_dtype=False,
                            check_column_type=False,
                            check_names=True)