devices.py 4.4 KB

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