Browse Source

add supply air temperature set logic for acatfu

chenhaiyang 4 years ago
parent
commit
acbbe7c6dd

+ 25 - 0
app/api/routers/devices.py

@@ -3,6 +3,7 @@ from fastapi import APIRouter, BackgroundTasks, Query
 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.on_ratio import start_on_ratio_mode
+from app.controllers.equipment.pau.switch import get_switch_action
 from app.models.domain.devices import DevicesInstructionsBaseResponse
 
 
@@ -49,3 +50,27 @@ async def run_on_ratio_experiment(fcu_id: str, target: float, period: int, backg
         'target': target,
         'period': period
     }
+
+
+@router.get('/instructions/acatfu/equip-switch-set', response_model=DevicesInstructionsBaseResponse)
+async def get_acatfu_equip_switch_set(
+        project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
+        device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
+):
+    action = await get_switch_action(project_id, device_id)
+
+    return {
+        'projectId': project_id,
+        'equipId': device_id,
+        'output': {
+            'equipSwitchSet': action
+        }
+    }
+
+
+@router.get('/instructions/acatfu/supply-ari-temperature-set', response_model=DevicesInstructionsBaseResponse)
+async def get_acatfu_supply_air_temperature_set(
+        project_id: str = Query(..., max_length=50, regex='^Pj', alias='projectId'),
+        device_id: str = Query(..., max_length=50, regex='^Eq', alias='equipId')
+):
+    pass

+ 43 - 0
app/controllers/equipment/pau/supply_air_temperature_set.py

@@ -0,0 +1,43 @@
+from typing import List
+
+import arrow
+from httpx import AsyncClient
+from loguru import logger
+
+
+class ACATFUSupplyAirTemperatureController:
+    """
+    Supply air temperature setting logic version 1 by Wenyan.
+    """
+
+    def __init__(self, current_supply_air_temp: float, cold_space_count: float, hot_space_count: float):
+        self.current_air_temp = current_supply_air_temp
+        self.cold_space_count = cold_space_count
+        self.hot_space_count = hot_space_count
+
+    def get_next_set(self, is_just_booted: bool, cold_hot_ratio: float) -> float:
+        if is_just_booted:
+            if cold_hot_ratio < 0.5:
+                next_temperature_set = 8.0
+            elif cold_hot_ratio < 0.9:
+                next_temperature_set = 11.0
+            elif cold_hot_ratio < 1.1:
+                next_temperature_set = 14.0
+            elif cold_hot_ratio < 1.5:
+                next_temperature_set = 17.0
+            else:
+                next_temperature_set = 20.0
+        else:
+            if cold_hot_ratio < 0.5:
+                diff = -3
+            elif cold_hot_ratio < 0.9:
+                diff = -2
+            elif cold_hot_ratio < 1.1:
+                diff = 0
+            elif cold_hot_ratio < 1.5:
+                diff = 2
+            else:
+                diff = 3
+            next_temperature_set = self.current_air_temp + diff
+
+        return next_temperature_set

+ 8 - 0
app/controllers/equipment/pau/switch.py

@@ -18,3 +18,11 @@ async def pau_switch_control(project_id: str, equipment_id: str) -> None:
     action = await PAUSwitch(PAU(**equip_params)).build_next_action(day_type.get('day_type'))
     logger.debug(f'PAU-{equipment_id}: {action}')
     await send_switch_command(project_id, equipment_id, action)
+
+
+@logger.catch()
+async def get_switch_action(project_id: str, device_id: str) -> str:
+    device_params, day_type = await fetch_data(project_id, device_id)
+    action = await PAUSwitch(PAU(**device_params)).build_next_action(day_type.get('day_type'))
+
+    return action