consolidator
63 строки · 3.0 Кб
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_1 = steel_mark if pd.isna(row["Класс прочности <Производство>"]) and pd.notna(steel_mark) else row["Класс прочности <Производство>"]19strength_class = consolidator.strength_by_steel(steel_mark)20strength_2 = consolidator.strength_mapping(strength_class,steel_mark)21strength_led = consolidator.strength_led(strength_2[0])22strength_led_int = int(strength_led[1:])23gmsps = consolidator.get_gmsps(steel_mark,product)24
25product_up=f"{product} {strength_led}"26if "ГУ" in gmsps: product_up=f"{product} ГУ"27elif strength_led_int >=60:28thickness_led = consolidator.nearest_in_guid("Параметры по Продукту Прокат",29f"`Производство`=='Сляб стан 5000' and `Продукт`=='{product}' and `Доп параметр2`=='{strength_led}'",30"Доп параметр1",thickness,"Доп параметр1")31thickness_led_s = str(thickness_led).replace(".0","")32product_up=f"{product} Т{thickness_led_s} {strength_led}"33print(f"{product} - strength_led: {strength_led}; gmsps: {gmsps}; strength_led_int: {strength_led_int} {thickness}->{thickness_led}")34row["error"] = pd.NA35except Exception as exp:36row["error"] = f"{exp}"37finally:38row["Продукт УП"]=product_up39row["Время укрупнения"]=datetime.datetime.now()40return row41
42def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:43try:44if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)45else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)46except: raise47
48def get_compiled(self):49code:str=f"print('{__file__}')"50try:51with open(__file__,encoding="utf-8",mode="r") as f:52code=f.read()53except Exception as exp:54code=f"print('error: {exp}')"55finally:56cc = compile(code,"","exec")57return cc58
59if __name__=="__half_roll__":60consolidator:MainConsolidator61record:pd.Series62result:pd.Series63result = handler.handle(record,consolidator)64
65