Переглянути джерело

complete supply air temperature set logic for ACATFU

chenhaiyang 4 роки тому
батько
коміт
74e7c7eedc

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

@@ -4,6 +4,7 @@ from app.controllers.equipment.ahu.supply_air_temperature_set import get_next_su
 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.controllers.equipment.pau.supply_air_temperature_set import get_next_acatfu_supply_air_temperature_set
 from app.models.domain.devices import DevicesInstructionsBaseResponse
 
 
@@ -73,4 +74,12 @@ 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
+    temperature_set = await get_next_acatfu_supply_air_temperature_set(project_id, device_id)
+
+    return {
+        'projectId': project_id,
+        'equipId': device_id,
+        'output': {
+            'supplyAirTemperatureSet': temperature_set
+        }
+    }

+ 47 - 3
app/controllers/equipment/pau/supply_air_temperature_set.py

@@ -4,6 +4,9 @@ import arrow
 from httpx import AsyncClient
 from loguru import logger
 
+from app.services.platform import DataPlatformService, InfoCode
+from app.services.transfer import Duoduo
+
 
 class ACATFUSupplyAirTemperatureController:
     """
@@ -15,7 +18,12 @@ class ACATFUSupplyAirTemperatureController:
         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:
+    def get_next_set(self, is_just_booted: bool) -> float:
+        try:
+            cold_hot_ratio = self.cold_space_count / self.hot_space_count
+        except ZeroDivisionError:
+            cold_hot_ratio = 99
+
         if is_just_booted:
             if cold_hot_ratio < 0.5:
                 next_temperature_set = 8.0
@@ -25,7 +33,9 @@ class ACATFUSupplyAirTemperatureController:
                 next_temperature_set = 14.0
             elif cold_hot_ratio < 1.5:
                 next_temperature_set = 17.0
-            else:
+            elif cold_hot_ratio >= 1.5:
+                next_temperature_set = 20.0
+            else:  # If cold hot ratio is nan.
                 next_temperature_set = 20.0
         else:
             if cold_hot_ratio < 0.5:
@@ -36,8 +46,42 @@ class ACATFUSupplyAirTemperatureController:
                 diff = 0
             elif cold_hot_ratio < 1.5:
                 diff = 2
-            else:
+            elif cold_hot_ratio >= 1.5:
                 diff = 3
+            else:  # If cold hot ratio is nan.
+                diff = 0
             next_temperature_set = self.current_air_temp + diff
 
         return next_temperature_set
+
+
+async def fetch_params(project_id: str, device_id: str):
+    async with AsyncClient() as client:
+        platform = DataPlatformService(client, project_id)
+        duoduo = Duoduo(client, project_id)
+
+        current_supply_air_temperature = await platform.get_realtime_supply_air_temperature(device_id)
+        running_status_duration = await platform.get_duration(InfoCode.running_status, device_id, 15 * 60)
+        count = await duoduo.get_fill_count()
+
+        is_just_booted = False
+        if running_status_duration[-1]['value'] == 1.0:
+            for item in running_status_duration[::-1]:
+                if item['value'] == 0.0:
+                    is_just_booted = True
+                    break
+
+    return current_supply_air_temperature, count.get('coldNum'), count.get('hotNum'), is_just_booted
+
+
+@logger.catch()
+async def get_next_acatfu_supply_air_temperature_set(project_id: str, device_id: str) -> float:
+    current_supply_air_temperature, cold_count, hot_count, is_just_booted = await fetch_params(project_id, device_id)
+    controller = ACATFUSupplyAirTemperatureController(
+        current_supply_air_temperature,
+        cold_count,
+        hot_count
+    )
+    next_temperature_set = controller.get_next_set(is_just_booted)
+
+    return next_temperature_set