control_period_step_adjust.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import pandas as pd
  2. # from logs_conf.logger import *
  3. from logs.logger import *
  4. class ControlPeriodStepAdjust(object):
  5. def __init__(self, dict_input):
  6. self.dict_input = dict_input
  7. self.data_upper_correct = pd.DataFrame()
  8. self.dict_code = {}
  9. self.dict_chiller_inner = {}
  10. # def step_adjust(self):
  11. # """
  12. # 根据历史安全压差对步长进行调整
  13. # """
  14. # preDiffMin = self.data_upper_correct['preDiff'].min()
  15. # if preDiffMin < 50:
  16. # if self.dict_chiller_inner['waterTempControlMode'] == 0:
  17. # if self.water_temp_set_new > (self.dict_chiller_inner['chillerWaterTempSet'] + 0.3):
  18. # self.water_temp_set_new = self.dict_chiller_inner['chillerWaterTempSet'] + 0.3
  19. # elif self.dict_chiller_inner['waterTempControlMode'] == 1:
  20. # if self.water_temp_set_new > (self.dict_chiller_inner['chillerWaterTempInSet'] + 0.3):
  21. # self.water_temp_set_new = self.dict_chiller_inner['chillerWaterTempInSet'] + 0.3
  22. # else:
  23. # self.water_temp_set_new = ''
  24. # # logger.critical('==============冷机控制选择输入错误==============')
  25. # return None
  26. # def control_period_adjust(self):
  27. # """
  28. # 根据采样周期进行调整
  29. # 采样周期不可低于80秒,否则会出现负值
  30. # :return:
  31. # """
  32. # tempLimit = 0.00125 * self.dict_code['controlPeriodNew'] - 0.1
  33. # if self.dict_chiller_inner['runMode'] == 0:
  34. # if self.dict_chiller_inner['waterTempControlMode'] == 0:
  35. # if self.water_temp_set_new > (self.dict_chiller_inner['chillerWaterTempSet'] + tempLimit):
  36. # self.water_temp_set_new = self.dict_chiller_inner['chillerWaterTempSet'] + tempLimit
  37. # elif self.dict_chiller_inner['waterTempControlMode'] == 1:
  38. # if self.water_temp_set_new > (self.dict_chiller_inner['chillerWaterTempInSet'] + tempLimit):
  39. # self.water_temp_set_new = self.dict_chiller_inner['chillerWaterTempInSet'] + tempLimit
  40. # else:
  41. # self.water_temp_set_new = ''
  42. # # logger.critical('==============冷机控制选择输入错误==============')
  43. # else:
  44. # if self.dict_chiller_inner['waterTempControlMode'] == 0:
  45. # if self.water_temp_set_new < (self.dict_chiller_inner['heatingWaterTempSet'] - tempLimit):
  46. # self.water_temp_set_new = self.dict_chiller_inner['heatingWaterTempSet'] - tempLimit
  47. # elif self.dict_chiller_inner['waterTempControlMode'] == 1:
  48. # if self.water_temp_set_new < (self.dict_chiller_inner['heatingWaterTempInSet'] - tempLimit):
  49. # self.water_temp_set_new = self.dict_chiller_inner['heatingWaterTempInSet'] - tempLimit
  50. # else:
  51. # self.water_temp_set_new = ''
  52. # # logger.critical('==============冷机控制选择输入错误==============')
  53. # return None
  54. def control_time_diff_cal(self):
  55. """
  56. 分别计算升温控制时间差和降温控制时间差
  57. :return:
  58. """
  59. self.dict_chiller_inner['triggerTime'] = pd.to_datetime(self.dict_chiller_inner['triggerTime'])
  60. # self.dict_code['controlTimeLatest'] = pd.to_datetime(self.dict_code['controlTimeLatest'])
  61. # self.dict_code['controlTimeDiff'] = (
  62. # self.dict_chiller_inner['triggerTime'] - self.dict_code['controlTimeLatest']).total_seconds()
  63. # 升温控制时间差
  64. self.dict_code['upControlTimeLatest'] = pd.to_datetime(self.dict_code['upControlTimeLatest'])
  65. self.dict_code['upControlTimeDiff'] = (
  66. self.dict_chiller_inner['triggerTime'] - self.dict_code['upControlTimeLatest']).total_seconds()
  67. # 降温控制时间差
  68. self.dict_code['downControlTimeLatest'] = pd.to_datetime(self.dict_code['downControlTimeLatest'])
  69. self.dict_code['downControlTimeDiff'] = (
  70. self.dict_chiller_inner['triggerTime'] - self.dict_code['downControlTimeLatest']).total_seconds()
  71. # self.dict_code['controlPeriodNew'] = self.dict_code['controlTimeDiff'] # 这里的赋值待确认 #######
  72. return self.dict_code
  73. def pointwise_temp_diff_cal(self):
  74. """
  75. 逐点温差的计算,当前只考虑了出水温度数量为1的场景,若出水温度数量大于1则需要分情况计算,待迭代
  76. :return:
  77. """
  78. temp_diff_list = []
  79. if self.dict_chiller_inner['runMode'] == 0:
  80. for i in range(1, len(self.dict_chiller_inner['chillerWaterTempOut'])):
  81. temp_diff = self.dict_chiller_inner['chillerWaterTempOut'][i] - \
  82. self.dict_chiller_inner['chillerWaterTempOut'][i - 1]
  83. temp_diff_list.append(temp_diff)
  84. elif self.dict_chiller_inner['runMode'] == 1:
  85. for i in range(1, len(self.dict_chiller_inner['coolingWaterTempOut'])):
  86. temp_diff = self.dict_chiller_inner['coolingWaterTempOut'][i] - \
  87. self.dict_chiller_inner['coolingWaterTempOut'][i - 1]
  88. temp_diff_list.append(temp_diff)
  89. else:
  90. logger.critical('============冷机运行模式输入错误============')
  91. return temp_diff_list
  92. def control_period_cal(self, is_safety_issue):
  93. """
  94. 计算控制周期是否满足调控周期,满足则控制,不满足则再进一步判断安全因素
  95. 判断安全因素时需要计算逐点温差
  96. :param is_safety_issue: 是否存在安全运行问题,三个安全校验的最终结果
  97. :return:
  98. """
  99. self.control_time_diff_cal()
  100. if self.dict_code['upControlTimeDiff'] > self.dict_code['upTempControlPeriod'] * 60 or \
  101. self.dict_code['downControlTimeDiff'] > self.dict_code['downTempControlPeriod'] * 60:
  102. is_control = 1
  103. # self.dict_code['controlPeriodNew'] = self.dict_code['controlPeriod'] # 这里的赋值待确认 #######
  104. logger.critical('============正常控制1:控制时间差已满足条件,设备正常控制============')
  105. else:
  106. if is_safety_issue:
  107. temp_diff_list = self.pointwise_temp_diff_cal()
  108. if temp_diff_list:
  109. if max(temp_diff_list) < 0.2 or (self.dict_code['upControlTimeDiff'] > 180 and
  110. self.dict_code['downControlTimeDiff'] > 180): # 这里的逻辑待确认 #######
  111. is_control = 1
  112. logger.critical('============正常控制2:存在安全运行风险,设备正常控制============')
  113. else:
  114. is_control = 0
  115. logger.critical('============不控制:控制时间差不满足条件,设备不控制============')
  116. else:
  117. is_control = 1
  118. else:
  119. is_control = 0
  120. logger.critical('============不控制:控制时间差不满足条件,且不存在安全运行风险,设备不控制============')
  121. return is_control