Browse Source

add new ATFU logic for zhejiang

highing666 2 years ago
parent
commit
9e2a5896b3
3 changed files with 68 additions and 10 deletions
  1. 13 1
      app/api/routers/devices.py
  2. 47 1
      app/controllers/equipment/pau/switch.py
  3. 8 8
      pyproject.toml

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

@@ -25,7 +25,7 @@ from app.controllers.equipment.pau.freq_set import build_acatfu_freq_set
 from app.controllers.equipment.pau.supply_air_temperature_set import (
     build_acatfu_supply_air_temperature,
 )
-from app.controllers.equipment.pau.switch import build_acatfu_switch_set
+from app.controllers.equipment.pau.switch import build_acatfu_switch_set, build_co2_acatfu_switch
 from app.controllers.equipment.vav import (
     build_acatva_instructions,
     build_acatva_instructions_for_JM,
@@ -141,6 +141,18 @@ async def get_acatfu_switch_set(params: domain_devices.ACATFUSwitchSetRequest):
     return resp
 
 
+@router.post("/instructions/acatfu/switch-set/co2", response_model=domain_devices.ACATFUSwitchSetResponse)
+async def get_acatfu_co2_switch(params: domain_devices.ACATFUCO2SwitchSetRequest):
+    switch_set = await build_co2_acatfu_switch(params)
+
+    logger.info(params)
+    logger.info(f"{params.device_id}: switch set - {switch_set}")
+
+    resp = {"switch_set": switch_set}
+
+    return resp
+
+
 @router.post(
     "/instructions/acatfu/supply-air-temperature-set",
     response_model=domain_devices.ACATFUSupplyAirTempSetResponse,

+ 47 - 1
app/controllers/equipment/pau/switch.py

@@ -1,9 +1,12 @@
 # -*- coding: utf-8 -*-
 
+from typing import List
+
+import numpy as np
 from loguru import logger
 
 from app.controllers.equipment.switch import Switch, SwitchSet
-from app.models.domain.devices import ACATFUSwitchSetRequest
+from app.models.domain.devices import ACATFUSwitchSetRequest, ACATFUCO2SwitchSetRequest
 from app.schemas.equipment import PAU
 
 
@@ -37,6 +40,40 @@ class PAUSwitch(Switch):
         return action
 
 
+class PAUSwitchWithCO2(PAUSwitch):
+    def __int__(self, equipment: PAU):
+        super(PAUSwitchWithCO2, self).__int__(equipment)
+
+    @staticmethod
+    def co2_logic(co2_list: List[float]) -> SwitchSet:
+        co2_list = np.array(co2_list)
+        action = SwitchSet.hold
+        if co2_list.size > 0:
+            if co2_list.mean() >= 800.0 or co2_list.max() > 1000.0:
+                action = SwitchSet.on
+            if co2_list.mean() <= 650.0 and co2_list.max() < 1000.0:
+                action = SwitchSet.off
+
+        return action
+
+    async def run(self, is_workday: bool, break_start_time: str, break_end_time: str,
+                  co2_list: List[float]) -> SwitchSet:
+        action = await self.build_next_action(is_workday)
+        break_action = self.break_time_action(break_start_time, break_end_time, is_workday)
+        if break_action == SwitchSet.off:
+            action = SwitchSet.off
+        co2_action = self.co2_logic(co2_list)
+        if co2_action == SwitchSet.off:
+            action = SwitchSet.off
+        elif co2_action == SwitchSet.on:
+            if action == SwitchSet.off:
+                action = SwitchSet.off
+            if action == SwitchSet.hold and not self._equip:
+                action = SwitchSet.hold
+
+        return action
+
+
 @logger.catch()
 async def build_acatfu_switch_set(params: ACATFUSwitchSetRequest) -> SwitchSet:
     pau = PAU(
@@ -54,3 +91,12 @@ async def build_acatfu_switch_set(params: ACATFUSwitchSetRequest) -> SwitchSet:
         action = SwitchSet.off
 
     return action
+
+
+@logger.catch
+async def build_co2_acatfu_switch(params: ACATFUCO2SwitchSetRequest) -> SwitchSet:
+    pau = PAU(**params.dict())
+    controller = PAUSwitchWithCO2(pau)
+    action = await controller.run(params.is_workday, params.break_start_time, params.break_end_time, params.co2_list)
+
+    return action

+ 8 - 8
pyproject.toml

@@ -1,27 +1,27 @@
 [tool.poetry]
 name = "saga_algo_api"
-version = "0.4.0"
+version = "0.4.5"
 description = "SagaCare Algorithm Web Server"
 authors = ["highing666 <bigseabigdream@gmail.com>"]
 license = "Apache-2.0"
 
 [tool.poetry.dependencies]
 python = "^3.9"
-Cython = "^0.29.28"
+Cython = "^0.29.29"
 pandas = "1.4.2"
 grpcio = "1.37.1"
-fastapi = "^0.75.1"
+fastapi = "^0.78.0"
 python-dotenv = "^0.20.0"
 uvicorn = "^0.17.6"
 psycopg2-binary = "^2.9.3"
-SQLAlchemy = "^1.4.34"
-redis = "^4.2.0"
+SQLAlchemy = "^1.4.36"
+redis = "^4.3.1"
 arrow = "^1.2.2"
-loguru = "^0.5.3"
+loguru = "^0.6.0"
 httpx = "^0.22.0"
-scikit-learn = "^0.24.2"
+scikit-learn = "^1.1.0"
 
-tencentcloud-sdk-python = "^3.0.612"
+tencentcloud-sdk-python = "^3.0.635"
 pymilvus = "^2.0.2"
 
 [tool.poetry.dev-dependencies]