Browse Source

modify ATFU control logic

highing666 3 years ago
parent
commit
35cd1cd927

+ 2 - 3
app/controllers/equipment/pau/freq_set.py

@@ -64,10 +64,8 @@ class ACATFUFanFreqControllerV2:
     def get_next_set(self, spaces_params: List[SpaceATFU], on_flag: bool) -> float:
         if self._season == Season.transition:
             next_freq_set = self.get_transition_logic(spaces_params, on_flag)
-        elif self._season == Season.cooling:
-            next_freq_set = self.get_cooling_logic(spaces_params, on_flag)
         else:
-            next_freq_set = self.get_heating_logic(spaces_params, on_flag)
+            next_freq_set = self.get_cooling_logic(spaces_params, on_flag)
 
         next_freq_set = max(20.0, next_freq_set)
         next_freq_set = min(50.0, next_freq_set)
@@ -168,6 +166,7 @@ class ACATFUFanFreqControllerV2:
         return freq_set
 
     def get_heating_logic(self, spaces_params: List[SpaceATFU], on_flag: bool) -> float:
+        # The same with cooling logic.
 
         return self._freq
 

+ 21 - 60
app/controllers/equipment/pau/supply_air_temperature_set.py

@@ -4,8 +4,7 @@ from httpx import AsyncClient
 from loguru import logger
 
 from app.models.domain.devices import ACATFUSupplyAirTempSetRequest
-from app.services.platform import DataPlatformService, InfoCode
-from app.services.transfer import Duoduo
+from app.schemas.season import Season
 
 
 class ACATFUSupplyAirTemperatureController:
@@ -14,11 +13,16 @@ class ACATFUSupplyAirTemperatureController:
     """
 
     def __init__(
-        self, current_supply_air_temp: float, hot_rate: float, cold_rate: float
+        self,
+        current_supply_air_temp_set: float,
+        hot_rate: float,
+        cold_rate: float,
+        season: Season,
     ):
-        self.current_air_temp = current_supply_air_temp
+        self.current_air_temp_set = current_supply_air_temp_set
         self.hot_rate = hot_rate
         self.cold_rate = cold_rate
+        self.season = season
 
     def get_next_set(self, is_just_booted: bool) -> float:
         try:
@@ -27,18 +31,12 @@ class ACATFUSupplyAirTemperatureController:
             cold_hot_ratio = 99
 
         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
-            elif cold_hot_ratio >= 1.5:
-                next_temperature_set = 20.0
-            else:  # If cold hot ratio is nan.
+            if self.season == Season.cooling:
                 next_temperature_set = 20.0
+            elif self.season == Season.heating:
+                next_temperature_set = 16.0
+            else:
+                next_temperature_set = self.current_air_temp_set
         else:
             if cold_hot_ratio < 0.5:
                 diff = -3
@@ -52,56 +50,16 @@ class ACATFUSupplyAirTemperatureController:
                 diff = 3
             else:  # If cold hot ratio is nan.
                 diff = 0
-            next_temperature_set = self.current_air_temp + diff
+
+            if self.season == Season.cooling or self.season == Season.transition:
+                diff = 0
+            next_temperature_set = self.current_air_temp_set + diff
 
         next_temperature_set = max(8.0, min(20.0, next_temperature_set))
 
         return next_temperature_set
 
 
-async def fetch_params(
-    project_id: str, device_id: str
-) -> Tuple[float, float, float, bool]:
-    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
-        )
-        hot_rate, cold_rate = await duoduo.query_fill_rate_by_device(device_id)
-
-        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, hot_rate, cold_rate, 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,
-        hot_rate,
-        cold_rate,
-        is_just_booted,
-    ) = await fetch_params(project_id, device_id)
-    controller = ACATFUSupplyAirTemperatureController(
-        current_supply_air_temperature, hot_rate, cold_rate
-    )
-    next_temperature_set = controller.get_next_set(is_just_booted)
-
-    return next_temperature_set
-
-
 @logger.catch()
 def build_acatfu_supply_air_temperature(params: ACATFUSupplyAirTempSetRequest) -> float:
     is_just_booted = False
@@ -112,7 +70,10 @@ def build_acatfu_supply_air_temperature(params: ACATFUSupplyAirTempSetRequest) -
                 break
 
     controller = ACATFUSupplyAirTemperatureController(
-        params.supply_air_temperature, params.hot_ratio, params.cold_ratio
+        params.supply_air_temperature_set,
+        params.hot_ratio,
+        params.cold_ratio,
+        params.season,
     )
     supply_air_temperature_set = controller.get_next_set(is_just_booted)
 

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

@@ -217,7 +217,8 @@ class ACATAHSupplyAirTempSetResponse(BaseModel):
 
 class ACATFUSupplyAirTempSetRequest(BaseModel):
     device_id: str
-    supply_air_temperature: float
+    season: Season
+    supply_air_temperature_set: float
     hot_ratio: float
     cold_ratio: float
     running_status_list: List[float]