devices.py 8.6 KB

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