123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- from data_initialize_standard.data_standardization import DataStandardization
- from water_temp_cal.water_temp_setpoint_new import SetPointStrategyOff, SetPointStrategyOnChillerOff,\
- SetPointStrategyOnChillerOnAsynchronous, SetPointStrategyOnChillerOnSynchronous,\
- JudgeSynchronizeAsynchronous, JudgeTempControlMode
- from data_initialize_standard.results import *
- from water_temp_cal.water_temp_set_switch import WaterTempSetVerify
- from temp_humid_cal.temp_humi_calculation import *
- from optimized_and_individal.control_period_step_adjust import ControlPeriodStepAdjust
- from optimized_and_individal.frequently_start_stop import JudgeFrequentlyStartStop
- # from logs_conf.logger import *
- from logs.logger import *
- import pandas as pd
- import time
- class PublicMethodClass(ControlPeriodStepAdjust):
- def __init__(self, dict_input):
- super(PublicMethodClass, self).__init__(dict_input)
- self.dict_chiller_outer = {}
- # self.modify_data = {}
- self.dict_results = {}
- self.data_temp_humi = pd.DataFrame()
- self.isAdjustWaterTemp = 0
- self.isControl = False
- self.water_temp_set_new = None
- self.results_depict = None
- self.judge_syn_asy = '' # 同步算法或异步算法
- self.excess_result = {}
- self.terminal_cal = False
- # def is_null_judge(self):
- # self.ds = DataStandardization(self.dict_input)
- # dict_back_useless = self.ds.dict_useless()
- # Num = self.ds.null_judge()
- # return dict_back_useless, Num
- def output_abnormal_situation(self, Num, is_control=1):
- """
- 异常情况的输出
- :param Num:
- :param is_control:
- :return:
- """
- if Num > 0:
- self.results_depict = '输入参数存在空值,无计算结果'
- elif self.dict_code['controlMode'] == 0:
- self.results_depict = '智控开关状态关闭,无计算结果'
- elif is_control == 0:
- self.results_depict = '距上次下发指令周期太短,无计算结果'
- else:
- self.results_depict = '输入参数错误,无计算结果'
- logger.critical("============%s============" % self.results_depict)
- self.dict_results = DictResultsNull(self.dict_chiller_outer, self.dict_chiller_inner, self.dict_code,
- self.results_depict)
- return None
- def output_normal_situation(self, is_safety_issue):
- """
- 正常计算下的输出
- :param is_safety_issue: 是否存在安全运行问题
- :return:
- """
- # if self.isAdjustWaterTemp == 1:
- # if self.dict_code['isHardwareControl'] == 1:
- # if self.isAdjustWaterTemp == 1:
- # self.isControl = True
- # else:
- # self.results_depict = '计算正常,但不向硬件层发送指令'
- # self.is_hardware_control() # 控制模块
- parameter = (is_safety_issue, self.isControl, self.results_depict, self.water_temp_set_new, self.dict_chiller_inner,
- self.dict_chiller_outer, self.dict_code, self.data_temp_humi, self.excess_result, self.terminal_cal)
- self.dict_results = DictResultsNormal(*parameter)
- def water_temp_set_verify(self, cal_mode):
- """
- 水温验证与转换,验证是否超限,转换单位等
- cal_mode: False表示停机状态下的水温计算;True表示运行状态下的水温计算
- :return:
- """
- wtst = WaterTempSetVerify(self.water_temp_set_new, self.dict_chiller_inner)
- if cal_mode:
- self.water_temp_set_new = wtst.modify_verify()
- else:
- self.water_temp_set_new = wtst.limit_verify()
- logger.critical('============经水温设定值校核后,最新水温设定值为 %s ℃============' % self.water_temp_set_new)
- return self.water_temp_set_new
- def is_adjust_judge(self):
- control_time_diff = self.control_time_diff_cal() # -----校验一下数据··········
- if self.dict_chiller_inner['runMode'] == 0:
- if self.dict_chiller_inner['waterTempControlMode'] == 0:
- delta_temp = self.water_temp_set_new - self.dict_chiller_inner['chillerWaterTempSet']
- else:
- delta_temp = self.water_temp_set_new - self.dict_chiller_inner['chillerWaterTempInSet']
- if (abs(delta_temp) < self.dict_code['minControlStep'] and self.dict_code['controlMode'] == 1 and
- self.judge_syn_asy == 0 and self.dict_chiller_inner['runStatus'][-1] == 1) or delta_temp == 0:
- self.results_depict = '制冷工况:计算正常,水温调整幅度太小,不进行调整'
- else:
- if (delta_temp > 0 and control_time_diff['upControlTimeDiff'] > control_time_diff['upTempControlPeriod']) \
- or (delta_temp < 0 and control_time_diff['downControlTimeDiff'] > control_time_diff['downTempControlPeriod']):
- self.isAdjustWaterTemp = 1
- self.results_depict = '制冷工况:计算正常,水温满足调整条件'
- else:
- self.results_depict = '制冷工况:计算正常,不满足控制周期,不进行调整'
- elif self.dict_chiller_inner['runMode'] == 1:
- if self.dict_chiller_inner['waterTempControlMode'] == 0:
- delta_temp = self.water_temp_set_new - self.dict_chiller_inner['heatingWaterTempSet']
- else:
- delta_temp = self.water_temp_set_new - self.dict_chiller_inner['heatingWaterTempInSet']
- if (abs(delta_temp) < self.dict_code['minControlStep'] and self.dict_code['controlMode'] == 1 and
- self.judge_syn_asy == 0 and self.dict_chiller_inner['runStatus'][-1] == 1) or delta_temp == 0:
- self.results_depict = '制热工况:计算正常,水温调整幅度太小,不进行调整'
- else:
- if (delta_temp > 0 and control_time_diff['upControlTimeDiff'] > control_time_diff['upControlPeriod']) \
- or (delta_temp < 0 and control_time_diff['downControlTimeDiff'] > control_time_diff['downControlPeriod']):
- self.isAdjustWaterTemp = 1
- self.results_depict = '制热工况:计算正常,水温满足调整条件'
- else:
- self.results_depict = '制热工况:计算正常,不满足控制周期,不进行调整'
- else:
- self.results_depict = '冷机运行模式输入错误'
- if self.isAdjustWaterTemp == 1:
- if self.dict_code['isHardwareControl'] == 1:
- self.isControl = True
- else:
- self.results_depict += ',但不向硬件层发送指令'
- logger.critical('============ %s ============' % self.results_depict)
- # ----------------------------------------
- # -----------------重构重构-----------------
- def water_temp_set_cal(self):
- # 运行冷机的水温计算主要步骤
- # 监测点数据处理
- # 监测点计算
- # 监测点超标判断
- # 同步或异步判断
- # 进入同步或异步算法
- # 设定值校验
- # 监测点计算
- logger.critical('============监测点计算开始============')
- thf = TempHumiFunction(self.data_temp_humi, self.dict_code, self.dict_chiller_outer) # 监测点实时数据
- self.data_temp_humi = thf.temp_humi_cal()
- if self.data_temp_humi.shape[0]:
- # 监测点超标判断
- judge = JudgeOutRange(self.data_temp_humi, self.dict_code)
- self.excess_result = judge.is_out_of_range()
- # # 判断控制模式是否唯一(供水控制还是回水控制)
- jtcm = JudgeTempControlMode(self.dict_chiller_inner)
- judge_sin_mul = jtcm.is_single_control_strategy()
- if judge_sin_mul == 0 and not self.excess_result['isOutRange'] == '':
- parameter = (self.dict_chiller_inner, self.data_temp_humi)
- # 判断同步算法还是异步算法
- jsa = JudgeSynchronizeAsynchronous(self.dict_chiller_inner)
- self.judge_syn_asy = jsa.judge_synchronize_asynchronous() # 判断同步算法还是异步算法
- if self.judge_syn_asy == 1:
- logger.critical('============冷站设备异步,当前冷机水温设定值为 %s ℃,冷站内所有开机冷机设定值为 %s ============'
- % (self.dict_chiller_inner['chillerWaterTempSet'],
- self.dict_chiller_inner['allChillerWaterTempSetOn']))
- spsocoa = SetPointStrategyOnChillerOnAsynchronous(*parameter, self.excess_result) # 异步算法
- water_temp_set_new = spsocoa.set_point_asynchronous() # 异步算法
- logger.critical('============经过异步算法计算后,最新水温设定值为 %s ℃============' % water_temp_set_new)
- else:
- logger.critical('============冷站设备同步,当前冷机水温设定值为 %s ℃,冷站内所有开机冷机设定值为 %s ============'
- % (self.dict_chiller_inner['chillerWaterTempSet'],
- self.dict_chiller_inner['allChillerWaterTempSetOn']))
- spsocos = SetPointStrategyOnChillerOnSynchronous(*parameter, self.excess_result) # 同步算法
- water_temp_set_new, excess_result = spsocos.set_point_synchronous(self.dict_code['controlBasis']) # 同步算法
- logger.critical('============经过同步算法计算后,最新水温设定值为 %s ℃============' % water_temp_set_new)
- # 水温设定值限值校验
- water_temp_set_new = WaterTempSetVerify(water_temp_set_new, self.dict_chiller_inner).limit_verify()
- logger.critical('============当前水温设定值为 %s ℃,经限值校验后,最新水温设定值为 %s ℃============'
- % (self.dict_chiller_inner['chillerWaterTempSet'], water_temp_set_new))
- else:
- water_temp_set_new = None
- if judge_sin_mul != 0: # 供水和回水共存的场景暂不考虑
- logger.critical('============所有冷机水温控制方式不唯一,暂不适配此场景============')
- self.results_depict = '所有冷机水温控制方式不唯一,暂不适配此场景'
- else:
- logger.critical('============监测点超标判断出现异常,不进行水温调控============')
- self.results_depict = '监测点超标判断出现异常,不进行水温调控'
- else:
- water_temp_set_new = None
- self.results_depict = '所有末端开启时间太短,不进行水温调控'
- logger.critical('============所有末端开启时间太短,不进行水温调控============')
- return water_temp_set_new
- def water_temp_main_process(self):
- """
- 水温计算的主函数
- :return:
- """
- parameter = (self.dict_chiller_inner, self.data_temp_humi)
- if self.dict_code['controlMode'] == 0: # 智控关闭
- # 实际上不用做任何计算或动作,这里只是需要考虑 如果在节能评估期的初始工况日,确保冷机水温保持在设定值或以下即可(后续随产品迭代)
- # spso = SetPointStrategyOff(*parameter) # 智控关闭场景下,恢复模式下的水温
- # self.water_temp_set_new = spso.self_control_strategy_off() # 智控关闭下的水温设定,这里是恢复模式下的设定值
- logger.critical('============智控开关为关闭,不进行水温计算============')
- elif self.dict_code['controlMode'] == 1: # 智控开启
- logger.critical('============智控开关为开启,开始进行水温计算============')
- if self.dict_chiller_inner['runStatus'][-1] == 0: # 当前冷机状态为关机
- jfss = JudgeFrequentlyStartStop(self.dict_code, self.dict_chiller_inner)
- judge_freq_start_stop = jfss.is_freq_start_stop() # 判断是正常停机还是频繁启停
- if judge_freq_start_stop == 0: # 非频繁启停,则是停机下水温设定
- logger.critical('============设备处于停机状态,水温正常调控============')
- spsoco = SetPointStrategyOnChillerOff(*parameter) # 停机下水温设定值
- self.water_temp_set_new = spsoco.water_temp_set_confirm() # 判断停机时长是否超过16小时
- else:
- logger.critical('============设备处于频繁启停状态,水温正常调控============')
- self.water_temp_set_new = self.water_temp_set_cal() # 运行冷机的水温计算
- self.terminal_cal = True
- elif self.dict_chiller_inner['runStatus'][-1] == 1: # 当前冷机状态为运行
- logger.critical('============设备处于运行状态,水温正常调控============')
- self.water_temp_set_new = self.water_temp_set_cal() # 运行冷机的水温计算
- self.terminal_cal = True
- else:
- self.water_temp_set_new = None
- self.results_depict = '冷机运行状态输入错误'
- logger.critical('============冷机运行状态输入错误============')
- else:
- self.water_temp_set_new = None
- self.results_depict = '算法智控状态输入错误'
- logger.critical('============算法智控状态输入错误============')
- # if self.water_temp_set_new:
- # # 水温设定值校验
- # self.water_temp_set_new = round(self.water_temp_set_new, 1)
- # self.water_temp_set_verify(self.terminal_cal)
- # # 判断是否要调节水温
- # self.is_adjust_judge()
- return self.water_temp_set_new
|