123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- from CoolProp.HumidAirProp import HAPropsSI
- from temp_humid_cal.excess_temp_modify import ExcessTempModify
- from temp_humid_cal.interval_start_stop_AHU import IntervalOnOffAHU
- from data_initialize_standard.constant import *
- # from logs_conf.logger import *
- from logs.logger import *
- import pandas as pd
- import time
- class TempHumiFunction(object):
- def __init__(self, terminal_data, code_data, chiller_outer):
- self.data = terminal_data
- self.config = code_data
- # self.modify = modify_data
- self.chiller_outer = chiller_outer
- self.chiller_mode = code_data['runMode']
- def terminal_limit_cal(self, data):
- """
- 监测点的限值计算
- :param data:
- :param dict_code:
- :return:
- """
- if self.chiller_mode == 0:
- data['tempLimit'] = data['coolingTempUpper'] - self.config['tempMargin']
- data['humiLimit'] = data['coolingHumiUpper'] - self.config['humiMargin']
- elif self.chiller_mode == 1:
- data['tempLimit'] = data['heatingTempDown'] + self.config['tempMargin']
- else:
- logger.critical("============冷机运行模式输入错误============")
- return data
- def delta_temp_humi(self, data):
- if self.chiller_mode == 0:
- data['deltaTemp'] = data['tempLimit'] - data['tempReal']
- data['deltaHumi'] = data['humiLimit'] - data['humiReal']
- elif self.chiller_mode == 1:
- data['deltaTemp'] = data['tempReal'] - data['tempLimit']
- data['deltaHumi'] = None
- else:
- logger.critical("============冷机运行模式输入错误============")
- return data
- def delta_dew_point(self, data):
- normal_condition = (data['tempReal'] <= TerminalTempRange['upperLimit']) & (data['tempReal'] > TerminalTempRange['lowerLimit']) & \
- (data['humiReal'] <= TerminalHumiRange['upperLimit']) & (data['humiReal'] > TerminalHumiRange['lowerLimit'])
- data_normal = data[normal_condition] # 筛选出温度和湿度范围在正常区间的数据,避免异常数据(如空值或极大值)调物性时出错
- data_abnormal = data.drop(data_normal.index)
- if self.chiller_mode == 0 and not data_normal.empty:
- data_normal.loc[:, ['dewTempReal']] = round(data_normal.apply(
- lambda x: HAPropsSI('D', 'T', x['tempReal'] + 273.15, 'P', 101325, 'R', x['humiReal'] / 100.0),
- axis=1) - 273.15, 1)
- data_normal.loc[:, ['dewTempLimit']] = round(data_normal.apply(
- lambda x: HAPropsSI('D', 'T', x['tempLimit'] + 273.15, 'P', 101325, 'R', x['humiLimit'] / 100.0),
- axis=1) - 273.15, 1)
- data_normal.loc[:, ['deltaDewPoint']] = data_normal['dewTempLimit'] - data_normal['dewTempReal']
- if not data_abnormal.empty:
- data_abnormal['dewTempReal'] = None
- data_abnormal['dewTempLimit'] = None
- data_abnormal['deltaDewPoint'] = None
- data = pd.concat([data_normal, data_abnormal])
- return data
- def excess_modify(self, terminal_data):
- data = self.delta_temp_humi(terminal_data)
- excess_condition = (data['deltaTemp'] < 0) | (data['deltaHumi'] < 0) # 温度或湿度超限的判断条件
- terminal_excess = data[excess_condition] # 温度或湿度超限的监测点
- terminal_remain = data[~excess_condition] # 未超限的监测点
- if not terminal_excess.empty:
- logger.critical("============存在监测点超限情况,开始温湿度限值修正计算============")
- etm = ExcessTempModify(terminal_excess, self.config, self.chiller_outer) # terminal_excess 超标的监测点数据
- if etm.data_judge():
- logger.critical("============监测点修正相关数据正常,进入修正计算============")
- Time1 = time.time()
- terminal_excess = etm.get_modified_air_temp_humi() # 温湿度计算
- Time2 = time.time()
- logger.critical("============温湿度超标点限值修正计算耗时: {}s ============".format(Time2 - Time1))
- else:
- logger.critical("============监测点修正相关数据异常,退出温湿度限值修正计算============")
- else:
- logger.critical("============不存在温度或湿度超限情况,温湿度上下限不修正============")
- data = pd.concat([terminal_excess, terminal_remain])
- return data
- def average_temp_humi(self, data_temp_humi):
- temp_mean = data_temp_humi["tempReal"].mean()
- humi_mean = data_temp_humi["humiReal"].mean()
- data_mean = {"tempHumiMeterId": "average", "terminalName": "average", "coolingTempUpper": 25,
- "coolingHumiUpper": 60, "heatingTempDown": 29} # 这里的上下限值实际取平均限值配置值,当前不适配写死
- if self.chiller_mode == 0:
- data_mean['tempLimit'] = data_mean['coolingTempUpper'] - self.config['tempMargin']
- data_mean['humiLimit'] = data_mean['coolingHumiUpper'] - self.config['humiMargin']
- data_mean['deltaTemp'] = data_mean['tempLimit'] - temp_mean
- data_mean['deltaHumi'] = data_mean['humiLimit'] - humi_mean
- elif self.chiller_mode == 1:
- data_mean['tempLimit'] = data_mean['heatingTempDown'] + self.config['tempMargin']
- data_mean['deltaTemp'] = data_mean['tempReal'] - data_mean['tempLimit']
- data_mean['deltaHumi'] = None
- else:
- logger.critical("============冷机运行模式输入错误============")
- data_mean_df = pd.DataFrame([data_mean])
- if self.config['calMode'] == 1:
- data = data_mean_df
- else:
- data = pd.concat([data_temp_humi, data_mean_df])
- return data
- def temp_humi_cal(self):
- data_temp_humi = self.terminal_limit_cal(self.data) # 确定监测点的上下限值
- if self.config['calMode'] == 0 or self.config['calMode'] == 2: # 监测点计算模式为常规或者综合
- if self.config['energyMode'] == 0: # 0为智能节能模式,1为需求优先模式
- logger.critical("============智控模式为智能节能模式,进入温湿度上下限修正计算============")
- data_temp_humi = self.excess_modify(data_temp_humi)
- else:
- logger.critical("============智控模式为需求优先模式,温湿度上下限不修正============")
- data_temp_humi = self.delta_temp_humi(data_temp_humi)
- data_temp_humi = self.delta_dew_point(data_temp_humi)
- ioa = IntervalOnOffAHU(data_temp_humi, self.config)
- data_temp_humi = ioa.exclude_ahu_short_time()
- if self.config['calMode'] == 1 or self.config['calMode'] == 2: # 监测点计算模式为仅平均温湿度或者综合
- logger.critical("============监测点计算模式为仅平均温湿度或综合模式,进入平均温湿度计算============")
- data_temp_humi = self.average_temp_humi(data_temp_humi)
- return data_temp_humi
- class JudgeOutRange(object):
- def __init__(self, data_temp_humi, dict_code):
- self.data = data_temp_humi
- self.config = dict_code
- self.chiller_mode = dict_code['runMode']
- def is_out_of_range(self):
- """制冷模式根据 控制依据 配置项判断 温度、露点或湿度是否超标,制热模式下只判断温度是否超标"""
- results = {'isOutRange': '', 'minDelta': '', 'minName': ''} # 分别代表是否超标,最不利监测点对应值,最不利监测点名称
- if self.chiller_mode == 0 and self.config['controlBasis'] == 0: # 制冷模式,控制依据,0为仅温度,1为仅湿度,2为温度和湿度
- if self.data['deltaTemp'].min() < 0:
- results['isOutRange'] = 1 # 1表示温度超标
- results['minName'] = self.data.loc[self.data['deltaTemp'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:温度超标,最不利监测点是 %s============" % (results['minName']))
- elif self.data['deltaDewPoint'].min() < 0:
- results['isOutRange'] = 2 # 2表示露点超标
- results['minName'] = self.data.loc[self.data['deltaDewPoint'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:露点超标,最不利监测点是 %s============" % (results['minName']))
- else:
- if (self.data['deltaTemp'].min() is None) or pd.isna(self.data['deltaTemp'].min()):
- logger.critical("============监测点超标情况:监测点输入数据异常============")
- else:
- results['isOutRange'] = 0 # 0表示不超标
- results['minName'] = self.data.loc[self.data['deltaTemp'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:无超标情况,最不利监测点是 %s============" % (results['minName']))
- elif self.chiller_mode == 0 and self.config['controlBasis'] == 1:
- if self.data['deltaHumi'].min() < 0:
- results['isOutRange'] = 3 # 3表示湿度超标
- results['minName'] = self.data.loc[self.data['deltaHumi'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:湿度超标,最不利监测点是 %s============" % (results['minName']))
- else:
- if (self.data['deltaHumi'].min() is None) or pd.isna(self.data['deltaHumi'].min()):
- logger.critical("============监测点超标情况:监测点输入数据异常============")
- else:
- results['isOutRange'] = 0 # 0表示不超标
- results['minName'] = self.data.loc[self.data['deltaHumi'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:无超标情况,最不利监测点是 %s============" % (results['minName']))
- elif self.chiller_mode == 0 and self.config['controlBasis'] == 2:
- if self.data['deltaTemp'].min() < 0:
- results['isOutRange'] = 1 # 1表示温度超标
- results['minName'] = self.data.loc[self.data['deltaTemp'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:温度超标,最不利监测点是 %s============" % (results['minName']))
- elif self.data['deltaHumi'].min() < 0:
- results['isOutRange'] = 3 # 3表示湿度超标
- results['minName'] = self.data.loc[self.data['deltaHumi'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:湿度超标,最不利监测点是 %s============" % (results['minName']))
- else:
- if (self.data['deltaTemp'].min() is None) or pd.isna(self.data['deltaTemp'].min() is None):
- logger.critical("============监测点超标情况:监测点输入数据异常============")
- else:
- results['isOutRange'] = 0 # 0表示不超标
- results['minName'] = self.data.loc[self.data['deltaTemp'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:无超标情况,最不利监测点是 %s============" % (results['minName']))
- elif self.chiller_mode == 1:
- if self.data['deltaTemp'].min() < 0:
- results['isOutRange'] = 1 # 1表示超标, 0表示不超标
- results['minName'] = self.data.loc[self.data['deltaTemp'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:温度超标,最不利监测点是 %s============" % (results['minName']))
- else:
- if (self.data['deltaTemp'].min() is None) or pd.isna(self.data['deltaTemp'].min()):
- logger.critical("============监测点超标情况:监测点输入数据异常============")
- else:
- results['isOutRange'] = 0
- results['minName'] = self.data.loc[self.data['deltaTemp'].idxmin(), 'ahuName']
- logger.critical("============监测点超标情况:温度超标,最不利监测点是 %s============" % (results['minName']))
- else:
- logger.critical("============冷机运行模式输入错误============")
- return results
- # if __name__ == '__main__':
- #
- # # 监测点的实时数据
- # data_df_cal = pd.DataFrame({
- # "tempHumiMeterId": ["3000638", "3000694", "3000691", "3000692", "3000693"],
- # "terminalName": ["监测点A", "监测点B", "监测点C", "监测点D", "监测点E"],
- # 'ahuStartTime': ["2025-4-10 23:00:00", "2025-4-10 23:00:00", "2025-4-10 23:00:00",
- # "2025-4-10 23:00:00", "2025-4-10 23:00:00"],
- # "coolingTempUpper": [25.0, 26.0, 25, 25, 25],
- # "coolingHumiUpper": [60.0, 65.0, 65, 65, 65],
- # "heatingTempDown": [18.0, 17.5, 24, 24, 26],
- # # "tempReal": [None, None, None, None, None],
- # "tempReal": [24.5, 25.3, 24, 20, 20],
- # "humiReal": [50, 50, 50, 50, 50],
- # # "humiReal": [None, None, None, None, None],
- # })
- #
- # station_data_ = {"chilledWaterMainTempOut": [7, 7, 7],
- # 'timeIndex': ["2025-4-3 12:00:00", "2025-4-4 12:00:00", "2025-4-5 12:00:00"]}
- #
- # sensor_data_ = {
- # "3000638": {"name": "sensor1", "tempReal": [10, 20, 30], "humiReal": [10, 20, 30], "tempSupply": [1, 2, 3]},
- # "3000694": {"name": "sensor2", "tempReal": [10, 20, 30], "humiReal": [10, 20, 30], "tempSupply": [1, 2, 3]},
- # "3000654": {"name": "sensor3", "tempReal": [10, 20, 30], "humiReal": [10, 20, 30], "tempSupply": [1, 2, 3]}}
- # # 冷机的历史7天数据
- # chiller_data_ = {"301": {"name": 1, "currentPercent": [20, 20, 30], "chillerPowerRatio": [50, 50, 50],
- # "chillerWaterTempOut": [7, 7, 7], "set": [7, 7, 7],
- # 'waterTempControlMode': 0, 'chillerWaterTempSetInitial': 7, 'capacity': 10},
- # "302": {"name": 1, "currentPercent": [10, 20, 30], "chillerPowerRatio": [50, 50, 50],
- # "chillerWaterTempOut": [7, 7, 7], "set": [7, 7, 7],
- # 'waterTempControlMode': 0, 'chillerWaterTempSetInitial': 7, 'capacity': 10}}
- # modify_data = {'terminalData': sensor_data_, 'chillerData': chiller_data_, 'stationData': station_data_}
- # config_info = {"handleService": 1, "controlMode": 1, "isHardwareControl": 1, "calPeriod": 3,
- # "minControlStep": 0.1, "chillerWaterTempSetInitial": 7, "chillerWaterTempSetUpper": 12,
- # "chillerWaterTempSetLower": 7, "energyMode": 1, "controlBasis": 0, "tempMargin": 0.2,
- # "humiMargin": 2, "mainTempMode": 0, "samplePeriod": 60, "upTempControlPeriod": 10,
- # "downTempControlPeriod": 12, 'runMode': 0, 'calMode': 0, 'allChillerControlSelect': [0, 0, 0],
- # 'triggerTime': "2025-4-5 12:00:00"}
- # thf = TempHumiFunction(data_df_cal, config_info, modify_data) # 监测点实时数据,冷站数据
- # data = thf.temp_humi_cal() # 监测点历史数据,冷机历史数据
- # pd.set_option('display.max_rows', None)
- # pd.set_option('display.max_columns', None)
- #
- # judge = JudgeOutRange(data, config_info)
- # result = judge.is_out_of_range()
|