supply_air_temperature_set.py 2.4 KB

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