consolidator
56 строк · 2.5 Кб
1import os2import sys3import pandas as pd4import datetime5from MainConsolidator import MainConsolidator6
7class handler(object):8@staticmethod9def module_name():10return 'Труба профильная ТЭСЦ-3'11@staticmethod12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:13try:14product = row["Первичный продукт"]15gmsps = row["ГМСПС"]16thickness = row["Толщина стенки, мм <Производство>"]17size = f"{row['Размер профиля 1, мм <Производство>']}Х{row['Размер профиля 2, мм <Производство>']}"18product_up = None19thickness_range = None20if "ГУ" in gmsps:21thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-3",22f"`Производство`=='Труба профильная ТЭСЦ-3' and `Продукт`=='{product}' and `Доп параметр2`=='ГУ' and `Мин`<={thickness}<=`Макс`","Диапазон")23product_up=f"{product}{size} {thickness_range} ГУ"24else:25product_up=f"{product}{size} {gmsps}"26print(f"product: {product}; gmsps: {gmsps}; thickness: {thickness}; thickness_range: {thickness_range}")27row["error"] = pd.NA28except Exception as exp:29row["error"] = f"{exp}"30finally:31row["Продукт УП"]=product_up32row["Время укрупнения"]=datetime.datetime.now()33return row34
35def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:36try:37if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)38else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)39except: raise40
41def get_compiled(self):42code:str=f"print('{__file__}')"43try:44with open(__file__,encoding="utf-8",mode="r") as f:45code=f.read()46except Exception as exp:47code=f"print('error: {exp}')"48finally:49cc = compile(code,"","exec")50return cc51
52if __name__=="__pipe_profile_t3__":53consolidator:MainConsolidator54record:pd.Series55result:pd.Series56result = handler.handle(record,consolidator)57
58