devices.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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, build_acatvi_instructions_v2
  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/v2", response_model=domain_devices.ACATVIInstructionsResponse
  159. )
  160. async def get_acatvi_instructions_v2(params: domain_devices.ACATVIInstructionsRequest):
  161. instructions = await build_acatvi_instructions_v2(params)
  162. logger.info(params)
  163. logger.info(f"{params.device_id} - {instructions}")
  164. return instructions
  165. @router.post(
  166. "/instructions/acatvi/mode", response_model=domain_devices.ACATVIModeResponse
  167. )
  168. async def get_acatvi_mode(params: domain_devices.ACATVIModeRequest):
  169. new_mode = await build_acatvi_mode(params)
  170. logger.info(params)
  171. logger.info(
  172. f"floor space temperature list: {params.space_temperature_list}"
  173. f"- new mode: {new_mode}"
  174. )
  175. return {"mode": new_mode}
  176. @router.post(
  177. "/instructions/acatfc", response_model=domain_devices.ACATFCInstructionsResponse
  178. )
  179. async def get_acatfc_instructions(params: domain_devices.ACATFC2InstructionsRequest):
  180. instructions = await build_acatfc2_instructions(params)
  181. logger.info(params)
  182. logger.info(f"{params.device_id} - {instructions}")
  183. response = domain_devices.ACATFCInstructionsResponse(
  184. onOff=instructions.switch_set,
  185. speed=instructions.speed_set,
  186. temperature=instructions.temperature_set,
  187. mode=instructions.mode_set,
  188. water=instructions.water_valve_switch_set,
  189. )
  190. return response
  191. @router.post(
  192. "/instructions/acatfc4", response_model=domain_devices.ACATFCInstructionsResponse
  193. )
  194. async def get_acatfc4_instructions(params: domain_devices.ACATFC4InstructionsRequest):
  195. instructions = await build_acatfc4_instructions(params)
  196. logger.info(params)
  197. logger.info(f"{params.device_id} - {instructions}")
  198. response = domain_devices.ACATFCInstructionsResponse(
  199. onOff=instructions.switch_set,
  200. speed=instructions.speed_set,
  201. temperature=instructions.temperature_set,
  202. mode=instructions.mode_set,
  203. water=instructions.water_valve_switch_set,
  204. )
  205. return response
  206. @router.post(
  207. "/instructions/acatfc2/v2",
  208. response_model=domain_devices.ACATFC2InstructionsResponse,
  209. )
  210. async def get_acatfc2_instruction_v2(params: domain_devices.ACATFC2InstructionsRequest):
  211. instructions = await build_acatfc2_instructions_v2(params)
  212. logger.info(params)
  213. logger.info(f"{params.device_id} - {instructions}")
  214. return instructions
  215. @router.post(
  216. "/instructions/acatfc4/v2",
  217. response_model=domain_devices.ACATFC4InstructionsResponse,
  218. )
  219. async def get_acatfc4_instructions_v2(params: domain_devices.ACATFC4InstructionsRequest):
  220. instructions = await build_acatfc4_instructions_v2(params)
  221. logger.info(params)
  222. logger.info(f"{params.device_id} - {instructions}")
  223. return instructions
  224. @router.post(
  225. "/instructions/acatva", response_model=domain_devices.ACATVAInstructionsResponse
  226. )
  227. async def get_acatva_instructions(params: domain_devices.ACATVAInstructionsRequest):
  228. instructions = await build_acatva_instructions(params)
  229. logger.info(params)
  230. logger.info(f"{params.device_id} - {instructions}")
  231. resp = dict()
  232. if not np.isnan(instructions.supply_air_flow_set):
  233. resp.update({"SupplyAirFlowSet": instructions.supply_air_flow_set})
  234. if not np.isnan(instructions.virtual_realtime_temperature):
  235. resp.update(
  236. {"VirtualRealtimeTemperature": instructions.virtual_realtime_temperature}
  237. )
  238. if not np.isnan(instructions.virtual_temperature_target_set):
  239. resp.update(
  240. {"TargetTemperatureSet": instructions.virtual_temperature_target_set}
  241. )
  242. return resp
  243. @router.post(
  244. "/instructions/acatva/v2",
  245. response_model=domain_devices.ACATVAInstructionsResponseV2,
  246. )
  247. async def get_acatva_instructions_v2(
  248. params: domain_devices.ACATVAInstructionsRequestV2,
  249. ):
  250. instructions = await build_acatva_instructions_for_jm(params)
  251. logger.info(params)
  252. logger.info(f"{params.device_id} - {instructions}")
  253. return instructions
  254. @router.post("/instructions/ashp", response_model=domain_devices.ASHPResponse)
  255. async def get_ashp_instructions(params: domain_devices.ASHPRequest):
  256. instructions = await build_ashp_instructions(params)
  257. logger.info(params)
  258. logger.info(instructions)
  259. return instructions
  260. @router.post("/instructions/feed-water-pump", response_model=domain_devices.FeedWaterPumpResponse)
  261. async def get_feed_water_pump_instructions(params: domain_devices.FeedWaterPumpRequest):
  262. instructions = await build_feed_water_pump_instructions(params)
  263. logger.info(params)
  264. logger.info(instructions)
  265. return instructions
  266. @router.post("/instructions/feed-water-pump-BR", response_model=domain_devices.FeedWaterPumpResponse)
  267. async def get_feed_water_pump_instructions(params: domain_devices.FeedWaterPumpRequest):
  268. instructions = await build_feed_water_pump_br_instructions(params)
  269. logger.info(params)
  270. logger.info(instructions)
  271. return instructions