consolidator
69 строк · 3.5 Кб
1import os
2import sys
3import pandas as pd
4import datetime
5from MainConsolidator import MainConsolidator
6
7class handler(object):
8@staticmethod
9def module_name():
10return 'Труба ТЭСЦ-1'
11@staticmethod
12def handle(row:pd.Series,consolidator:MainConsolidator)->pd.Series:
13product_up = None
14try:
15product = row["Первичный продукт"]
16vm_code = row['Вид материала в SAP ERP'][:4]
17pipe_type = consolidator.scalar_in_guid("Виды материалов ТЭСЦ-1",f"`Код`=='{vm_code}'","Тип трубы")
18if pipe_type=="НГП":
19strength_1 = consolidator.strength_by_steel(row["Марка стали <Производство>"])
20strength_steel = consolidator.strength_mapping(strength_1,row["Марка стали <Производство>"])
21gmsps = consolidator.get_gmsps(strength_steel[1],product)
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_s}; ")
31thickness_range = None
32if "ГУ" 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
39print(f"{product} - pipe_type: {pipe_type} ({vm_code})")
40row["error"] = pd.NA
41except Exception as exp:
42row["error"] = f"{exp}"
43finally:
44row["Продукт УП"]=product_up
45row["Время укрупнения"]=datetime.datetime.now()
46return row
47
48def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:
49try:
50if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)
51else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)
52except: raise
53
54def get_compiled(self):
55code:str=f"print('{__file__}')"
56try:
57with open(__file__,encoding="utf-8",mode="r") as f:
58code=f.read()
59except Exception as exp:
60code=f"print('error: {exp}')"
61finally:
62cc = compile(code,"","exec")
63return cc
64
65if __name__=="__pipe_t1__":
66consolidator:MainConsolidator
67record:pd.Series
68result:pd.Series
69result = handler.handle(record,consolidator)
70
71