devices.py 9.5 KB

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