devices.py 11 KB

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