consolidator
59 строк · 2.9 Кб
1import os2import sys3import pandas as pd4import datetime5from MainConsolidator import MainConsolidator6
7class handler(object):8@staticmethod9def module_name():10return 'Труба бесшовная ТПЦ'11@staticmethod12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:13product_up=None14try:15product = row["Первичный продукт"]16thickness = row["Толщина стенки, мм <Производство>"]17diametr = row["Диаметр, мм <Производство>"]18vm_code = row['Вид материала в SAP ERP'][:4]19steel_mark = row["Марка стали <Производство>"]20
21pipe_type = consolidator.scalar_in_guid("Виды материалов ТПЦ",f"`Код`=='{vm_code}'","Тип трубы")22diametr_led = consolidator.nearest_in_guid("Параметры по Продукту ТПЦ",f"`Производство`=='Труба бесшовная ТПЦ'","Диаметр",diametr,"Диаметр")23diametr_led_s = str(diametr_led).replace(".0","")24thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТПЦ",f"`Производство`=='Труба бесшовная ТПЦ' and `Мин`<={thickness}<=`Макс`","Диапазон")25gmsps = consolidator.get_gmsps(steel_mark,product)26# if pd.isna(gmsps): gmsps = f"[{steel_mark}]" # for debug27print(f"{product}: {thickness}: {diametr} -> {diametr_led_s}: {pipe_type}")28product_up = f"{product} Д{diametr_led_s} {thickness_range} {gmsps}"29if "ИВ" in pipe_type: product_up = f"{product_up} ИВ"30row["error"] = pd.NA31except Exception as exp:32row["error"] = f"{exp}"33finally:34row["Продукт УП"]=product_up35row["Время укрупнения"]=datetime.datetime.now()36return row37
38def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:39try:40if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)41else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)42except: raise43
44def get_compiled(self):45code:str=f"print('{__file__}')"46try:47with open(__file__,encoding="utf-8",mode="r") as f:48code=f.read()49except Exception as exp:50code=f"print('error: {exp}')"51finally:52cc = compile(code,"","exec")53return cc54
55if __name__=="__pipe_tpc__":56consolidator:MainConsolidator57record:pd.Series58result:pd.Series59result = handler.handle(record,consolidator)60
61