def __init__(self, data_provider, output):
     self.output = output
     self.data_provider = data_provider
     self.project_name = data_provider.project_name
     self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
     self.common = Common(self.data_provider)
     self.commonV2 = CommonV2(self.data_provider)
     self.diageo_generator = DIAGEOGenerator(self.data_provider, self.output, self.common)
     self.template_handler = TemplateHandler(self.project_name)
Beispiel #2
0
 def __init__(self, data_provider, output=None):
     super(DiageoUtil, self).__init__(data_provider)
     self.data_provider = data_provider
     self.store_id = self.data_provider[Data.STORE_FK]
     self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
     self.diageo_generator = DIAGEOGenerator(self.data_provider, output, common=None, menu=True)
     self.diageo_manufacturer = int(self.data_provider.own_manufacturer.param_value.values[0])
     self.template_handler = TemplateHandler(self.data_provider.project_name)
     self.template_handler.update_templates()
     self.assortment = Assortment(self.data_provider)
     self.assortment_lvl3_results = self.assortment.calculate_lvl3_assortment()
Beispiel #3
0
class DiageoUtil(UnifiedKPISingleton):

    def __init__(self, data_provider, output=None):
        super(DiageoUtil, self).__init__(data_provider)
        self.data_provider = data_provider
        self.store_id = self.data_provider[Data.STORE_FK]
        self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
        self.diageo_generator = DIAGEOGenerator(self.data_provider, output, common=None, menu=True)
        self.diageo_manufacturer = int(self.data_provider.own_manufacturer.param_value.values[0])
        self.template_handler = TemplateHandler(self.data_provider.project_name)
        self.template_handler.update_templates()
        self.assortment = Assortment(self.data_provider)
        self.assortment_lvl3_results = self.assortment.calculate_lvl3_assortment()

    @property
    def assortment_lvl2_results(self):
        if self.assortment_lvl3_results:
            return self.assortment.calculate_lvl2_assortment(self.assortment_lvl3_results)
        return None

    def get_template_data(self, kpi_name):
        template_data = self.template_handler.download_template(kpi_name)
        return template_data
class DIAGEOARDIAGEOARToolBox:

    def __init__(self, data_provider, output):
        self.output = output
        self.data_provider = data_provider
        self.project_name = data_provider.project_name
        self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
        self.common = Common(self.data_provider)
        self.commonV2 = CommonV2(self.data_provider)
        self.diageo_generator = DIAGEOGenerator(self.data_provider, self.output, self.common)
        self.template_handler = TemplateHandler(self.project_name)

    def main_calculation(self):
        """
        This function calculates the KPI results.
        """
        log_runtime('Updating templates')(self.template_handler.update_templates)()

        # SOS Out Of The Box kpis
        self.diageo_generator.activate_ootb_kpis(self.commonV2)

        # sos by scene type
        self.diageo_generator.sos_by_scene_type(self.commonV2)

        # Global assortment kpis
        assortment_res_dict = self.diageo_generator.diageo_global_assortment_function_v2()
        self.commonV2.save_json_to_new_tables(assortment_res_dict)

        # Global assortment kpis - v3 for NEW MOBILE REPORTS use
        assortment_res_dict_v3 = self.diageo_generator.diageo_global_assortment_function_v3()
        self.commonV2.save_json_to_new_tables(assortment_res_dict_v3)

        # Global Relative Position function
        template_data = self.template_handler.download_template(DiageoKpiNames.RELATIVE_POSITION)
        res_dict = self.diageo_generator.diageo_global_relative_position_function(
            template_data, location_type='template_name')
        self.commonV2.save_json_to_new_tables(res_dict)

        # committing to new tables
        self.commonV2.commit_results_data()
        # committing to the old tables
        self.common.commit_results_data()
 def __init__(self, data_provider, output):
     self.data_provider = data_provider
     self.commonV2 = CommonV2(self.data_provider)
     self.rds_conn = PSProjectConnector(self.data_provider.project_name, DbUsers.CalculationEng)
     self.store_assortment = PSAssortmentDataProvider(self.data_provider).execute(policy_name=None)
     self.output = output
     self.kpi_static_data = self.get_kpi_static_data()
     self.store_id = self.data_provider[Data.STORE_FK]
     self.own_manufacturer_fk = 12
     self.store_info = self.get_store_info(self.store_id)
     self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
     self.all_templates = self.data_provider[Data.ALL_TEMPLATES]
     self.common = Common(self.data_provider)
     self.scene_info = self.data_provider[Data.SCENES_INFO]
     self.diageo_generator = DIAGEOGenerator(self.data_provider, self.output, self.common)
     self.template_handler = TemplateHandler(self.data_provider.project_name)
     self.template_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'Data')
     self.template_path = os.path.join(self.template_path, "Template.xlsx")
     self.kpi_template_data = parse_template(self.template_path, sheet_name='KPI')
     self.store_info = self.data_provider[Data.STORE_INFO]
     self.current_date = datetime.now()
