devices.py 9.1 KB

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