devices.py 5.3 KB

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