consolidator
56 строк · 3.0 Кб
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["Первичный продукт"]15thickness = row["Толщина стенки, мм <Производство>"]16diametr = row["Диаметр, мм <Производство>"]17diametr_range = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-3",18f"`Производство`=='Труба бесшовная ТЭСЦ-3' and `Продукт`=='{product}' and {diametr}>=`Мин` and {diametr}<=`Макс`","Диапазон")19strength_class_led = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-3",20f"`Производство`=='Труба бесшовная ТЭСЦ-3' and `Продукт`=='{product}' and `Доп параметр1`=='{row['Класс прочности <Производство>']}'","Доп параметр2")21if pd.isna(strength_class_led):22strength_class_led = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-3",23f"`Производство`=='Труба бесшовная ТЭСЦ-3' and `Продукт`=='{product}' and `Доп параметр1`=='{row['Марка стали <Производство>']}'","Доп параметр2")24if pd.isna(strength_class_led): strength_class_led = "ПD"25
26print(f"product: {product}; thickness: {thickness}; diametr: {diametr}; diametr_range: {diametr_range}; strength_class_led: {strength_class_led}")27row["error"] = pd.NA28except Exception as exp:29row["error"] = f"{exp}"30finally:31row["Продукт УП"]=f"{product} {diametr_range} {strength_class_led}"32row["Время укрупнения"]=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_seamless_t3__":53consolidator:MainConsolidator54record:pd.Series55result:pd.Series56result = handler.handle(record,consolidator)57
58