Преглед изворни кода

add VRF logic for Zhejiang

highing666 пре 2 година
родитељ
комит
2801da2d57
4 измењених фајлова са 95 додато и 7 уклоњено
  1. 18 1
      app/api/routers/devices.py
  2. 62 0
      app/controllers/equipment/vrf/mode.py
  3. 14 5
      app/models/domain/devices.py
  4. 1 1
      docker-compose.yml

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

@@ -31,6 +31,7 @@ from app.controllers.equipment.vav import (
 )
 from app.controllers.equipment.ventilation_fan.switch import build_acvtsf_switch_set
 from app.controllers.equipment.vrf.basic import build_acatvi_instructions
+from app.controllers.equipment.vrf.mode import build_acatvi_mode
 
 router = APIRouter()
 
@@ -190,6 +191,21 @@ async def get_acatvi_instructions(
 
 
 @router.post(
+    "/instructions/acatvi/mode", response_model=domain_devices.ACATVIModeResponse
+)
+async def get_acatvi_mode(params: domain_devices.ACATVIModeRequest):
+    new_mode = await build_acatvi_mode(params)
+
+    logger.info(params)
+    logger.info(
+        f"floor space temperature list: {params.space_temperature_list}"
+        f"- new mode: {new_mode}"
+    )
+
+    return {"mode": new_mode}
+
+
+@router.post(
     "/instructions/acatfc", response_model=domain_devices.ACATFCInstructionsResponse
 )
 async def get_acatfc_instructions(params: domain_devices.ACATFC2InstructionsRequest):
@@ -243,7 +259,8 @@ async def get_acatfc2_instruction_v2(params: domain_devices.ACATFC2InstructionsR
 
 
 @router.post(
-    "/instructions/acatfc4/v2", response_model=domain_devices.ACATFC4InstructionsResponse
+    "/instructions/acatfc4/v2",
+    response_model=domain_devices.ACATFC4InstructionsResponse,
 )
 async def get_acatfc4_instrutions_v2(params: domain_devices.ACATFC4InstructionsRequest):
     instructions = await build_acatfc4_instructions_v2(params)

+ 62 - 0
app/controllers/equipment/vrf/mode.py

@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+
+from loguru import logger
+
+
+from app.controllers.equipment.controller import EquipmentController
+from app.models.domain.devices import ACATVIModeRequest
+from app.schemas.season import Season
+
+
+class VRFModeController(EquipmentController):
+    def __init__(self, season: Season, space_temperature: list):
+        super().__init__()
+        self._season = season
+        self._space_temperature = space_temperature
+        self._new_mode = "hold"
+
+    def run(self) -> None:
+        if self._season == Season.cooling:
+            cold_space_count, hot_space_count = 0, 0
+            for item in self._space_temperature:
+                if item < 22.0:
+                    cold_space_count += 1
+                if item > 26.0:
+                    hot_space_count += 1
+            if (
+                cold_space_count / len(self._space_temperature) > 0.6
+                and hot_space_count < 1
+            ):
+                new_mode = "ventilation"
+            else:
+                new_mode = "cooling"
+        elif self._season == Season.transition:
+            new_mode = "ventilation"
+        else:
+            cold_space_count, hot_space_count = 0, 0
+            for item in self._space_temperature:
+                if item < 22.0:
+                    cold_space_count += 1
+                if item > 25.0:
+                    hot_space_count += 1
+            if (
+                hot_space_count / len(self._space_temperature) > 0.6
+                and cold_space_count < 1
+            ):
+                new_mode = "ventilation"
+            else:
+                new_mode = "heating"
+
+        self._new_mode = new_mode
+
+    def get_results(self) -> str:
+        return self._new_mode
+
+
+@logger.catch()
+async def build_acatvi_mode(params: ACATVIModeRequest) -> str:
+    controller = VRFModeController(params.season, params.space_temperature_list)
+    controller.run()
+    new_mode = controller.get_results()
+
+    return new_mode

+ 14 - 5
app/models/domain/devices.py

@@ -16,11 +16,11 @@ class ThermalMode(str, Enum):
 
 
 class Speed(str, Enum):
-    off = 'off'
-    low = 'low'
-    medium = 'medium'
-    high = 'high'
-    hold = 'hold'
+    off = "off"
+    low = "low"
+    medium = "medium"
+    high = "high"
+    hold = "hold"
 
 
 class DevicesInstructionsBaseResponse(BaseModel):
@@ -60,6 +60,15 @@ class ACATVIInstructionsResponse(BaseModel):
     # mode_set: Optional[str]
 
 
+class ACATVIModeRequest(BaseModel):
+    season: Season
+    space_temperature_list: List[float]
+
+
+class ACATVIModeResponse(BaseModel):
+    mode: str
+
+
 class ACATFCInstructionsRequestBase(BaseModel):
     device_id: str
     season: str

+ 1 - 1
docker-compose.yml

@@ -2,7 +2,7 @@ version: "3"
 
 services:
   app:
-      image: registry.persagy.com/sagacloud/saga_algo_api:0.3.38
+      image: registry.persagy.com/sagacloud/saga_algo_api:0.3.39
       container_name: saga_algo_api
       ports:
         - 8002:8002