Browse Source

fix a bug

highing666 2 years ago
parent
commit
7121e27270

+ 19 - 40
app/controllers/equipment/ahu/supply_air_temperature_set.py

@@ -5,10 +5,7 @@ import numpy as np
 from httpx import AsyncClient
 from loguru import logger
 
-from app.controllers.equipment.ahu.thermal_mode import (
-    count_vav_box_weight,
-    fetch_status_params,
-)
+from app.controllers.equipment.ahu.thermal_mode import count_vav_box_weight, fetch_status_params
 from app.models.domain.devices import ThermalMode, ACATAHSupplyAirTempSetRequest
 from app.schemas.equipment import VAVBox
 from app.services.platform import DataPlatformService, InfoCode
@@ -23,14 +20,14 @@ class ACATAHSupplyAirTemperatureController:
     """
 
     def __init__(
-        self,
-        vav_boxes_list: List[VAVBox],
-        current_set: float,
-        return_air: float,
-        thermal_mode: ThermalMode,
-        is_off_to_on: bool,
-        is_thermal_mode_switched: bool,
-        season: Season,
+            self,
+            vav_boxes_list: List[VAVBox],
+            current_set: float,
+            return_air: float,
+            thermal_mode: ThermalMode,
+            is_off_to_on: bool,
+            is_thermal_mode_switched: bool,
+            season: Season,
     ):
         super(ACATAHSupplyAirTemperatureController, self).__init__()
         self.vav_boxes_list = vav_boxes_list
@@ -83,7 +80,7 @@ class ACATAHSupplyAirTemperatureController:
                 box.supply_air_flow_lower_limit,
                 box.supply_air_flow_set,
                 box.valve_opening,
-                self.season,
+                box.supply_air_temperature
             )
             cold += temp if temp < 0 else 0
             total += abs(temp)
@@ -100,10 +97,7 @@ class ACATAHSupplyAirTemperatureController:
     def get_normal_ratio(self):
         normal = 0
         for box in self.vav_boxes_list:
-            if (
-                abs(box.virtual_realtime_temperature - box.virtual_target_temperature)
-                <= 1
-            ):
+            if abs(box.virtual_realtime_temperature - box.virtual_target_temperature) <= 1:
                 normal += 1
 
         try:
@@ -172,12 +166,8 @@ async def get_planned(project_id: str, device_id: str) -> float:
         platform = DataPlatformService(client, project_id)
         duoduo = Duoduo(client, project_id)
 
-        current_supply_air_temperature = (
-            await platform.get_realtime_supply_air_temperature(device_id)
-        )
-        return_air_temperature = await platform.query_realtime_return_air_temperature(
-            device_id
-        )
+        current_supply_air_temperature = await platform.get_realtime_supply_air_temperature(device_id)
+        return_air_temperature = await platform.query_realtime_return_air_temperature(device_id)
 
         hot_water_valve_opening_set_duration = await platform.get_duration(
             InfoCode.hot_water_valve_opening_set, device_id, 15 * 60
@@ -185,14 +175,10 @@ async def get_planned(project_id: str, device_id: str) -> float:
         chill_water_valve_opening_set_duration = await platform.get_duration(
             InfoCode.chill_water_valve_opening_set, device_id, 15 * 60
         )
-        on_off_set_duration = await platform.get_duration(
-            InfoCode.equip_switch_set, device_id, 20 * 60
-        )
+        on_off_set_duration = await platform.get_duration(InfoCode.equip_switch_set, device_id, 20 * 60)
 
         season = await duoduo.get_season()
 
-        # if hot_water_valve_opening_set_duration[-1]['value'] == 0.0:
-        #     thermal_mode = ThermalMode.cooling
         if chill_water_valve_opening_set_duration[-1]["value"] == 0.0:
             thermal_mode = ThermalMode.heating
         else:
@@ -204,18 +190,11 @@ async def get_planned(project_id: str, device_id: str) -> float:
                 if item["value"] == 0.0:
                     is_off_to_on = True
                     break
-        # logger.debug(f'{device_id} was off to on: {is_off_to_on}')
 
         is_thermal_mode_switched = False
-        if (
-            len(set([item["value"] for item in hot_water_valve_opening_set_duration]))
-            > 1
-        ):
+        if len(set([item["value"] for item in hot_water_valve_opening_set_duration])) > 1:
             is_thermal_mode_switched = True
-        if (
-            len(set([item["value"] for item in chill_water_valve_opening_set_duration]))
-            > 1
-        ):
+        if len(set([item["value"] for item in chill_water_valve_opening_set_duration])) > 1:
             is_thermal_mode_switched = True
 
     controller = ACATAHSupplyAirTemperatureController(
@@ -248,7 +227,7 @@ async def get_default(project_id: str) -> float:
     return next_supply_air_temperature_set
 
 
-@logger.catch()
+@logger.catch
 async def get_next_supply_air_temperature_set(project_id: str, device_id: str) -> float:
     try:
         new = await get_planned(project_id, device_id)
@@ -260,9 +239,9 @@ async def get_next_supply_air_temperature_set(project_id: str, device_id: str) -
     return new
 
 
-@logger.catch()
+@logger.catch
 def build_acatah_supply_air_temperature_set(
-    params: ACATAHSupplyAirTempSetRequest,
+        params: ACATAHSupplyAirTempSetRequest,
 ) -> float:
     try:
         vav_list = list()

+ 14 - 14
app/controllers/equipment/ahu/thermal_mode.py

@@ -3,36 +3,36 @@ from typing import Dict, List
 from httpx import AsyncClient
 from loguru import logger
 
-from app.models.domain.devices import ThermalMode
 from app.models.domain.devices import ACATAHThermalModeSetRequest
+from app.models.domain.devices import ThermalMode
 from app.schemas.equipment import VAVBox
 from app.services.platform import DataPlatformService, InfoCode
 from app.services.transfer import Duoduo, Season
 
 
 def count_vav_box_weight(
-    realtime: float,
-    target: float,
-    upper_limit_flow: float,
-    lower_limit_flow: float,
-    current_flow_set: float,
-    valve_opening: float,
-    season: Season,
+        realtime: float,
+        target: float,
+        upper_limit_flow: float,
+        lower_limit_flow: float,
+        current_flow_set: float,
+        valve_opening: float,
+        supply_air_temp: float,
 ) -> float:
     diff = realtime - target
     flag = False
-    if current_flow_set < lower_limit_flow * 1.1:
-        if season == Season.cooling:
+    if current_flow_set < lower_limit_flow * 1.1 or valve_opening < 10.0:
+        if supply_air_temp < realtime:
             if diff < 0:
                 flag = True
-        if season == Season.heating:
+        if supply_air_temp > realtime:
             if diff > 0:
                 flag = True
     elif current_flow_set > upper_limit_flow * 0.9 or valve_opening > 90.0:
-        if season == Season.cooling:
+        if supply_air_temp > realtime:
             if diff > 0:
                 flag = True
-        if season == Season.heating:
+        if supply_air_temp < realtime:
             if diff < 0:
                 flag = True
 
@@ -70,7 +70,7 @@ class ACATAHThermalModeController:
                 box.supply_air_flow_lower_limit,
                 box.supply_air_flow_set,
                 box.valve_opening,
-                self.season,
+                box.supply_air_temperature
             )
 
         if weight > 0: