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