supply_air_temperature_set.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. from app.api.errors.iot import MissingIOTDataError
  2. from app.models.domain.devices import ACATFUSupplyAirTempSetRequest
  3. from app.schemas.season import Season
  4. class ACATFUSupplyAirTemperatureController:
  5. """
  6. Supply air temperature setting logic version 1 by Wenyan.
  7. """
  8. def __init__(
  9. self,
  10. current_supply_air_temp_set: float,
  11. hot_rate: float,
  12. cold_rate: float,
  13. season: Season,
  14. ):
  15. self.current_air_temp_set = current_supply_air_temp_set
  16. self.hot_rate = hot_rate
  17. self.cold_rate = cold_rate
  18. self.season = season
  19. def get_next_set(self, is_just_booted: bool) -> float:
  20. try:
  21. cold_hot_ratio = self.cold_rate / self.hot_rate
  22. except (ZeroDivisionError, TypeError):
  23. cold_hot_ratio = 99
  24. if is_just_booted:
  25. if self.season == Season.cooling:
  26. next_temperature_set = 20.0
  27. elif self.season == Season.heating:
  28. next_temperature_set = 16.0
  29. else:
  30. next_temperature_set = self.current_air_temp_set
  31. else:
  32. if cold_hot_ratio < 0.5:
  33. diff = -3
  34. elif cold_hot_ratio < 0.9:
  35. diff = -2
  36. elif cold_hot_ratio < 1.1:
  37. diff = 0
  38. elif cold_hot_ratio < 1.5:
  39. diff = 2
  40. elif cold_hot_ratio >= 1.5:
  41. diff = 3
  42. else: # If cold hot ratio is nan.
  43. diff = 0
  44. if self.season == Season.cooling or self.season == Season.transition:
  45. diff = 0
  46. try:
  47. next_temperature_set = self.current_air_temp_set + diff
  48. except TypeError:
  49. raise MissingIOTDataError
  50. next_temperature_set = max(8.0, min(20.0, next_temperature_set))
  51. return next_temperature_set
  52. def build_acatfu_supply_air_temperature(params: ACATFUSupplyAirTempSetRequest) -> float:
  53. is_just_booted = False
  54. if len(params.running_status_list) > 0:
  55. if params.running_status_list[-1] == 1.0:
  56. for item in params.running_status_list[::-1]:
  57. if item == 0.0:
  58. is_just_booted = True
  59. break
  60. controller = ACATFUSupplyAirTemperatureController(
  61. params.supply_air_temperature_set,
  62. params.hot_ratio,
  63. params.cold_ratio,
  64. params.season,
  65. )
  66. supply_air_temperature_set = controller.get_next_set(is_just_booted)
  67. return supply_air_temperature_set