consolidator
58 строк · 2.9 Кб
1import os
2import sys
3import pandas as pd
4import datetime
5from MainConsolidator import MainConsolidator
6
7class handler(object):
8@staticmethod
9def module_name():
10return 'Труба бесшовная нефтегазопроводная ТПЦ'
11@staticmethod
12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:
13product_up = "не реализовано"
14try:
15product = row["Первичный продукт"]
16thickness = row["Толщина стенки, мм <Производство>"]
17diametr = row["Диаметр, мм <Производство>"]
18vm_code = row['Вид материала в SAP ERP'][:4]
19steel_mark = row["Марка стали <Производство>"]
20
21pipe_type = consolidator.scalar_in_guid("Виды материалов ТПЦ",f"`Код`=='{vm_code}'","Тип трубы")
22diametr_led = consolidator.nearest_in_guid("Параметры по Продукту ТПЦ",f"`Производство`=='Труба бесшовная ТПЦ'","Диаметр",diametr,"Диаметр")
23diametr_led_s = str(diametr_led).replace(".0","")
24thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТПЦ",f"`Производство`=='Труба бесшовная ТПЦ' and `Мин`<={thickness}<=`Макс`","Диапазон")
25gmsps = consolidator.get_gmsps(steel_mark,product)
26# if pd.isna(gmsps): gmsps = f"[{steel_mark}]" # for debug
27print(f"{product}: {thickness}: {diametr} -> {diametr_led_s}: {pipe_type} : {gmsps} <- {steel_mark}")
28product_up = f"{product} Д{diametr_led_s} {thickness_range} {gmsps}"
29row["error"] = pd.NA
30except Exception as exp:
31row["error"] = f"{exp}"
32finally:
33row["Продукт УП"]=product_up
34row["Время укрупнения"]=datetime.datetime.now()
35return row
36
37def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:
38try:
39if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)
40else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)
41except: raise
42
43def get_compiled(self):
44code:str=f"print('{__file__}')"
45try:
46with open(__file__,encoding="utf-8",mode="r") as f:
47code=f.read()
48except Exception as exp:
49code=f"print('error: {exp}')"
50finally:
51cc = compile(code,"","exec")
52return cc
53
54if __name__=="__pipe_ngp_tpc__":
55consolidator:MainConsolidator
56record:pd.Series
57result:pd.Series
58result = handler.handle(record,consolidator)
59
60