consolidator
58 строк · 2.3 Кб
1import os
2import sys
3import pandas as pd
4import datetime
5from MainConsolidator import MainConsolidator
6
7class handler(object):
8@staticmethod
9def module_name():
10return 'Жидкая сталь'
11@staticmethod
12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:
13product_up = None
14try:
15product = row["Первичный продукт"]
16steel_mark = row["Марка стали <Производство>"]
17strength = row["Класс прочности <Производство>"]
18steel_letter = steel_mark[:1]
19if steel_letter in ["K","X","К","Х"]: strength = steel_mark
20strength_2 = consolidator.strength_mapping(strength,steel_mark)
21strength_led = consolidator.strength_led(strength_2[0])
22gmsps = consolidator.get_gmsps(steel_mark,product)
23print(f"{product} ; steel_mark: {steel_mark}; strength: {strength}; strength_2:{strength_2}; {strength_led} ; {gmsps}")
24if pd.isna(strength_led):
25if "ГУ" in str(gmsps): gmsps="ГУ"
26product_up = f"{product} {gmsps}"
27else:
28product_up = f"{product} {strength_led}"
29row["error"] = pd.NA
30except Exception as exp:
31row["error"] = f"{exp}"
32finally:
33row["Продукт УП"]=product_up
34row["Время укрупнения"]=datetime.datetime.now()
35return row
36
37def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:
38try:
39if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)
40else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)
41except: raise
42
43def get_compiled(self):
44code:str=f"print('{__file__}')"
45try:
46with open(__file__,encoding="utf-8",mode="r") as f:
47code=f.read()
48except Exception as exp:
49code=f"print('error: {exp}')"
50finally:
51cc = compile(code,"","exec")
52return cc
53
54if __name__=="__steel__":
55consolidator:MainConsolidator
56record:pd.Series
57result:pd.Series
58result = handler.handle(record,consolidator)
59
60