class PS3SandToolBox:

    def __init__(self, data_provider, output):
        self.output = output
        self.data_provider = data_provider
        self.project_name = data_provider.project_name
        self.store_id = self.data_provider[Data.STORE_FK]
        self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
        self.common = Common(self.data_provider)
        self.commonV2 = CommonV2(self.data_provider)
        self.diageo_generator = DIAGEOGenerator(self.data_provider, self.output, self.common, menu=True)
        self.template_handler = TemplateHandler(self.project_name)

    def main_calculation(self):
        """
        This function calculates the KPI results.
        """
        # SOS Out Of The Box kpis
        self.diageo_generator.activate_ootb_kpis(self.commonV2)

        # sos by scene type
        self.diageo_generator.sos_by_scene_type(self.commonV2)

        log_runtime('Updating templates')
        self.template_handler.update_templates()

        # Global assortment kpis
        assortment_res = self.diageo_generator.diageo_global_grouping_assortment_calculation()
        self.commonV2.save_json_to_new_tables(assortment_res)

        # Global Menu kpis
        menus_res = self.diageo_generator.diageo_global_new_share_of_menu_function()
        self.commonV2.save_json_to_new_tables(menus_res)

        # Global Secondary Displays function
        res_json = self.diageo_generator.diageo_global_secondary_display_secondary_function()
        if res_json:
            self.commonV2.write_to_db_result(fk=res_json['fk'], numerator_id=1, denominator_id=self.store_id,
                                             result=res_json['result'])

        # Brand Blocking Global function
        template_data = self.template_handler.download_template(DiageoKpiNames.BRAND_BLOCKING)
        res_dict = self.diageo_generator.diageo_global_block_together(
            kpi_name=DiageoKpiNames.BRAND_BLOCKING,
            set_templates_data=template_data)
        self.commonV2.save_json_to_new_tables(res_dict)

        # Global Relative Position function
        template_data = self.template_handler.download_template(DiageoKpiNames.RELATIVE_POSITION)
        res_dict = self.diageo_generator.diageo_global_relative_position_function(
            template_data, location_type='template_name')
        self.commonV2.save_json_to_new_tables(res_dict)

        # Global Vertical Shelf Placement function
        template_data = self.template_handler.download_template(DiageoKpiNames.VERTICAL_SHELF_PLACEMENT)
        res_dict = self.diageo_generator.diageo_global_vertical_placement(template_data)
        self.commonV2.save_json_to_new_tables(res_dict)

        # committing to the new tables
        self.commonV2.commit_results_data()
        # committing to the old tables
        self.common.commit_results_data()
Beispiel #7
0
class DIAGEOUKToolBox:
    def __init__(self, data_provider, output):
        self.data_provider = data_provider
        self.project_name = self.data_provider.project_name
        self.store_id = self.data_provider[Data.STORE_FK]
        self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
        self.output = output
        self.common = Common(self.data_provider)
        self.commonV2 = CommonV2(self.data_provider)
        self.diageo_generator = DIAGEOGenerator(self.data_provider,
                                                self.output,
                                                self.common,
                                                menu=True)
        self.template_handler = TemplateHandler(self.project_name)

    def main_calculation(self):
        """
        This function calculates the KPI results.
        """
        log_runtime('Updating templates')
        self.template_handler.update_templates()

        # SOS Out Of The Box kpis
        self.diageo_generator.activate_ootb_kpis(self.commonV2)

        # sos by scene type
        self.diageo_generator.sos_by_scene_type(self.commonV2)

        # Global assortment kpis
        assortment_res = self.diageo_generator.diageo_global_grouping_assortment_calculation(
        )
        self.commonV2.save_json_to_new_tables(assortment_res)

        # Global Menu kpis
        menus_res = self.diageo_generator.diageo_global_new_share_of_menu_function(
        )
        self.commonV2.save_json_to_new_tables(menus_res)

        # Global Equipment score kpis
        equipment_score_scenes = self.get_equipment_score_relevant_scenes()
        res_dict = self.diageo_generator.diageo_global_equipment_score(
            save_scene_level=False, scene_list=equipment_score_scenes)
        self.commonV2.save_json_to_new_tables(res_dict)

        # Global Relative Position function
        template_data = self.template_handler.download_template(
            DiageoKpiNames.RELATIVE_POSITION)
        res_dict = self.diageo_generator.diageo_global_relative_position_function(
            template_data, location_type='template_name')
        self.commonV2.save_json_to_new_tables(res_dict)

        # Global Secondary Displays function
        res_json = self.diageo_generator.diageo_global_secondary_display_secondary_function(
        )
        if res_json:
            self.commonV2.write_to_db_result(fk=res_json['fk'],
                                             numerator_id=1,
                                             denominator_id=self.store_id,
                                             result=res_json['result'])

        # Global Visible to Consumer function
        sku_list = filter(
            None, self.scif[self.scif['product_type'] ==
                            'SKU'].product_ean_code.tolist())
        res_dict = self.diageo_generator.diageo_global_visible_percentage(
            sku_list)
        self.commonV2.save_json_to_new_tables(res_dict)

        # committing to new tables
        self.commonV2.commit_results_data()
        # committing to the old tables
        self.common.commit_results_data()

    def get_equipment_score_relevant_scenes(self):
        scenes = []
        if not self.diageo_generator.scif.empty:
            scenes = self.diageo_generator.scif[
                self.diageo_generator.scif['template_name'] ==
                'ON - DRAUGHT TAPS']['scene_fk'].unique().tolist()
        return scenes
