devices.py 7.0 KB

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