devices.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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(supply_air_temperature_set)
  49. resp = {"supply_air_temperature_set": supply_air_temperature_set}
  50. return resp
  51. @router.post(
  52. "/instructions/acatah/freq-set", response_model=domain_devices.ACATAHFreqSetResponse
  53. )
  54. async def get_acatah_freq_set(params: domain_devices.ACATAHFreqSetRequest):
  55. freq_set = await build_acatah_freq_set(params)
  56. logger.info(params)
  57. logger.info(f"{params.device_id}: freq set - {freq_set}")
  58. resp = {"freq_set": freq_set}
  59. return resp
  60. @router.post(
  61. "/instructions/acatah/switch-set",
  62. response_model=domain_devices.ACATAHSwitchSetResponse,
  63. )
  64. async def get_acatah_switch_set(params: domain_devices.ACATAHSwitchSetRequest):
  65. switch_set = await build_acatah_switch_set(params)
  66. logger.info(params)
  67. logger.info(f"{params.device_id}: switch set - {switch_set}")
  68. resp = {"switch_set": switch_set}
  69. return resp
  70. @router.post(
  71. "/instructions/acvtsf/switch-set",
  72. response_model=domain_devices.ACVTSFSwitchSetResponse,
  73. )
  74. async def get_acvtsf_switch_set(params: domain_devices.ACVTSFSwitchSetRequest):
  75. switch_set = await build_acvtsf_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/acatfu/switch-set",
  82. response_model=domain_devices.ACATFUSwitchSetResponse,
  83. )
  84. async def get_acatfu_switch_set(params: domain_devices.ACATFUSwitchSetRequest):
  85. switch_set = await build_acatfu_switch_set(params)
  86. logger.info(params)
  87. logger.info(f"{params.device_id}: switch set - {switch_set}")
  88. resp = {"switch_set": switch_set}
  89. return resp
  90. @router.post(
  91. "/instructions/acatfu/supply-air-temperature-set",
  92. response_model=domain_devices.ACATFUSupplyAirTempSetResponse,
  93. )
  94. async def get_acatfu_supply_air_temperature_set_v2(
  95. params: domain_devices.ACATFUSupplyAirTempSetRequest,
  96. ):
  97. supply_air_temperature_set = build_acatfu_supply_air_temperature(params)
  98. logger.info(supply_air_temperature_set)
  99. resp = {"supply_air_temperature_set": supply_air_temperature_set}
  100. return resp
  101. @router.post(
  102. "/instructions/acatfu/freq-set", response_model=domain_devices.ACATFUFreqSetResponse
  103. )
  104. async def get_acatfu_freq_set(params: domain_devices.ACATFUFreqSetRequest):
  105. freq_set = await build_acatfu_freq_set(params)
  106. logger.info(f"{params.device_id} - {freq_set}")
  107. resp = {"freq_set": freq_set}
  108. return resp
  109. @router.post(
  110. "/prediction/acatfc/early-start",
  111. response_model=domain_devices.ACATFCEarlyStartPredictionResponse,
  112. )
  113. async def get_acatfc_early_start_prediction(
  114. params: domain_devices.ACATFCEarlyStartPredictionRequest,
  115. db: Session = Depends(get_db),
  116. ):
  117. minutes = await build_acatfc_early_start_prediction(params, db)
  118. logger.info(params)
  119. logger.info(f"{params.space_id} - {minutes}")
  120. resp = {"minutes": minutes}
  121. return resp
  122. @router.post(
  123. "/instructions/acatvi", response_model=domain_devices.ACATVIInstructionsResponse
  124. )
  125. async def get_acatvi_instructions(
  126. params: domain_devices.ACATVIInstructionsRequest, db: Session = Depends(get_db)
  127. ):
  128. instructions = await build_acatvi_instructions(params, db)
  129. logger.info(params)
  130. logger.info(f"{params.device_id} - {instructions}")
  131. return instructions
  132. @router.post(
  133. "/instructions/acatfc", response_model=domain_devices.ACATFCInstructionsResponse
  134. )
  135. async def get_acatfc_instructions(params: domain_devices.ACATFCInstructionsRequest):
  136. instructions = await build_acatfc_instructions(params)
  137. logger.info(params)
  138. logger.info(f"{params.device_id} - {instructions}")
  139. response = domain_devices.ACATFCInstructionsResponse(
  140. onOff=instructions.switch_set,
  141. speed=instructions.speed_set,
  142. temperature=instructions.temperature_set,
  143. mode=instructions.mode_set,
  144. water=instructions.water_valve_switch_set,
  145. )
  146. return response
  147. @router.post(
  148. "/instructions/acatva", response_model=domain_devices.ACATVAInstructionsResponse
  149. )
  150. async def get_acatva_instructions(params: domain_devices.ACATVAInstructionsRequest):
  151. instructions = await build_acatva_instructions(params)
  152. logger.info(params)
  153. logger.info(f"{params.device_id} - {instructions}")
  154. resp = dict()
  155. if not np.isnan(instructions.supply_air_flow_set):
  156. resp.update({"SupplyAirFlowSet": instructions.supply_air_flow_set})
  157. if not np.isnan(instructions.virtual_realtime_temperature):
  158. resp.update(
  159. {"VirtualRealtimeTemperature": instructions.virtual_realtime_temperature}
  160. )
  161. if not np.isnan(instructions.virtual_temperature_target_set):
  162. resp.update(
  163. {"TargetTemperatureSet": instructions.virtual_temperature_target_set}
  164. )
  165. return resp
  166. @router.post(
  167. "/instructions/acatva/v2",
  168. response_model=domain_devices.ACATVAInstructionsResponseV2,
  169. )
  170. async def get_acatva_instructions_v2(
  171. params: domain_devices.ACATVAInstructionsRequestV2,
  172. ):
  173. temp_set = await build_acatva_instructions_for_JM(params)
  174. return temp_set