public_method.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. from data_initialize_standard.data_standardization import DataStandardization
  2. from water_temp_cal.water_temp_setpoint_new import SetPointStrategyOff, SetPointStrategyOnChillerOff,\
  3. SetPointStrategyOnChillerOnAsynchronous, SetPointStrategyOnChillerOnSynchronous,\
  4. JudgeSynchronizeAsynchronous, JudgeTempControlMode
  5. from data_initialize_standard.results import *
  6. from water_temp_cal.water_temp_set_switch import WaterTempSetVerify
  7. from temp_humid_cal.temp_humi_calculation import *
  8. from optimized_and_individal.control_period_step_adjust import ControlPeriodStepAdjust
  9. from optimized_and_individal.frequently_start_stop import JudgeFrequentlyStartStop
  10. # from logs_conf.logger import *
  11. from logs.logger import *
  12. import pandas as pd
  13. import time
  14. class PublicMethodClass(ControlPeriodStepAdjust):
  15. def __init__(self, dict_input):
  16. super(PublicMethodClass, self).__init__(dict_input)
  17. self.dict_chiller_outer = {}
  18. # self.modify_data = {}
  19. self.dict_results = {}
  20. self.data_temp_humi = pd.DataFrame()
  21. self.isAdjustWaterTemp = 0
  22. self.isControl = False
  23. self.water_temp_set_new = None
  24. self.results_depict = None
  25. self.judge_syn_asy = '' # 同步算法或异步算法
  26. self.excess_result = {}
  27. self.terminal_cal = False
  28. # def is_null_judge(self):
  29. # self.ds = DataStandardization(self.dict_input)
  30. # dict_back_useless = self.ds.dict_useless()
  31. # Num = self.ds.null_judge()
  32. # return dict_back_useless, Num
  33. def output_abnormal_situation(self, Num, is_control=1):
  34. """
  35. 异常情况的输出
  36. :param Num:
  37. :param is_control:
  38. :return:
  39. """
  40. if Num > 0:
  41. self.results_depict = '输入参数存在空值,无计算结果'
  42. elif self.dict_code['controlMode'] == 0:
  43. self.results_depict = '智控开关状态关闭,无计算结果'
  44. elif is_control == 0:
  45. self.results_depict = '距上次下发指令周期太短,无计算结果'
  46. else:
  47. self.results_depict = '输入参数错误,无计算结果'
  48. logger.critical("============%s============" % self.results_depict)
  49. self.dict_results = DictResultsNull(self.dict_chiller_outer, self.dict_chiller_inner, self.dict_code,
  50. self.results_depict)
  51. return None
  52. def output_normal_situation(self, is_safety_issue):
  53. """
  54. 正常计算下的输出
  55. :param is_safety_issue: 是否存在安全运行问题
  56. :return:
  57. """
  58. # if self.isAdjustWaterTemp == 1:
  59. # if self.dict_code['isHardwareControl'] == 1:
  60. # if self.isAdjustWaterTemp == 1:
  61. # self.isControl = True
  62. # else:
  63. # self.results_depict = '计算正常,但不向硬件层发送指令'
  64. # self.is_hardware_control() # 控制模块
  65. parameter = (is_safety_issue, self.isControl, self.results_depict, self.water_temp_set_new, self.dict_chiller_inner,
  66. self.dict_chiller_outer, self.dict_code, self.data_temp_humi, self.excess_result, self.terminal_cal)
  67. self.dict_results = DictResultsNormal(*parameter)
  68. def water_temp_set_verify(self, cal_mode):
  69. """
  70. 水温验证与转换,验证是否超限,转换单位等
  71. cal_mode: False表示停机状态下的水温计算;True表示运行状态下的水温计算
  72. :return:
  73. """
  74. wtst = WaterTempSetVerify(self.water_temp_set_new, self.dict_chiller_inner)
  75. if cal_mode:
  76. self.water_temp_set_new = wtst.modify_verify()
  77. else:
  78. self.water_temp_set_new = wtst.limit_verify()
  79. logger.critical('============经水温设定值校核后,最新水温设定值为 %s ℃============' % self.water_temp_set_new)
  80. return self.water_temp_set_new
  81. def is_adjust_judge(self):
  82. control_time_diff = self.control_time_diff_cal() # -----校验一下数据··········
  83. if self.dict_chiller_inner['runMode'] == 0:
  84. if self.dict_chiller_inner['waterTempControlMode'] == 0:
  85. delta_temp = self.water_temp_set_new - self.dict_chiller_inner['chillerWaterTempSet']
  86. else:
  87. delta_temp = self.water_temp_set_new - self.dict_chiller_inner['chillerWaterTempInSet']
  88. if (abs(delta_temp) < self.dict_code['minControlStep'] and self.dict_code['controlMode'] == 1 and
  89. self.judge_syn_asy == 0 and self.dict_chiller_inner['runStatus'][-1] == 1) or delta_temp == 0:
  90. self.results_depict = '制冷工况:计算正常,水温调整幅度太小,不进行调整'
  91. else:
  92. if (delta_temp > 0 and control_time_diff['upControlTimeDiff'] > control_time_diff['upTempControlPeriod']) \
  93. or (delta_temp < 0 and control_time_diff['downControlTimeDiff'] > control_time_diff['downTempControlPeriod']):
  94. self.isAdjustWaterTemp = 1
  95. self.results_depict = '制冷工况:计算正常,水温满足调整条件'
  96. else:
  97. self.results_depict = '制冷工况:计算正常,不满足控制周期,不进行调整'
  98. elif self.dict_chiller_inner['runMode'] == 1:
  99. if self.dict_chiller_inner['waterTempControlMode'] == 0:
  100. delta_temp = self.water_temp_set_new - self.dict_chiller_inner['heatingWaterTempSet']
  101. else:
  102. delta_temp = self.water_temp_set_new - self.dict_chiller_inner['heatingWaterTempInSet']
  103. if (abs(delta_temp) < self.dict_code['minControlStep'] and self.dict_code['controlMode'] == 1 and
  104. self.judge_syn_asy == 0 and self.dict_chiller_inner['runStatus'][-1] == 1) or delta_temp == 0:
  105. self.results_depict = '制热工况:计算正常,水温调整幅度太小,不进行调整'
  106. else:
  107. if (delta_temp > 0 and control_time_diff['upControlTimeDiff'] > control_time_diff['upControlPeriod']) \
  108. or (delta_temp < 0 and control_time_diff['downControlTimeDiff'] > control_time_diff['downControlPeriod']):
  109. self.isAdjustWaterTemp = 1
  110. self.results_depict = '制热工况:计算正常,水温满足调整条件'
  111. else:
  112. self.results_depict = '制热工况:计算正常,不满足控制周期,不进行调整'
  113. else:
  114. self.results_depict = '冷机运行模式输入错误'
  115. if self.isAdjustWaterTemp == 1:
  116. if self.dict_code['isHardwareControl'] == 1:
  117. self.isControl = True
  118. else:
  119. self.results_depict += ',但不向硬件层发送指令'
  120. logger.critical('============ %s ============' % self.results_depict)
  121. # ----------------------------------------
  122. # -----------------重构重构-----------------
  123. def water_temp_set_cal(self):
  124. # 运行冷机的水温计算主要步骤
  125. # 监测点数据处理
  126. # 监测点计算
  127. # 监测点超标判断
  128. # 同步或异步判断
  129. # 进入同步或异步算法
  130. # 设定值校验
  131. # 监测点计算
  132. logger.critical('============监测点计算开始============')
  133. thf = TempHumiFunction(self.data_temp_humi, self.dict_code, self.dict_chiller_outer) # 监测点实时数据
  134. self.data_temp_humi = thf.temp_humi_cal()
  135. if self.data_temp_humi.shape[0]:
  136. # 监测点超标判断
  137. judge = JudgeOutRange(self.data_temp_humi, self.dict_code)
  138. self.excess_result = judge.is_out_of_range()
  139. # # 判断控制模式是否唯一(供水控制还是回水控制)
  140. jtcm = JudgeTempControlMode(self.dict_chiller_inner)
  141. judge_sin_mul = jtcm.is_single_control_strategy()
  142. if judge_sin_mul == 0 and not self.excess_result['isOutRange'] == '':
  143. parameter = (self.dict_chiller_inner, self.data_temp_humi)
  144. # 判断同步算法还是异步算法
  145. jsa = JudgeSynchronizeAsynchronous(self.dict_chiller_inner)
  146. self.judge_syn_asy = jsa.judge_synchronize_asynchronous() # 判断同步算法还是异步算法
  147. if self.judge_syn_asy == 1:
  148. logger.critical('============冷站设备异步,当前冷机水温设定值为 %s ℃,冷站内所有开机冷机设定值为 %s ============'
  149. % (self.dict_chiller_inner['chillerWaterTempSet'],
  150. self.dict_chiller_inner['allChillerWaterTempSetOn']))
  151. spsocoa = SetPointStrategyOnChillerOnAsynchronous(*parameter, self.excess_result) # 异步算法
  152. water_temp_set_new = spsocoa.set_point_asynchronous() # 异步算法
  153. logger.critical('============经过异步算法计算后,最新水温设定值为 %s ℃============' % water_temp_set_new)
  154. else:
  155. logger.critical('============冷站设备同步,当前冷机水温设定值为 %s ℃,冷站内所有开机冷机设定值为 %s ============'
  156. % (self.dict_chiller_inner['chillerWaterTempSet'],
  157. self.dict_chiller_inner['allChillerWaterTempSetOn']))
  158. spsocos = SetPointStrategyOnChillerOnSynchronous(*parameter, self.excess_result) # 同步算法
  159. water_temp_set_new, excess_result = spsocos.set_point_synchronous(self.dict_code['controlBasis']) # 同步算法
  160. logger.critical('============经过同步算法计算后,最新水温设定值为 %s ℃============' % water_temp_set_new)
  161. # 水温设定值限值校验
  162. water_temp_set_new = WaterTempSetVerify(water_temp_set_new, self.dict_chiller_inner).limit_verify()
  163. logger.critical('============当前水温设定值为 %s ℃,经限值校验后,最新水温设定值为 %s ℃============'
  164. % (self.dict_chiller_inner['chillerWaterTempSet'], water_temp_set_new))
  165. else:
  166. water_temp_set_new = None
  167. if judge_sin_mul != 0: # 供水和回水共存的场景暂不考虑
  168. logger.critical('============所有冷机水温控制方式不唯一,暂不适配此场景============')
  169. self.results_depict = '所有冷机水温控制方式不唯一,暂不适配此场景'
  170. else:
  171. logger.critical('============监测点超标判断出现异常,不进行水温调控============')
  172. self.results_depict = '监测点超标判断出现异常,不进行水温调控'
  173. else:
  174. water_temp_set_new = None
  175. self.results_depict = '所有末端开启时间太短,不进行水温调控'
  176. logger.critical('============所有末端开启时间太短,不进行水温调控============')
  177. return water_temp_set_new
  178. def water_temp_main_process(self):
  179. """
  180. 水温计算的主函数
  181. :return:
  182. """
  183. parameter = (self.dict_chiller_inner, self.data_temp_humi)
  184. if self.dict_code['controlMode'] == 0: # 智控关闭
  185. # 实际上不用做任何计算或动作,这里只是需要考虑 如果在节能评估期的初始工况日,确保冷机水温保持在设定值或以下即可(后续随产品迭代)
  186. # spso = SetPointStrategyOff(*parameter) # 智控关闭场景下,恢复模式下的水温
  187. # self.water_temp_set_new = spso.self_control_strategy_off() # 智控关闭下的水温设定,这里是恢复模式下的设定值
  188. logger.critical('============智控开关为关闭,不进行水温计算============')
  189. elif self.dict_code['controlMode'] == 1: # 智控开启
  190. logger.critical('============智控开关为开启,开始进行水温计算============')
  191. if self.dict_chiller_inner['runStatus'][-1] == 0: # 当前冷机状态为关机
  192. jfss = JudgeFrequentlyStartStop(self.dict_code, self.dict_chiller_inner)
  193. judge_freq_start_stop = jfss.is_freq_start_stop() # 判断是正常停机还是频繁启停
  194. if judge_freq_start_stop == 0: # 非频繁启停,则是停机下水温设定
  195. logger.critical('============设备处于停机状态,水温正常调控============')
  196. spsoco = SetPointStrategyOnChillerOff(*parameter) # 停机下水温设定值
  197. self.water_temp_set_new = spsoco.water_temp_set_confirm() # 判断停机时长是否超过16小时
  198. else:
  199. logger.critical('============设备处于频繁启停状态,水温正常调控============')
  200. self.water_temp_set_new = self.water_temp_set_cal() # 运行冷机的水温计算
  201. self.terminal_cal = True
  202. elif self.dict_chiller_inner['runStatus'][-1] == 1: # 当前冷机状态为运行
  203. logger.critical('============设备处于运行状态,水温正常调控============')
  204. self.water_temp_set_new = self.water_temp_set_cal() # 运行冷机的水温计算
  205. self.terminal_cal = True
  206. else:
  207. self.water_temp_set_new = None
  208. self.results_depict = '冷机运行状态输入错误'
  209. logger.critical('============冷机运行状态输入错误============')
  210. else:
  211. self.water_temp_set_new = None
  212. self.results_depict = '算法智控状态输入错误'
  213. logger.critical('============算法智控状态输入错误============')
  214. # if self.water_temp_set_new:
  215. # # 水温设定值校验
  216. # self.water_temp_set_new = round(self.water_temp_set_new, 1)
  217. # self.water_temp_set_verify(self.terminal_cal)
  218. # # 判断是否要调节水温
  219. # self.is_adjust_judge()
  220. return self.water_temp_set_new