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