devices.py 7.8 KB

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