consolidator
45 строк · 1.6 Кб
1import os2import sys3import pandas as pd4import datetime5from MainConsolidator import MainConsolidator6
7class handler(object):8@staticmethod9def module_name():10return 'Лист плакированный Стан-5000'11@staticmethod12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:13try:14product = row["Первичный продукт"]15row["error"] = pd.NA16print(f"product: {product};")17except Exception as exp:18row["error"] = f"{exp}"19finally:20row["Продукт УП"]="ЛИСТ БМ Т24/4 ГН"21row["Время укрупнения"]=datetime.datetime.now()22return row23
24def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:25try:26if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)27else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)28except: raise29
30def get_compiled(self):31code:str=f"print('{__file__}')"32try:33with open(__file__,encoding="utf-8",mode="r") as f:34code=f.read()35except Exception as exp:36code=f"print('error: {exp}')"37finally:38cc = compile(code,"","exec")39return cc40
41if __name__=="__sheet_5k_p__":42consolidator:MainConsolidator43record:pd.Series44result:pd.Series45result = handler.handle(record,consolidator)46
47