from typing import Union from datetime import datetime import numpy as np import pandas as pd from ..DHU.config_reader import ConfigReader as ConfigReader_DHU class ConfigReader: def __init__( self, path, DHU_AB_config:ConfigReader_DHU = None ): self.path = path self.room = pd.read_excel(self.path,sheet_name='房间') self.app = pd.read_excel(self.path,sheet_name='程序') self.all_room_dew = set(self.room.loc[:,'房间露点温度'].to_list()) self.DHU_AB_config:ConfigReader_DHU = DHU_AB_config def get_room_info(self,room_dew,info_name) -> str: info = self.room.loc[lambda dt:dt.房间露点温度==room_dew,info_name].to_list()[0] return info def get_point(self,room_dew) -> dict: if room_dew not in self.all_room_dew: raise ValueError('房间露点温度不存在') point = {'Droom':room_dew} if self.DHU_AB_config is not None: equp_name = self.get_room_info(room_dew,'设备编号') equp_point = self.DHU_AB_config.get_equp_point( equp_name = equp_name, equp_type = self.get_room_info(room_dew,'设备类型'), equp_class = 'B' ) point['Dout'] = equp_name + '_' + equp_point['wheel_2_DoutP'] return point def get_app_info( self, equp_name: str, app_type : str, key : str, info_type: str = None ) -> str: value = self.app.loc[lambda dt:(dt.程序类型==app_type) & (dt.项目==key)] if value.shape[0] != 1: raise Exception(f'程序类型({app_type})下不存在唯一的的项目({key})') info_value = value.loc[:,'全局配置'].iat[0] # 更新全局配置 if equp_name in value.columns: equp_value = value.loc[:,equp_name].iat[0] if isinstance(equp_value,(str,float)) and not np.isnan(equp_value): info_value = equp_value # 调整数据类型 info_value = convert_info_type(info_value,info_type) return info_value def convert_info_type(info_value,info_type): if info_type == 'int': info_value = int(info_value) elif info_type == 'float': info_value = float(info_value) elif info_type == 'bool': info_value = bool(info_value) elif info_type == 'datetime': if info_value == 'NOW': info_value = datetime.now() elif not isinstance(info_value,datetime): info_value = datetime.strptime(info_value,'%Y/%m/%d %H:%M:%S') elif info_type == 'str': info_value = str(info_value) elif info_type is None: pass else: raise ValueError(f"{info_type} type error!") return info_value