Beispiel #8
0
class DIAGEOCOToolBox:
    def __init__(self, data_provider, output):
        self.output = output
        self.data_provider = data_provider
        self.common = Common(self.data_provider)
        self.common_v2 = CommonV2(self.data_provider)
        self.scif = self.data_provider[Data.SCENE_ITEM_FACTS]
        self.store_id = self.data_provider.store_fk
        self.template_handler = TemplateHandler(
            self.data_provider.project_name)
        self.diageo_generator = DIAGEOGenerator(self.data_provider,
                                                self.output,
                                                self.common,
                                                menu=True)

    def main_calculation(self):
        """
        This function calculates the KPI results.
        """

        self.template_handler.update_templates()

        # SOS Out Of The Box kpis
        self.diageo_generator.activate_ootb_kpis(self.common_v2)

        # sos by scene type
        self.diageo_generator.sos_by_scene_type(self.common_v2)

        # Global assortment kpis
        assortment_res_dict = self.diageo_generator.diageo_global_assortment_function_v2(
        )
        self.common_v2.save_json_to_new_tables(assortment_res_dict)

        # Global assortment kpis - v3 for NEW MOBILE REPORTS use
        assortment_res_dict_v3 = self.diageo_generator.diageo_global_assortment_function_v3(
        )
        self.common_v2.save_json_to_new_tables(assortment_res_dict_v3)

        # Global Share of Menu kpis
        menus_res_dict = self.diageo_generator.diageo_global_new_share_of_menu_function(
        )
        self.common_v2.save_json_to_new_tables(menus_res_dict)

        # Global Secondary Displays KPI
        res_json = self.diageo_generator.diageo_global_secondary_display_secondary_function(
        )
        if res_json:
            self.common_v2.write_to_db_result(
                fk=res_json['fk'],
                numerator_id=res_json['numerator_id'],
                denominator_id=self.store_id,
                result=res_json['result'])

        # Global Brand Pouring KPI
        template_data = self.template_handler.download_template(
            DiageoKpiNames.BRAND_POURING)
        results_list = self.diageo_generator.diageo_global_brand_pouring_status_function(
            template_data)
        self.save_results_to_db(results_list)

        # Global Brand Blocking KPI
        template_data = self.template_handler.download_template(
            DiageoKpiNames.BRAND_BLOCKING)
        results_list = self.diageo_generator.diageo_global_block_together(
            DiageoKpiNames.BRAND_BLOCKING, template_data)
        self.save_results_to_db(results_list)

        # Global Relative Position KPI
        template_data = self.template_handler.download_template(
            DiageoKpiNames.RELATIVE_POSITION)
        results_list = self.diageo_generator.diageo_global_relative_position_function(
            template_data)
        self.save_results_to_db(results_list)

        # Global TOUCH_POINT KPI
        templates_data = pd.read_excel(Const.TEMPLATE_PATH,
                                       Const.TOUCH_POINT_SHEET_NAME,
                                       header=Const.TOUCH_POINT_HEADER_ROW)
        template = templates_data.fillna(method='ffill').set_index(
            templates_data.keys()[0])
        results_list = self.diageo_generator.diageo_global_touch_point_function(
            template=template,
            old_tables=True,
            new_tables=False,
            store_attribute=Consts.ADDITIONAL_ATTR_2)
        self.save_results_to_db(results_list)

        # committing to new tables
        self.common_v2.commit_results_data()
        # committing to the old tables
        self.common.commit_results_data()

    def save_results_to_db(self, results_list):
        if results_list:
            for result in results_list:
                if result is not None:
                    self.common_v2.write_to_db_result(**result)