123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import pandas as pd
- # from logs_conf.logger import *
- from logs.logger import *
- class ControlPeriodStepAdjust(object):
- def __init__(self, dict_input):
- self.dict_input = dict_input
- self.data_upper_correct = pd.DataFrame()
- self.dict_code = {}
- self.dict_chiller_inner = {}
- # def step_adjust(self):
- # """
- # 根据历史安全压差对步长进行调整
- # """
- # preDiffMin = self.data_upper_correct['preDiff'].min()
- # if preDiffMin < 50:
- # if self.dict_chiller_inner['waterTempControlMode'] == 0:
- # if self.water_temp_set_new > (self.dict_chiller_inner['chillerWaterTempSet'] + 0.3):
- # self.water_temp_set_new = self.dict_chiller_inner['chillerWaterTempSet'] + 0.3
- # elif self.dict_chiller_inner['waterTempControlMode'] == 1:
- # if self.water_temp_set_new > (self.dict_chiller_inner['chillerWaterTempInSet'] + 0.3):
- # self.water_temp_set_new = self.dict_chiller_inner['chillerWaterTempInSet'] + 0.3
- # else:
- # self.water_temp_set_new = ''
- # # logger.critical('==============冷机控制选择输入错误==============')
- # return None
- # def control_period_adjust(self):
- # """
- # 根据采样周期进行调整
- # 采样周期不可低于80秒,否则会出现负值
- # :return:
- # """
- # tempLimit = 0.00125 * self.dict_code['controlPeriodNew'] - 0.1
- # if self.dict_chiller_inner['runMode'] == 0:
- # if self.dict_chiller_inner['waterTempControlMode'] == 0:
- # if self.water_temp_set_new > (self.dict_chiller_inner['chillerWaterTempSet'] + tempLimit):
- # self.water_temp_set_new = self.dict_chiller_inner['chillerWaterTempSet'] + tempLimit
- # elif self.dict_chiller_inner['waterTempControlMode'] == 1:
- # if self.water_temp_set_new > (self.dict_chiller_inner['chillerWaterTempInSet'] + tempLimit):
- # self.water_temp_set_new = self.dict_chiller_inner['chillerWaterTempInSet'] + tempLimit
- # else:
- # self.water_temp_set_new = ''
- # # logger.critical('==============冷机控制选择输入错误==============')
- # else:
- # if self.dict_chiller_inner['waterTempControlMode'] == 0:
- # if self.water_temp_set_new < (self.dict_chiller_inner['heatingWaterTempSet'] - tempLimit):
- # self.water_temp_set_new = self.dict_chiller_inner['heatingWaterTempSet'] - tempLimit
- # elif self.dict_chiller_inner['waterTempControlMode'] == 1:
- # if self.water_temp_set_new < (self.dict_chiller_inner['heatingWaterTempInSet'] - tempLimit):
- # self.water_temp_set_new = self.dict_chiller_inner['heatingWaterTempInSet'] - tempLimit
- # else:
- # self.water_temp_set_new = ''
- # # logger.critical('==============冷机控制选择输入错误==============')
- # return None
- def control_time_diff_cal(self):
- """
- 分别计算升温控制时间差和降温控制时间差
- :return:
- """
- self.dict_chiller_inner['triggerTime'] = pd.to_datetime(self.dict_chiller_inner['triggerTime'])
- # self.dict_code['controlTimeLatest'] = pd.to_datetime(self.dict_code['controlTimeLatest'])
- # self.dict_code['controlTimeDiff'] = (
- # self.dict_chiller_inner['triggerTime'] - self.dict_code['controlTimeLatest']).total_seconds()
- # 升温控制时间差
- self.dict_code['upControlTimeLatest'] = pd.to_datetime(self.dict_code['upControlTimeLatest'])
- self.dict_code['upControlTimeDiff'] = (
- self.dict_chiller_inner['triggerTime'] - self.dict_code['upControlTimeLatest']).total_seconds()
- # 降温控制时间差
- self.dict_code['downControlTimeLatest'] = pd.to_datetime(self.dict_code['downControlTimeLatest'])
- self.dict_code['downControlTimeDiff'] = (
- self.dict_chiller_inner['triggerTime'] - self.dict_code['downControlTimeLatest']).total_seconds()
- # self.dict_code['controlPeriodNew'] = self.dict_code['controlTimeDiff'] # 这里的赋值待确认 #######
- return self.dict_code
- def pointwise_temp_diff_cal(self):
- """
- 逐点温差的计算,当前只考虑了出水温度数量为1的场景,若出水温度数量大于1则需要分情况计算,待迭代
- :return:
- """
- temp_diff_list = []
- if self.dict_chiller_inner['runMode'] == 0:
- for i in range(1, len(self.dict_chiller_inner['chillerWaterTempOut'])):
- temp_diff = self.dict_chiller_inner['chillerWaterTempOut'][i] - \
- self.dict_chiller_inner['chillerWaterTempOut'][i - 1]
- temp_diff_list.append(temp_diff)
- elif self.dict_chiller_inner['runMode'] == 1:
- for i in range(1, len(self.dict_chiller_inner['coolingWaterTempOut'])):
- temp_diff = self.dict_chiller_inner['coolingWaterTempOut'][i] - \
- self.dict_chiller_inner['coolingWaterTempOut'][i - 1]
- temp_diff_list.append(temp_diff)
- else:
- logger.critical('============冷机运行模式输入错误============')
- return temp_diff_list
- def control_period_cal(self, is_safety_issue):
- """
- 计算控制周期是否满足调控周期,满足则控制,不满足则再进一步判断安全因素
- 判断安全因素时需要计算逐点温差
- :param is_safety_issue: 是否存在安全运行问题,三个安全校验的最终结果
- :return:
- """
- self.control_time_diff_cal()
- if self.dict_code['upControlTimeDiff'] > self.dict_code['upTempControlPeriod'] * 60 or \
- self.dict_code['downControlTimeDiff'] > self.dict_code['downTempControlPeriod'] * 60:
- is_control = 1
- # self.dict_code['controlPeriodNew'] = self.dict_code['controlPeriod'] # 这里的赋值待确认 #######
- logger.critical('============正常控制1:控制时间差已满足条件,设备正常控制============')
- else:
- if is_safety_issue:
- temp_diff_list = self.pointwise_temp_diff_cal()
- if temp_diff_list:
- if max(temp_diff_list) < 0.2 or (self.dict_code['upControlTimeDiff'] > 180 and
- self.dict_code['downControlTimeDiff'] > 180): # 这里的逻辑待确认 #######
- is_control = 1
- logger.critical('============正常控制2:存在安全运行风险,设备正常控制============')
- else:
- is_control = 0
- logger.critical('============不控制:控制时间差不满足条件,设备不控制============')
- else:
- is_control = 1
- else:
- is_control = 0
- logger.critical('============不控制:控制时间差不满足条件,且不存在安全运行风险,设备不控制============')
- return is_control
|