Browse Source

update supply air temperature of ATFU

highing666 4 years ago
parent
commit
85ea1a0265

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

@@ -80,6 +80,6 @@ async def get_acatfu_supply_air_temperature_set(
         'projectId': project_id,
         'equipId': device_id,
         'output': {
-            # 'supplyAirTemperatureSet': temperature_set
+            'supplyAirTemperatureSet': temperature_set
         }
     }

+ 15 - 10
app/controllers/equipment/pau/supply_air_temperature_set.py

@@ -1,3 +1,5 @@
+from typing import Tuple
+
 from httpx import AsyncClient
 from loguru import logger
 
@@ -10,14 +12,14 @@ 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):
+    def __init__(self, current_supply_air_temp: float, hot_rate: float, cold_rate: float):
         self.current_air_temp = current_supply_air_temp
-        self.cold_space_count = cold_space_count
-        self.hot_space_count = hot_space_count
+        self.hot_rate = hot_rate
+        self.cold_rate = cold_rate
 
     def get_next_set(self, is_just_booted: bool) -> float:
         try:
-            cold_hot_ratio = self.cold_space_count / self.hot_space_count
+            cold_hot_ratio = self.cold_rate / self.hot_rate
         except ZeroDivisionError:
             cold_hot_ratio = 99
 
@@ -49,17 +51,19 @@ class ACATFUSupplyAirTemperatureController:
                 diff = 0
             next_temperature_set = self.current_air_temp + 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):
+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)
-        count = await duoduo.get_fill_count()
+        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:
@@ -68,17 +72,18 @@ async def fetch_params(project_id: str, device_id: str):
                     is_just_booted = True
                     break
 
-    return current_supply_air_temperature, count.get('coldNum'), count.get('hotNum'), is_just_booted
+    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, cold_count, hot_count, is_just_booted = await fetch_params(project_id, device_id)
+    current_supply_air_temperature, hot_rate, cold_rate, is_just_booted = await fetch_params(project_id, device_id)
     controller = ACATFUSupplyAirTemperatureController(
         current_supply_air_temperature,
-        cold_count,
-        hot_count
+        hot_rate,
+        cold_rate
     )
     next_temperature_set = controller.get_next_set(is_just_booted)
+    logger.debug(next_temperature_set)
 
     return next_temperature_set

+ 25 - 0
app/services/transfer.py

@@ -299,3 +299,28 @@ class Duoduo(Service):
             value = np.NAN
 
         return value
+
+    async def query_fill_rate_by_device(self, device_id: str) -> [float, float]:
+        url = self._base_url.join('duoduo-service/review-service/space/quarter/getQueryByCategory')
+        payload = {
+            'criteria': {
+                'projectId': self._project_id,
+                'date': arrow.get(self._now_time, TIME_FMT).date().strftime('%Y%m%d'),
+                'eqId': device_id
+            }
+        }
+
+        raw_info = await self._post(url, payload=payload)
+
+        try:
+            value_info = raw_info['content'][-1]
+            hot_count = value_info['hotSpaceNum']
+            cold_count = value_info['coldSpaceNum']
+            total = value_info['spaceNum']
+
+            hot_rate = hot_count / total
+            cold_rate = cold_count / total
+        except (KeyError, IndexError, ZeroDivisionError):
+            hot_rate, cold_rate = np.NAN, np.NAN
+
+        return hot_rate, cold_rate