devices.py 7.1 KB

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