Selaa lähdekoodia

add thermal mode and supply air temperature set logic of ahu

chenhaiyang 4 vuotta sitten
vanhempi
commit
f3f2acbf33

+ 52 - 2
app/controllers/equipment/ahu/supply_air_temperature_set.py

@@ -1,13 +1,63 @@
-from typing import Optional
+from typing import List, Optional
 
 from httpx import AsyncClient
 from loguru import logger
 
+from app.controllers.equipment.ahu.water_valve_opening import count_vav_box_weight
+from app.models.domain.devices import ThermalMode
+from app.schemas.equipment import VAVBox
+
 
 class ACATAHSupplyAirTemperatureController:
     """
     Supply air temperature setting logic version 2 by WuXu.
     """
 
-    def __init__(self):
+    def __init__(self, vav_boxes_list: List[VAVBox], current: float, return_air: float, thermal_mode: ThermalMode):
         super(ACATAHSupplyAirTemperatureController, self).__init__()
+        self.vav_boxes_list = vav_boxes_list
+        self.current = current
+        self.return_air = return_air
+        self.thermal_mode = thermal_mode
+
+    def calculate_by_cold_vav(self, cold_ratio: float) -> float:
+        if self.thermal_mode == ThermalMode.cooling:
+            if cold_ratio < 0.3:
+                new = self.current - 1.0
+            elif cold_ratio < 0.45:
+                new = self.current - 0.5
+            elif cold_ratio <= 0.55:
+                new = self.current
+            elif cold_ratio <= 0.7:
+                new = self.current + 1.0
+            elif cold_ratio <= 1.0:
+                new = self.return_air
+            else:
+                new = self.current
+        elif self.thermal_mode == ThermalMode.heating:
+            if cold_ratio < 0.3:
+                new = self.return_air
+            elif cold_ratio < 0.45:
+                new = self.current - 1
+            elif cold_ratio <= 0.55:
+                new = self.current
+            elif cold_ratio <= 0.7:
+                new = self.current + 0.5
+            elif cold_ratio <= 1.0:
+                new = self.current + 1
+            else:
+                new = self.current
+        else:
+            new = self.current
+
+        return new
+
+    def get_cold_ratio(self):
+        cold, total = 0, 0
+        for box in self.vav_boxes_list:
+            temp = count_vav_box_weight(box.virtual_realtime_temperature, box.virtual_target_temperature)
+            cold += temp if temp < 0 else 0
+            total += abs(temp)
+
+        return abs(cold / total)
+

+ 17 - 18
app/controllers/equipment/ahu/water_valve_opening.py

@@ -7,6 +7,22 @@ from app.schemas.equipment import VAVBox
 from app.services.platform import DataPlatformService, InfoCode
 
 
+def count_vav_box_weight(realtime: float, target: float) -> float:
+    diff = abs(realtime - target)
+    if diff > 3:
+        weight = 4
+    elif diff > 2:
+        weight = 3
+    elif diff > 1:
+        weight = 2
+    elif diff > 0:
+        weight = 1
+    else:
+        weight = 0
+
+    return weight * (realtime - target)
+
+
 class ACATAHThermalModeController:
     """
     Decide whether to use cooling or heating mode according to space condition controlled by VAV Box.
@@ -17,26 +33,10 @@ class ACATAHThermalModeController:
         super(ACATAHThermalModeController, self).__init__()
         self.vav_boxes_list = vav_boxes_list
 
-    @staticmethod
-    def count_box_weight(realtime: float, target: float) -> float:
-        diff = abs(realtime - target)
-        if diff > 3:
-            weight = 4
-        elif diff > 2:
-            weight = 3
-        elif diff > 1:
-            weight = 2
-        elif diff > 0:
-            weight = 1
-        else:
-            weight = 0
-
-        return weight * (realtime - target)
-
     def build(self) -> str:
         weight = 0.0
         for box in self.vav_boxes_list:
-            weight += self.count_box_weight(box.virtual_realtime_temperature, box.virtual_target_temperature)
+            weight += count_vav_box_weight(box.virtual_realtime_temperature, box.virtual_target_temperature)
 
         if weight > 0:
             mode = 'cooling'
@@ -46,4 +46,3 @@ class ACATAHThermalModeController:
             mode = 'hold'
 
         return mode
-

+ 2 - 1
app/main.py

@@ -7,7 +7,7 @@ import uvicorn
 from fastapi import FastAPI
 from loguru import logger
 
-from app.api.routers import targets, equipment, space, item, user, bluetooth
+from app.api.routers import targets, equipment, space, item, user, bluetooth, devices
 from app.core.config import settings
 from app.core.events import create_start_app_handler
 from app.core.logger import InterceptHandler
@@ -30,6 +30,7 @@ def get_application() -> FastAPI:
     application.include_router(item.router, prefix='/items', tags=['items'])
     application.include_router(user.router, prefix='/users', tags=['users'])
     application.include_router(bluetooth.router, prefix='/bluetooth', tags=['bluetooth'])
+    application.include_router(devices.router, prefix='/devices', tags=['devices'])
 
     return application