consolidator
76 строк · 3.8 Кб
1import os2import sys3import pandas as pd4import datetime5from MainConsolidator import MainConsolidator6
7class handler(object):8@staticmethod9def module_name():10return 'Труба черная ТЭСЦ-3'11@staticmethod12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:13try:14product = row["Первичный продукт"]15diametr = row["Диаметр, мм <Производство>"]16thickness = row["Толщина стенки, мм <Производство>"]17gmsps = row["ГМСПС"]18en_pr=None19if "ТУ" in str(row["НТД качества (трубы стальные) <Производство>"]) or "ГОСТ" in str(row["НТД качества (трубы стальные) <Производство>"]):20en_pr="ПР"21else:22if pd.notna(row["НТД качества (трубы стальные) <Производство>"]):23en_pr="EN"24diametr_led = consolidator.nearest_in_guid("Параметры по Продукту ТЭСЦ-3",25f"`Производство`=='Труба черная ТЭСЦ-3' and `Продукт`=='{product}'",26"Доп параметр1",27diametr,28"Доп параметр1"29)30diametr_led_s=str(diametr_led).replace(".0","")31thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-3",32f"`Производство`=='Труба черная ТЭСЦ-3' and `Продукт`=='{product}' and {thickness}>=`Мин` and {thickness}<=`Макс` and `Доп параметр2`.str.contains('{gmsps}')",33"Диапазон")34print(f"product: {product}; diametr: {diametr}; thickness: {thickness}; gmsps: {gmsps}; en_pr: {en_pr}; diametr_led: {diametr_led}; thickness_range: {thickness_range}")35product_up = f"{product}{diametr_led_s} {gmsps}"36
37###### П0130_Наименование_УП_для_труб ###########38if pd.notna(gmsps) and "ГУ" in gmsps:39product_up=f"{product}{diametr_led_s} {thickness_range} {gmsps}"40if en_pr=="EN" and "ПР" in gmsps: product_up=product_up +" EN"41if pd.notna(gmsps) and "ГК" in gmsps:42product_up=f"{product}{diametr_led_s} {gmsps}"43if en_pr=="EN" and "ПР" in gmsps: product_up=product_up +" EN"44if diametr_led==457 and "EN" not in product_up: product_up = product_up+" EN"45#################################################46
47row["error"] = pd.NA48except Exception as exp:49row["error"] = f"{exp}"50finally:51row["Продукт УП"]=product_up52row["Время укрупнения"]=datetime.datetime.now()53return row54
55def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:56try:57if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)58else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)59except: raise60
61def get_compiled(self):62code:str=f"print('{__file__}')"63try:64with open(__file__,encoding="utf-8",mode="r") as f:65code=f.read()66except Exception as exp:67code=f"print('error: {exp}')"68finally:69cc = compile(code,"","exec")70return cc71
72if __name__=="__pipe_black_t3__":73consolidator:MainConsolidator74record:pd.Series75result:pd.Series76result = handler.handle(record,consolidator)77
78