devices.py 4.4 KB

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