devices.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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, build_co2_acatfu_switch
  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("/instructions/acatfu/switch-set/co2", response_model=domain_devices.ACATFUSwitchSetResponse)
  108. async def get_acatfu_co2_switch(params: domain_devices.ACATFUCO2SwitchSetRequest):
  109. switch_set = await build_co2_acatfu_switch(params)
  110. logger.info(params)
  111. logger.info(f"{params.device_id}: switch set - {switch_set}")
  112. resp = {"switch_set": switch_set}
  113. return resp
  114. @router.post(
  115. "/instructions/acatfu/supply-air-temperature-set",
  116. response_model=domain_devices.ACATFUSupplyAirTempSetResponse,
  117. )
  118. async def get_acatfu_supply_air_temperature_set_v2(
  119. params: domain_devices.ACATFUSupplyAirTempSetRequest,
  120. ):
  121. supply_air_temperature_set = build_acatfu_supply_air_temperature(params)
  122. logger.info(supply_air_temperature_set)
  123. resp = {"supply_air_temperature_set": supply_air_temperature_set}
  124. return resp
  125. @router.post(
  126. "/instructions/acatfu/freq-set", response_model=domain_devices.ACATFUFreqSetResponse
  127. )
  128. async def get_acatfu_freq_set(params: domain_devices.ACATFUFreqSetRequest):
  129. freq_set = await build_acatfu_freq_set(params)
  130. logger.info(f"{params.device_id} - {freq_set}")
  131. resp = {"freq_set": freq_set}
  132. return resp
  133. @router.post(
  134. "/prediction/acatfc/early-start",
  135. response_model=domain_devices.ACATFCEarlyStartPredictionResponse,
  136. )
  137. async def get_acatfc_early_start_prediction(
  138. params: domain_devices.ACATFCEarlyStartPredictionRequest,
  139. db: Session = Depends(get_db),
  140. ):
  141. minutes = await build_acatfc_early_start_prediction(params, db)
  142. logger.info(params)
  143. logger.info(f"{params.space_id} - {minutes}")
  144. resp = {"minutes": minutes}
  145. return resp
  146. @router.post(
  147. "/instructions/acatvi", response_model=domain_devices.ACATVIInstructionsResponse
  148. )
  149. async def get_acatvi_instructions(params: domain_devices.ACATVIInstructionsRequest):
  150. instructions = await build_acatvi_instructions(params)
  151. logger.info(params)
  152. logger.info(f"{params.device_id} - {instructions}")
  153. return instructions
  154. @router.post(
  155. "/instructions/acatvi/mode", response_model=domain_devices.ACATVIModeResponse
  156. )
  157. async def get_acatvi_mode(params: domain_devices.ACATVIModeRequest):
  158. new_mode = await build_acatvi_mode(params)
  159. logger.info(params)
  160. logger.info(
  161. f"floor space temperature list: {params.space_temperature_list}"
  162. f"- new mode: {new_mode}"
  163. )
  164. return {"mode": new_mode}
  165. @router.post(
  166. "/instructions/acatfc", response_model=domain_devices.ACATFCInstructionsResponse
  167. )
  168. async def get_acatfc_instructions(params: domain_devices.ACATFC2InstructionsRequest):
  169. instructions = await build_acatfc2_instructions(params)
  170. logger.info(params)
  171. logger.info(f"{params.device_id} - {instructions}")
  172. response = domain_devices.ACATFCInstructionsResponse(
  173. onOff=instructions.switch_set,
  174. speed=instructions.speed_set,
  175. temperature=instructions.temperature_set,
  176. mode=instructions.mode_set,
  177. water=instructions.water_valve_switch_set,
  178. )
  179. return response
  180. @router.post(
  181. "/instructions/acatfc4", response_model=domain_devices.ACATFCInstructionsResponse
  182. )
  183. async def get_acatfc4_instructions(params: domain_devices.ACATFC4InstructionsRequest):
  184. instructions = await build_acatfc4_instructions(params)
  185. logger.info(params)
  186. logger.info(f"{params.device_id} - {instructions}")
  187. response = domain_devices.ACATFCInstructionsResponse(
  188. onOff=instructions.switch_set,
  189. speed=instructions.speed_set,
  190. temperature=instructions.temperature_set,
  191. mode=instructions.mode_set,
  192. water=instructions.water_valve_switch_set,
  193. )
  194. return response
  195. @router.post(
  196. "/instructions/acatfc2/v2",
  197. response_model=domain_devices.ACATFC2InstructionsResponse,
  198. )
  199. async def get_acatfc2_instruction_v2(params: domain_devices.ACATFC2InstructionsRequest):
  200. instructions = await build_acatfc2_instructions_v2(params)
  201. logger.info(params)
  202. logger.info(f"{params.device_id} - {instructions}")
  203. return instructions
  204. @router.post(
  205. "/instructions/acatfc4/v2",
  206. response_model=domain_devices.ACATFC4InstructionsResponse,
  207. )
  208. async def get_acatfc4_instructions_v2(params: domain_devices.ACATFC4InstructionsRequest):
  209. instructions = await build_acatfc4_instructions_v2(params)
  210. logger.info(params)
  211. logger.info(f"{params.device_id} - {instructions}")
  212. return instructions
  213. @router.post(
  214. "/instructions/acatva", response_model=domain_devices.ACATVAInstructionsResponse
  215. )
  216. async def get_acatva_instructions(params: domain_devices.ACATVAInstructionsRequest):
  217. instructions = await build_acatva_instructions(params)
  218. logger.info(params)
  219. logger.info(f"{params.device_id} - {instructions}")
  220. resp = dict()
  221. if not np.isnan(instructions.supply_air_flow_set):
  222. resp.update({"SupplyAirFlowSet": instructions.supply_air_flow_set})
  223. if not np.isnan(instructions.virtual_realtime_temperature):
  224. resp.update(
  225. {"VirtualRealtimeTemperature": instructions.virtual_realtime_temperature}
  226. )
  227. if not np.isnan(instructions.virtual_temperature_target_set):
  228. resp.update(
  229. {"TargetTemperatureSet": instructions.virtual_temperature_target_set}
  230. )
  231. return resp
  232. @router.post(
  233. "/instructions/acatva/v2",
  234. response_model=domain_devices.ACATVAInstructionsResponseV2,
  235. )
  236. async def get_acatva_instructions_v2(
  237. params: domain_devices.ACATVAInstructionsRequestV2,
  238. ):
  239. instructions = await build_acatva_instructions_for_jm(params)
  240. logger.info(params)
  241. logger.info(f"{params.device_id} - {instructions}")
  242. return instructions
  243. @router.post("/instructions/ashp", response_model=domain_devices.ASHPResponse)
  244. async def get_ashp_instructions(params: domain_devices.ASHPRequest):
  245. pass