consolidator
75 строк · 3.5 Кб
1import os2import sys3import pandas as pd4import datetime5from MainConsolidator import MainConsolidator6
7class handler(object):8@staticmethod9def module_name():10return 'Труба нефтепроводная ТЭСЦ-5'11@staticmethod12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:13product_up = None14try:15product = row["Первичный продукт"]16strength_1 = consolidator.strength_by_steel(row["Марка стали <Производство>"])17strength_steel = consolidator.strength_mapping(strength_1,row["Марка стали <Производство>"])18strength_led = consolidator.strength_led(strength_steel[0]) # ????19gmsps = consolidator.get_gmsps(strength_steel[1],product)20
21# gmsps = row["ГМСПС"]22thickness = row["Толщина стенки, мм <Производство>"]23diametr = row["Диаметр, мм <Производство>"]24diametr_led = consolidator.nearest_in_guid("Параметры по Продукту ТЭСЦ-5",25f"`Производство`=='Труба нефтепроводная ТЭСЦ-5' and `Продукт`=='{product}'",26"Доп параметр1",27diametr,28"Доп параметр1")29diametr_led_s = str(diametr_led).replace(".0","")30print(f"product: {product}; gmsps: {gmsps}; thickness: {thickness}; diametr: {diametr}; diametr_led: {diametr_led}; ")31thickness_range = None32if "ГУ" in gmsps or "ГФ" in gmsps:33thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-5",34f"`Производство`=='Труба нефтепроводная ТЭСЦ-5' and `Продукт`=='{product}' and `Доп параметр2` == 'ГУ' and `Мин`<={thickness}<=`Макс`","Диапазон")35product_up=f"{product}{diametr_led_s} {thickness_range} ГУ"36else:37product_up=f"{product}{diametr_led_s} {gmsps}"38
39if diametr_led==219:40product_up= product_up + " Т5"41
42
43# print(f"strength_1: {strength_1}; strength_steel: {strength_steel}; strength_led: {strength_led}; gmsps_: {gmsps_}" )44
45
46row["error"] = pd.NA47except Exception as exp:48row["error"] = f"{exp}"49finally:50row["Продукт УП"]=product_up51row["Время укрупнения"]=datetime.datetime.now()52return row53
54def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:55try:56if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)57else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)58except: raise59
60def get_compiled(self):61code:str=f"print('{__file__}')"62try:63with open(__file__,encoding="utf-8",mode="r") as f:64code=f.read()65except Exception as exp:66code=f"print('error: {exp}')"67finally:68cc = compile(code,"","exec")69return cc70
71if __name__=="__pipe_oil_t5__":72consolidator:MainConsolidator73record:pd.Series74result:pd.Series75result = handler.handle(record,consolidator)76
77