consolidator
55 строк · 2.6 Кб
1import os2import sys3import pandas as pd4import datetime5from MainConsolidator import MainConsolidator6
7class handler(object):8@staticmethod9def module_name():10return 'Труба круглая ТЭСЦ-2'11@staticmethod12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:13try:14product = row["Первичный продукт"]15thickness = row["Толщина стенки, мм <Производство>"]16typical_diametr = consolidator.nearest_in_guid("Параметры по Продукту ТЭСЦ-2",17f"`Производство`=='Труба круглая ТЭСЦ-2' and `Продукт`=='{product}'",18"Доп параметр1",19row["Диаметр, мм <Производство>"],20"Доп параметр1"21)22typical_diametr_s = str(typical_diametr).replace(".",",").replace(",0","")23thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-2",24f"`Производство`=='Труба круглая ТЭСЦ-2' and `Продукт`=='{product}' and `Доп параметр1`=='{typical_diametr_s}'","Диапазон")25print(f"product: {product}; thickness: {thickness}; thickness_range: {thickness_range}; typical_diametr: {typical_diametr_s}")26row["error"] = pd.NA27except Exception as exp:28row["error"] = f"{exp}"29finally:30row["Продукт УП"]=f"{product}{typical_diametr_s} {thickness_range} ГУ"31row["Время укрупнения"]=datetime.datetime.now()32return row33
34def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:35try:36if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)37else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)38except: raise39
40def get_compiled(self):41code:str=f"print('{__file__}')"42try:43with open(__file__,encoding="utf-8",mode="r") as f:44code=f.read()45except Exception as exp:46code=f"print('error: {exp}')"47finally:48cc = compile(code,"","exec")49return cc50
51if __name__=="__pipe_t2__":52consolidator:MainConsolidator53record:pd.Series54result:pd.Series55result = handler.handle(record,consolidator)56
57