소스 검색

amend the logic of the first period

chenhaiyang 4 년 전
부모
커밋
29eb3aa8b6
1개의 변경된 파일19개의 추가작업 그리고 7개의 파일을 삭제
  1. 19 7
      app/controllers/equipment/fcu/on_ratio.py

+ 19 - 7
app/controllers/equipment/fcu/on_ratio.py

@@ -59,19 +59,27 @@ class OnRatioController:
 
         return switch
 
-    def calculate_on_ratio(self, delta_on: float, delta_off: float) -> float:
+    def calculate_on_ratio(self, delta_on: float, delta_off: float, last_mode: str) -> float:
         if self.period_num == 0:
-            ratio = 0.9
+            if last_mode == 'normal':
+                ratio = 0.9
+            elif last_mode == 'off':
+                ratio = 0.1
+            else:
+                if self.return_air > self.target - 0.5:
+                    ratio = 0.1
+                else:
+                    ratio = 0.9
         else:
             if delta_on <= 0:
-                ratio = 1.0
+                ratio = 0.9
             else:
                 try:
                     ratio = (0.5 * (self.return_air - self.target) + delta_off) / (delta_off - delta_on)
-                    if ratio > 1:
-                        ratio = 1.0
+                    if ratio > 0.9:
+                        ratio = 0.9
                 except ZeroDivisionError:
-                    ratio = 0.0
+                    ratio = 0.1
 
         return ratio
 
@@ -127,6 +135,7 @@ async def start_on_ratio_mode(device_id: str, target: float, period_time: int):
 
     period_num = 0
     last_on_ratio = 1.0
+    last_mode = 'default'
     life_count = 0
     while life_count < 2000:
         try:
@@ -140,7 +149,7 @@ async def start_on_ratio_mode(device_id: str, target: float, period_time: int):
                 water_valve = controller.select_water_valve()
 
                 if mode == 'on_ratio':
-                    on_ratio = controller.calculate_on_ratio(delta_on, delta_off)
+                    on_ratio = controller.calculate_on_ratio(delta_on, delta_off, last_mode)
                     on_range = round_half_up(period_time * on_ratio)
                     off_range = period_time - on_range
                     logger.debug(f'life count: {life_count}, {device_id}, on time: {on_range}, off time: {off_range}, '
@@ -160,6 +169,7 @@ async def start_on_ratio_mode(device_id: str, target: float, period_time: int):
 
                     period_num += 1
                     last_on_ratio = on_ratio
+                    last_mode = mode
                 else:
                     await send_instructions(device_id, switch, speed, water_valve)
                     logger.debug(f'{device_id}, {switch}, {speed}, {water_valve}')
@@ -167,6 +177,7 @@ async def start_on_ratio_mode(device_id: str, target: float, period_time: int):
 
                     period_num = 0
                     last_on_ratio = 1.0
+                    last_mode = mode
 
                 life_count += 1
 
@@ -175,6 +186,7 @@ async def start_on_ratio_mode(device_id: str, target: float, period_time: int):
                 await send_instructions(device_id, False, 'off', False)
                 period_num = 0
                 last_on_ratio = 0.0
+                last_mode = 'off'
                 await asyncio.sleep(period_time)
         except (KeyError, IndexError, TypeError, HTTPException):
             await asyncio.sleep(period_time)