consolidator
64 строки · 3.1 Кб
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["Первичный продукт"]
16strength_1 = consolidator.strength_by_steel(row["Марка стали <Производство>"])
17strength_steel = consolidator.strength_mapping(strength_1,row["Марка стали <Производство>"])
18gmsps = consolidator.get_gmsps(strength_steel[1],product)
19thickness = row["Толщина стенки, мм <Производство>"]
20diametr = row["Диаметр, мм <Производство>"]
21diametr_led = consolidator.nearest_in_guid("Параметры по Продукту ТЭСЦ-5",
22f"`Производство`=='Труба нефтепроводная ТЭСЦ-5' and `Продукт`=='{product}'",
23"Доп параметр1",
24diametr,
25"Доп параметр1")
26diametr_led_s = str(diametr_led).replace(".0","")
27print(f"product: {product}; gmsps: {gmsps}; thickness: {thickness}; diametr: {diametr}; diametr_led: {diametr_led_s}; ")
28thickness_range = None
29if "ГУ" in gmsps or "ГФ" in gmsps:
30thickness_range = consolidator.scalar_in_guid("Параметры по Продукту ТЭСЦ-5",
31f"`Производство`=='Труба нефтепроводная ТЭСЦ-5' and `Продукт`=='{product}' and `Доп параметр2` == 'ГУ' and `Мин`<={thickness}<=`Макс`","Диапазон")
32product_up=f"{product}{diametr_led_s} {thickness_range} ГУ"
33else:
34product_up=f"{product}{diametr_led_s} {gmsps}"
35row["error"] = pd.NA
36except Exception as exp:
37row["error"] = f"{exp}"
38finally:
39row["Продукт УП"]=product_up
40row["Время укрупнения"]=datetime.datetime.now()
41return row
42
43def debug_handle(self,inputDf:pd.DataFrame,consolidator:MainConsolidator,module:str=None)->pd.DataFrame:
44try:
45if module is None: return inputDf.apply(lambda row: self.handle(row,consolidator), axis=1)
46else: return inputDf[inputDf["Производство2"]==module].apply(lambda row: self.handle(row,consolidator), axis=1)
47except: raise
48
49def get_compiled(self):
50code:str=f"print('{__file__}')"
51try:
52with open(__file__,encoding="utf-8",mode="r") as f:
53code=f.read()
54except Exception as exp:
55code=f"print('error: {exp}')"
56finally:
57cc = compile(code,"","exec")
58return cc
59
60if __name__=="__pipe_oil_t1__":
61consolidator:MainConsolidator
62record:pd.Series
63result:pd.Series
64result = handler.handle(record,consolidator)
65
66