consolidator
61 строка · 3.1 Кб
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["Первичный продукт"]15carving = row["Тип резьбы <Производство>"]16strength_class = row["Класс прочности <Производство>"]17steel_mark = row["Марка стали <Производство>"]18diametr = row["Диаметр, мм <Производство>"]19carving_type = consolidator.scalar_in_guid("Резьба",f"`Исх резьба`=='{carving}'","Результ Резьба")20if pd.isna(carving) or pd.isna(carving_type): carving_type="БР"21# strength_group = consolidator.scalar_in_guid("Группа по классу прочности для труб",f"`Марка стали`=='{strength_class}' or `Марка стали`=='{steel_mark}'","Группа прочности")22# if pd.isna(strength_group): strength_group="ПD"23strength_group = consolidator.strength_group_by_steel(strength_class,steel_mark)24diametr_type = consolidator.nearest_in_guid("Параметры по Продукту ТЭСЦ-5",25f"`Производство`=='Труба обсадная ТЭСЦ-5' and `Продукт`=='{product}'",26"Доп параметр1",27diametr,28"Доп параметр1")29diametr_type_s = str(diametr_type).replace(".0","")30print(f"product: {product}; carving: {carving}; strength_group: {strength_group}; diametr_type: {diametr_type_s}")31product_up=f"{product}{diametr_type_s} ГО {strength_group} {carving_type}"32row["error"] = pd.NA33except Exception as exp:34row["error"] = f"{exp}"35finally:36row["Продукт УП"]=product_up37row["Время укрупнения"]=datetime.datetime.now()38return row39
40def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:41try:42if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)43else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)44except: raise45
46def get_compiled(self):47code:str=f"print('{__file__}')"48try:49with open(__file__,encoding="utf-8",mode="r") as f:50code=f.read()51except Exception as exp:52code=f"print('error: {exp}')"53finally:54cc = compile(code,"","exec")55return cc56
57if __name__=="__pipe_casing_t3__":58consolidator:MainConsolidator59record:pd.Series60result:pd.Series61result = handler.handle(record,consolidator)62
63