consolidator
67 строк · 3.3 Кб
1import os2import sys3import pandas as pd4import datetime5from MainConsolidator import MainConsolidator6
7class handler(object):8@staticmethod9def module_name():10return 'Штрипс ТЭСЦ-5'11@staticmethod12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:13product_up=None14try:15product = row["Первичный продукт"]16gmsps = row["ГМСПС"]17ntd = row["НТД качества (прокат) <Производство>"]18gmsps_oto = consolidator.scalar_in_guid("Признак по НТД",f"`Производство`=='Штрипс ТЭСЦ-5' and `НТД качества (трубы стальные) <Производство>`=='{ntd}'","Доп параметр1")19if "ГЮ" in gmsps and pd.notna(gmsps_oto): gmsps=gmsps_oto20thickness = row["Толщина, мм <Производство>"]21thickness = round(thickness,1)22width_led = consolidator.nearest_in_guid("Параметры по Продукту ТЭСЦ-5",23f"`Производство`=='Штрипс ТЭСЦ-5' and `Продукт`=='{product}' and `Доп параметр2` == '{gmsps[:2]}'",24"Доп параметр1",25row["Ширина штрипса, мм <Производство>"],26"Доп параметр1")27width_led_s=str(width_led).replace(".0","")28print(f"product: {product}; gmsps: {gmsps}; thickness: {thickness}; ntd: {ntd}; width_led: {width_led_s}")29product_up = None30thickness_range = None31if "ГУ" in gmsps:32thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-5",33f"`Производство`=='Штрипс ТЭСЦ-5' and `Продукт`=='{product}' and `Доп параметр2` == 'ГУ' and `Мин`<={thickness}<=`Макс`","Диапазон")34product_up=f"{product} {thickness_range} Ш{width_led_s} ГУ"35else:36product_up=f"{product} Ш{width_led_s} {gmsps}"37row["error"] = pd.NA38except Exception as exp:39consolidator.mlog.error("handler error",exc_info=True)40row["error"] = f"{exp}"41finally:42row["Продукт УП"]=product_up43row["Время укрупнения"]=datetime.datetime.now()44return row45
46def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:47try:48if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)49else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)50except: raise51
52def get_compiled(self):53code:str=f"print('{__file__}')"54try:55with open(__file__,encoding="utf-8",mode="r") as f:56code=f.read()57except Exception as exp:58code=f"print('error: {exp}')"59finally:60cc = compile(code,"","exec")61return cc62
63if __name__=="__strips_t5__":64consolidator:MainConsolidator65record:pd.Series66result:pd.Series67result = handler.handle(record,consolidator)68
69