consolidator
61 строка · 2.8 Кб
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["Толщина раската, мм <Производство>"]17steel_mark = row["Марка стали <Производство>"]18strength_class = consolidator.strength_by_steel(steel_mark)19strength_2 = consolidator.strength_mapping(strength_class,steel_mark)20strength_led = consolidator.strength_led(strength_2[0])21strength_led_int = int(strength_led[1:])22gmsps = consolidator.get_gmsps(steel_mark,"ТОЛСТЫЙ СЛЯБ")23print(f"{product} - strength_led: {strength_led}; gmsps: {gmsps}; strength_led_int: {strength_led_int}")24product_up=f"{product} {strength_led}"25if "ГУ" in gmsps: product_up=f"{product} ГУ"26elif strength_led_int >=60:27thickness_led = consolidator.nearest_in_guid("Параметры по Продукту Прокат",28f"`Производство`=='Сляб катаный' and `Продукт`=='{product}' and `Доп параметр2`=='{strength_led}'",29"Доп параметр1",thickness,"Доп параметр1")30thickness_led_s = str(thickness_led).replace(".0","")31product_up=f"{product} Т{thickness_led_s} {strength_led}"32row["error"] = pd.NA33except Exception as exp:34row["error"] = f"{exp}"35finally:36row["Продукт УП"]=product_up37row["Время укрупнения"]=datetime.datetime.now()38return row39
40def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:41try:42if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)43else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)44except: raise45
46def get_compiled(self):47code:str=f"print('{__file__}')"48try:49with open(__file__,encoding="utf-8",mode="r") as f:50code=f.read()51except Exception as exp:52code=f"print('error: {exp}')"53finally:54cc = compile(code,"","exec")55return cc56
57if __name__=="__slab_rolled__":58consolidator:MainConsolidator59record:pd.Series60result:pd.Series61result = handler.handle(record,consolidator)62
63