public_method.py 15 KB

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