consolidator
62 строки · 3.0 Кб
1import os
2import sys
3import pandas as pd
4import datetime
5from MainConsolidator import MainConsolidator
6
7class handler(object):
8@staticmethod
9def module_name():
10return 'Сляб стан 5000'
11@staticmethod
12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:
13product_up=None
14try:
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)
24print(f"{product} - strength_led: {strength_led}; gmsps: {gmsps}; strength_led_int: {strength_led_int}")
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}"
33row["error"] = pd.NA
34except Exception as exp:
35row["error"] = f"{exp}"
36finally:
37row["Продукт УП"]=product_up
38row["Время укрупнения"]=datetime.datetime.now()
39return row
40
41def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:
42try:
43if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)
44else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)
45except: raise
46
47def get_compiled(self):
48code:str=f"print('{__file__}')"
49try:
50with open(__file__,encoding="utf-8",mode="r") as f:
51code=f.read()
52except Exception as exp:
53code=f"print('error: {exp}')"
54finally:
55cc = compile(code,"","exec")
56return cc
57
58if __name__=="__slab_5k__":
59consolidator:MainConsolidator
60record:pd.Series
61result:pd.Series
62result = handler.handle(record,consolidator)
63
64