basic.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # -*- coding: utf-8 -*-
  2. import numpy as np
  3. from app.api.errors.iot import MissingIOTDataError
  4. from app.models.domain.devices import ACATAHFreqSetRequest
  5. from app.schemas.equipment import AHU
  6. from app.schemas.system import ACAT
  7. class AHUController:
  8. def __init__(self, equipment: AHU | None, system: ACAT | None):
  9. super(AHUController, self).__init__()
  10. self._equipment = equipment
  11. self._system = system
  12. async def build_freq_set(self, supply_air_temperature_set_duration: list[float], hot_rate: float) -> float:
  13. extent = 5
  14. if (
  15. self._equipment.freq_set is None
  16. or self._system.supply_static_press is None
  17. or self._system.supply_static_press_set is None
  18. ):
  19. temp_freq_set = 80.0
  20. else:
  21. pre_fan_freq_set = self._equipment.freq_set
  22. if self._system.supply_static_press < self._system.supply_static_press_set - extent:
  23. temp_freq_set = pre_fan_freq_set + 2
  24. elif self._system.supply_static_press > self._system.supply_static_press_set + extent:
  25. temp_freq_set = pre_fan_freq_set - 2
  26. else:
  27. temp_freq_set = pre_fan_freq_set
  28. temperature_value_list = np.array(supply_air_temperature_set_duration)
  29. freq_upper_limit = 90.0
  30. try:
  31. if (
  32. temperature_value_list.size > 0
  33. and np.all(temperature_value_list == temperature_value_list[0])
  34. and temperature_value_list[0] <= 18.0
  35. and hot_rate >= 0.5
  36. ):
  37. freq_upper_limit = 100.0
  38. except TypeError:
  39. raise MissingIOTDataError
  40. freq_set = min(temp_freq_set, freq_upper_limit)
  41. self._equipment.freq_set = freq_set
  42. return freq_set
  43. async def build_acatah_freq_set(params: ACATAHFreqSetRequest) -> float:
  44. acat_system = ACAT(
  45. supply_static_press=params.system_supply_static_press,
  46. supply_static_press_set=params.system_supply_static_press_set,
  47. )
  48. ahu = AHU(freq_set=params.current_freq_set)
  49. ahu_controller = AHUController(ahu, acat_system)
  50. new_freq_set = await ahu_controller.build_freq_set(params.supply_air_temperature_set_list, params.spaces_hot_rate)
  51. return new_freq_set