devices.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. from fastapi import APIRouter, BackgroundTasks, Depends, Query
  2. from sqlalchemy.orm import Session
  3. import app.models.domain.devices as domain_devices
  4. from app.api.dependencies.db import get_db
  5. from app.controllers.equipment.ahu.supply_air_temperature_set import get_next_supply_air_temperature_set
  6. from app.controllers.equipment.ahu.thermal_mode import get_thermal_mode
  7. from app.controllers.equipment.fcu.basic import build_acatfc_instructions
  8. from app.controllers.equipment.fcu.early_start import get_recommended_early_start_time
  9. from app.controllers.equipment.fcu.on_ratio import start_on_ratio_mode
  10. from app.controllers.equipment.pau.freq_set import get_next_acatfu_freq_set
  11. from app.controllers.equipment.pau.supply_air_temperature_set import get_next_acatfu_supply_air_temperature_set
  12. from app.controllers.equipment.pau.switch import get_switch_action
  13. from app.controllers.equipment.vav import build_acatva_instructions
  14. from app.controllers.equipment.vrf.basic import build_acatvi_instructions
  15. from app.models.domain.devices import DevicesInstructionsBaseResponse, DevicesEarlyStartTime
  16. router = APIRouter()
  17. @router.get('/instructions/acatah/thermal-mode-set', response_model=DevicesInstructionsBaseResponse)
  18. async def get_acatah_thermal_mode_set(
  19. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  20. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  21. ):
  22. thermal_mode = await get_thermal_mode(project_id, device_id)
  23. return {
  24. 'projectId': project_id,
  25. 'equipId': device_id,
  26. 'output': {
  27. 'thermalModeSet': thermal_mode
  28. }
  29. }
  30. @router.get('/instructions/acatah/supply-air-temperature-set', response_model=DevicesInstructionsBaseResponse)
  31. async def get_acatah_supply_air_temperature_set(
  32. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  33. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  34. ):
  35. next_supply_air_temperature_set = await get_next_supply_air_temperature_set(project_id, device_id)
  36. return {
  37. 'projectId': project_id,
  38. 'equipId': device_id,
  39. 'output': {
  40. 'supplyAirTemperatureSet': next_supply_air_temperature_set
  41. }
  42. }
  43. @router.post('/on-ratio-experiment/fcu/{fcu_id}/target/{target}/period/{period}')
  44. async def run_on_ratio_experiment(fcu_id: str, target: float, period: int, background_tasks: BackgroundTasks):
  45. background_tasks.add_task(start_on_ratio_mode, fcu_id, target, period)
  46. return {
  47. 'fcu': fcu_id,
  48. 'target': target,
  49. 'period': period
  50. }
  51. @router.get('/instructions/acatfu/equip-switch-set', response_model=DevicesInstructionsBaseResponse)
  52. async def get_acatfu_equip_switch_set(
  53. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  54. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  55. ):
  56. action = await get_switch_action(project_id, device_id)
  57. return {
  58. 'projectId': project_id,
  59. 'equipId': device_id,
  60. 'output': {
  61. 'equipSwitchSet': action
  62. }
  63. }
  64. @router.get('/instructions/acatfu/supply-air-temperature-set', response_model=DevicesInstructionsBaseResponse)
  65. async def get_acatfu_supply_air_temperature_set(
  66. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  67. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  68. ):
  69. temperature_set = await get_next_acatfu_supply_air_temperature_set(project_id, device_id)
  70. return {
  71. 'projectId': project_id,
  72. 'equipId': device_id,
  73. 'output': {
  74. 'supplyAirTemperatureSet': temperature_set
  75. }
  76. }
  77. @router.get('/instructions/acatfu/freq-set', response_model=DevicesInstructionsBaseResponse)
  78. async def get_acatfu_freq_set(
  79. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  80. device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
  81. ):
  82. freq_set = await get_next_acatfu_freq_set(project_id, device_id)
  83. return {
  84. 'projectId': project_id,
  85. 'equipId': device_id,
  86. 'output': {
  87. 'fanFreqSet': freq_set
  88. }
  89. }
  90. @router.get('/early-start/prediction/acatfc', response_model=DevicesEarlyStartTime)
  91. async def get_acatfc_early_start_time(
  92. project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
  93. space_id: str = Query(..., max_length=50, regex='^Sp', alias='spaceId'),
  94. db: Session = Depends(get_db)
  95. ):
  96. minutes = await get_recommended_early_start_time(db, project_id, space_id)
  97. return {
  98. 'projectId': project_id,
  99. 'spaceId': space_id,
  100. 'minutes': minutes
  101. }
  102. @router.post('/instructions/acatvi', response_model=domain_devices.ACATVIInstructionsTemporaryResponse)
  103. async def get_acatvi_instructions(params: domain_devices.ACATVIInstructionsRequest):
  104. instructions = await build_acatvi_instructions(params)
  105. return {
  106. 'output': instructions
  107. }
  108. @router.post('/instructions/acatfc', response_model=domain_devices.ACATFCInstructionsResponse)
  109. async def get_acatfc_instructions(params: domain_devices.ACATFCInstructionsRequest):
  110. instructions = await build_acatfc_instructions(params)
  111. return instructions
  112. @router.post('/instructions/acatva', response_model=domain_devices.ACATVAInstructionsResponse)
  113. async def get_acatva_instructions(params: domain_devices.ACATVAInstructionsRequest):
  114. instructions = await build_acatva_instructions(params)
  115. return instructions