devices.py 10 KB

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