devices.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import numpy as np
  2. from fastapi import APIRouter, Depends
  3. from loguru import logger
  4. from sqlalchemy.orm import Session
  5. import app.models.domain.devices as domain_devices
  6. from app.api.dependencies.db import get_db
  7. from app.controllers.equipment.ahu.basic import build_acatah_freq_set
  8. from app.controllers.equipment.ahu.supply_air_temperature_set import (
  9. build_acatah_supply_air_temperature_set,
  10. )
  11. from app.controllers.equipment.ahu.switch import build_acatah_switch_set
  12. from app.controllers.equipment.ahu.thermal_mode import build_acatah_thermal_mode_set
  13. from app.controllers.equipment.fcu.basic import build_acatfc_instructions
  14. from app.controllers.equipment.fcu.early_start import (
  15. build_acatfc_early_start_prediction,
  16. )
  17. from app.controllers.equipment.pau.freq_set import build_acatfu_freq_set
  18. from app.controllers.equipment.pau.supply_air_temperature_set import (
  19. build_acatfu_supply_air_temperature,
  20. )
  21. from app.controllers.equipment.pau.switch import build_acatfu_switch_set
  22. from app.controllers.equipment.vav import build_acatva_instructions
  23. from app.controllers.equipment.ventilation_fan.switch import build_acvtsf_switch_set
  24. from app.controllers.equipment.vrf.basic import build_acatvi_instructions
  25. router = APIRouter()
  26. @router.post(
  27. "/instructions/acatah/thermal-mode-set",
  28. response_model=domain_devices.ACATAHThermalModeSetResponse,
  29. )
  30. async def get_acatah_thermal_mode_set_v2(
  31. params: domain_devices.ACATAHThermalModeSetRequest,
  32. ):
  33. thermal_mode = build_acatah_thermal_mode_set(params)
  34. logger.info(f"{params.device_id}: thermal mode set - {thermal_mode}")
  35. resp = {"thermal_mode_set": thermal_mode}
  36. return resp
  37. @router.post(
  38. "/instructions/acatah/supply-air-temperature-set",
  39. response_model=domain_devices.ACATAHSupplyAirTempSetResponse,
  40. )
  41. async def get_acatah_supply_air_temperature_set_v2(
  42. params: domain_devices.ACATAHSupplyAirTempSetRequest,
  43. ):
  44. supply_air_temperature_set = build_acatah_supply_air_temperature_set(params)
  45. logger.info(supply_air_temperature_set)
  46. resp = {"supply_air_temperature_set": supply_air_temperature_set}
  47. return resp
  48. @router.post(
  49. "/instructions/acatah/freq-set", response_model=domain_devices.ACATAHFreqSetResponse
  50. )
  51. async def get_acatah_freq_set(params: domain_devices.ACATAHFreqSetRequest):
  52. freq_set = await build_acatah_freq_set(params)
  53. logger.info(params)
  54. logger.info(f"{params.device_id}: freq set - {freq_set}")
  55. resp = {"freq_set": freq_set}
  56. return resp
  57. @router.post(
  58. "/instructions/acatah/switch-set",
  59. response_model=domain_devices.ACATAHSwitchSetResponse,
  60. )
  61. async def get_acatah_switch_set(params: domain_devices.ACATAHSwitchSetRequest):
  62. switch_set = await build_acatah_switch_set(params)
  63. logger.info(params)
  64. logger.info(f"{params.device_id}: switch set - {switch_set}")
  65. resp = {"switch_set": switch_set}
  66. return resp
  67. @router.post(
  68. "/instructions/acvtsf/switch-set",
  69. response_model=domain_devices.ACVTSFSwitchSetResponse,
  70. )
  71. async def get_acvtsf_switch_set(params: domain_devices.ACVTSFSwitchSetRequest):
  72. switch_set = await build_acvtsf_switch_set(params)
  73. logger.info(params)
  74. logger.info(f"{params.device_id}: switch set - {switch_set}")
  75. resp = {"switch_set": switch_set}
  76. return resp
  77. @router.post(
  78. "/instructions/acatfu/switch-set",
  79. response_model=domain_devices.ACATFUSwitchSetResponse,
  80. )
  81. async def get_acatfu_switch_set(params: domain_devices.ACATFUSwitchSetRequest):
  82. switch_set = await build_acatfu_switch_set(params)
  83. logger.info(params)
  84. logger.info(f"{params.device_id}: switch set - {switch_set}")
  85. resp = {"switch_set": switch_set}
  86. return resp
  87. @router.post(
  88. "/instructions/acatfu/supply-air-temperature-set",
  89. response_model=domain_devices.ACATFUSupplyAirTempSetResponse,
  90. )
  91. async def get_acatfu_supply_air_temperature_set_v2(
  92. params: domain_devices.ACATFUSupplyAirTempSetRequest,
  93. ):
  94. supply_air_temperature_set = build_acatfu_supply_air_temperature(params)
  95. logger.info(supply_air_temperature_set)
  96. resp = {"supply_air_temperature_set": supply_air_temperature_set}
  97. return resp
  98. @router.post(
  99. "/instructions/acatfu/freq-set", response_model=domain_devices.ACATFUFreqSetResponse
  100. )
  101. async def get_acatfu_freq_set(params: domain_devices.ACATFUFreqSetRequest):
  102. freq_set = build_acatfu_freq_set(params)
  103. logger.info(f"{params.device_id} - {freq_set}")
  104. resp = {"freq_set": freq_set}
  105. return resp
  106. @router.post(
  107. "/prediction/acatfc/early-start",
  108. response_model=domain_devices.ACATFCEarlyStartPredictionResponse,
  109. )
  110. async def get_acatfc_early_start_prediction(
  111. params: domain_devices.ACATFCEarlyStartPredictionRequest,
  112. db: Session = Depends(get_db),
  113. ):
  114. minutes = await build_acatfc_early_start_prediction(params, db)
  115. logger.info(params)
  116. logger.info(f"{params.space_id} - {minutes}")
  117. resp = {"minutes": minutes}
  118. return resp
  119. @router.post(
  120. "/instructions/acatvi", response_model=domain_devices.ACATVIInstructionsResponse
  121. )
  122. async def get_acatvi_instructions(
  123. params: domain_devices.ACATVIInstructionsRequest, db: Session = Depends(get_db)
  124. ):
  125. instructions = await build_acatvi_instructions(params, db)
  126. logger.info(params)
  127. logger.info(f"{params.device_id} - {instructions}")
  128. return instructions
  129. @router.post(
  130. "/instructions/acatfc", response_model=domain_devices.ACATFCInstructionsResponse
  131. )
  132. async def get_acatfc_instructions(params: domain_devices.ACATFCInstructionsRequest):
  133. instructions = await build_acatfc_instructions(params)
  134. logger.info(params)
  135. logger.info(f"{params.device_id} - {instructions}")
  136. response = domain_devices.ACATFCInstructionsResponse(
  137. onOff=instructions.switch_set,
  138. speed=instructions.speed_set,
  139. temperature=instructions.temperature_set,
  140. mode=instructions.switch_set,
  141. water=instructions.water_valve_switch_set,
  142. )
  143. return response
  144. @router.post(
  145. "/instructions/acatva", response_model=domain_devices.ACATVAInstructionsResponse
  146. )
  147. async def get_acatva_instructions(params: domain_devices.ACATVAInstructionsRequest):
  148. instructions = await build_acatva_instructions(params)
  149. logger.info(params)
  150. logger.info(f"{params.device_id} - {instructions}")
  151. resp = dict()
  152. if not np.isnan(instructions.supply_air_flow_set):
  153. resp.update({"SupplyAirFlowSet": instructions.supply_air_flow_set})
  154. if not np.isnan(instructions.virtual_realtime_temperature):
  155. resp.update(
  156. {"VirtualRealtimeTemperature": instructions.virtual_realtime_temperature}
  157. )
  158. if not np.isnan(instructions.virtual_temperature_target_set):
  159. resp.update(
  160. {"TargetTemperatureSet": instructions.virtual_temperature_target_set}
  161. )
  162. return resp