consolidator
52 строки · 2.3 Кб
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:13product_up = None14try:15wall = row["Толщина стенки, мм <Производство>"]16s1 = str(row['Размер профиля 1, мм <Производство>']).replace(".0","")17s2 = str(row['Размер профиля 2, мм <Производство>']).replace(".0","")18size = f"{s1}Х{s2}"19thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-2",20f"`Производство`=='Труба профильная ТЭСЦ-2' and `Доп параметр1`=='{size}' and {wall}>=`Мин` and {wall}<=`Макс`","Диапазон")21print(f"t2 wall: {wall} ; size: {size}; thickness_range: {thickness_range}")22product_up = f"ТРУБА Д{size} {thickness_range} ГУ"23row["error"] = pd.NA24except Exception as exp:25row["error"] = f"{exp}"26finally:27row["Продукт УП"]= product_up28row["Время укрупнения"]=datetime.datetime.now()29return row30
31def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:32try:33if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)34else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)35except: raise36
37def get_compiled(self):38code:str=f"print('{__file__}')"39try:40with open(__file__,encoding="utf-8",mode="r") as f:41code=f.read()42except Exception as exp:43code=f"print('error: {exp}')"44finally:45cc = compile(code,"","exec")46return cc47
48if __name__=="__pipe_profile_t2__":49consolidator:MainConsolidator50record:pd.Series51result:pd.Series52result = handler.handle(record,consolidator)53
54