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