Browse Source

add ACATFC instructions router

highing666 3 years ago
parent
commit
cd6b96b643
3 changed files with 38 additions and 3 deletions
  1. 4 1
      app/api/routers/devices.py
  2. 28 0
      app/controllers/equipment/fcu/basic.py
  3. 6 2
      app/models/domain/devices.py

+ 4 - 1
app/api/routers/devices.py

@@ -5,6 +5,7 @@ import app.models.domain.devices as domain_devices
 from app.api.dependencies.db import get_db
 from app.controllers.equipment.ahu.supply_air_temperature_set import get_next_supply_air_temperature_set
 from app.controllers.equipment.ahu.thermal_mode import get_thermal_mode
+from app.controllers.equipment.fcu.basic import build_acatfc_instructions
 from app.controllers.equipment.fcu.early_start import get_recommended_early_start_time
 from app.controllers.equipment.fcu.on_ratio import start_on_ratio_mode
 from app.controllers.equipment.pau.freq_set import get_next_acatfu_freq_set
@@ -134,7 +135,9 @@ async def get_acatvi_instructions(device_info: domain_devices.ACATVIInstructions
 
 @router.post('/instructions/acatfc', response_model=domain_devices.ACATFCInstructionsResponse)
 async def get_acatfc_instructions(params: domain_devices.ACATFCInstructionsRequest):
-    pass
+    instructions = await build_acatfc_instructions(params)
+
+    return instructions
 
 
 @router.post('/instructions/acatva', response_model=domain_devices.ACATVAInstructionsResponse)

+ 28 - 0
app/controllers/equipment/fcu/basic.py

@@ -7,6 +7,7 @@ from httpx import AsyncClient
 from loguru import logger
 
 from app.controllers.equipment.controller import EquipmentController
+from app.models.domain.devices import ACATFCInstructionsRequest
 from app.schemas.equipment import AirValveSpeed, FCU
 from app.schemas.space import Space
 from app.services.platform import DataPlatformService, InfoCode
@@ -216,3 +217,30 @@ async def get_fcu_control_result(project_id: str, equipment_id: str) -> Dict:
     }
 
     return output
+
+
+@logger.catch()
+async def build_acatfc_instructions(params: ACATFCInstructionsRequest) -> Dict:
+    space = Space(
+        temperature_target=params.space_temperature_target,
+        realtime_temperature=params.space_realtime_temperature
+    )
+    fcu = FCU(
+        space=space,
+        supply_air_temperature=params.supply_air_temperature,
+        water_in_temperature=params.water_in_temperature
+    )
+
+    controller = FCUControllerV2(fcu, Season(params.season))
+    await controller.run()
+    regulated_fcu = controller.get_results()
+
+    instructions = {
+        'switch_set': 1 if regulated_fcu.running_status else 0,
+        'speed_set': regulated_fcu.air_valve_speed.value,
+        'temperature_set': float(round_half_up(regulated_fcu.setting_temperature, 1)),
+        'mode_set': regulated_fcu.work_mode,
+        'water_valve_switch_set': 1 if regulated_fcu.running_status else 0
+    }
+
+    return instructions

+ 6 - 2
app/models/domain/devices.py

@@ -40,7 +40,11 @@ class ACATVIInstructionsResponse(BaseModel):
 
 
 class ACATFCInstructionsRequest(BaseModel):
-    pass
+    season: str
+    supply_air_temperature: Optional[float]
+    water_in_temperature: Optional[float]
+    space_temperature_target: float
+    space_realtime_temperature: Optional[float]
 
 
 class ACATFCInstructionsResponse(BaseModel):
@@ -56,7 +60,7 @@ class Space(BaseModel):
     temperature_target: float
     vav_default_weight: float
     vav_temporary_weight: float
-    vav_temporary_update_time: float
+    vav_temporary_update_time: str
 
 
 class ACATVAInstructionsRequest(BaseModel):