consolidator
53 строки · 2.7 Кб
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["Первичный продукт"]15diametr = row["Диаметр, мм <Производство>"]16carving = row["Тип резьбы <Производство>"]17strength_class = row["Класс прочности <Производство>"]18diametr_type = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-5",f"`Производство`=='Муфта ТЭСЦ-5' and `Доп параметр1`=={round(diametr,1)}","Доп параметр2")19carving_type = consolidator.scalar_in_guid("Резьба",f"`Исх резьба`=='{carving}'","Результ Резьба")20strength_group = consolidator.scalar_in_guid("Группа по классу прочности для муфт",f"`Марка стали`=='{strength_class}'","Группа прочности")21if pd.isna(carving): carving_type="БР"22print(f"product: {product}; diametr: {diametr}; diametr_type: {diametr_type}; carving: {carving}; carving_type: {carving_type}; strength_class_type: {strength_group}")23product_up=f"{product}{diametr_type} {strength_group} {carving_type}"24row["error"] = pd.NA25except Exception as exp:26row["error"] = f"{exp}"27finally:28row["Продукт УП"]=product_up29row["Время укрупнения"]=datetime.datetime.now()30return row31
32def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:33try:34if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)35else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)36except: raise37
38def get_compiled(self):39code:str=f"print('{__file__}')"40try:41with open(__file__,encoding="utf-8",mode="r") as f:42code=f.read()43except Exception as exp:44code=f"print('error: {exp}')"45finally:46cc = compile(code,"","exec")47return cc48
49if __name__=="__billet_sleeve_t3__":50consolidator:MainConsolidator51record:pd.Series52result:pd.Series53result = handler.handle(record,consolidator)54
55