浏览代码

add work mode logic for HongShan FCU

chenhaiyang 4 年之前
父节点
当前提交
36c2098366
共有 3 个文件被更改,包括 47 次插入18 次删除
  1. 1 9
      app/api/routers/equipment.py
  2. 30 6
      app/controllers/equipment/fcu/basic.py
  3. 16 3
      app/schemas/equipment.py

+ 1 - 9
app/api/routers/equipment.py

@@ -10,7 +10,6 @@ from app.controllers.equipment.fcu.q_learning import get_fcu_q_learning_control_
 from app.controllers.equipment.vav import get_vav_control_result
 from app.models.domain.equipment import EquipmentControlResponse, EquipmentControlRequest
 from app.utils.date import get_time_str
-from app.utils.math import round_half_up
 
 
 class EquipmentName(str, Enum):
@@ -59,14 +58,7 @@ async def get_equipment_command_test(
 async def get_equipment_command(equipment_control_info: EquipmentControlRequest):
     if equipment_control_info.equipType == EquipmentName.FCU:
         if equipment_control_info.projectId == 'Pj1101050030':
-            fcu = await get_fcu_control_result(equipment_control_info.projectId, equipment_control_info.equipId)
-            output = {
-                'EquipSwitchSet': 1 if fcu.running_status else 0,
-                'WorkModeSet': 3,
-                'IndoorAirTempSet': int(round_half_up(fcu.setting_temperature, 1) * 10)
-            }
-            if fcu.air_valve_speed.value != 0.0:
-                output.update({'FanGearSet': fcu.air_valve_speed.value})
+            output = await get_fcu_control_result(equipment_control_info.projectId, equipment_control_info.equipId)
         else:
             output = await get_fcu_q_learning_control_result(
                 equipment_control_info.projectId,

+ 30 - 6
app/controllers/equipment/fcu/basic.py

@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+from typing import Dict
+
 import numpy as np
 from httpx import AsyncClient
 from loguru import logger
@@ -8,14 +10,16 @@ from app.controllers.equipment.controller import EquipmentController
 from app.schemas.equipment import AirValveSpeed, FCU
 from app.schemas.space import Space
 from app.services.platform import DataPlatformService
-from app.services.transfer import SpaceInfoService, EquipmentInfoService
+from app.services.transfer import SpaceInfoService, Duoduo, Season
+from app.utils.math import round_half_up
 
 
 class FCUController(EquipmentController):
 
-    def __init__(self, equipment: FCU):
+    def __init__(self, equipment: FCU, season: Season):
         super(FCUController, self).__init__()
         self._equipment = equipment
+        self.season = season
 
     async def get_temperature_target(self) -> float:
         target = self._equipment.space.temperature_target
@@ -48,25 +52,36 @@ class FCUController(EquipmentController):
         else:
             self._equipment.running_status = True
 
+    async def get_mode(self) -> None:
+        if self.season == Season.heating:
+            mode = 2
+        elif self.season == Season.cooling:
+            mode = 1
+        else:
+            mode = 0
+        self._equipment.work_mode = mode
+
     async def run(self):
         await self.get_temperature_target()
         await self.get_air_valve_speed()
         await self.get_running_status()
+        await self.get_mode()
 
     def get_results(self):
         return self._equipment
 
 
 @logger.catch()
-async def get_fcu_control_result(project_id: str, equipment_id: str) -> FCU:
+async def get_fcu_control_result(project_id: str, equipment_id: str) -> Dict:
     async with AsyncClient() as client:
-        duo_duo = EquipmentInfoService(client, project_id)
+        duo_duo = Duoduo(client, project_id)
         platform = DataPlatformService(client, project_id)
         spaces = await duo_duo.get_space_by_equipment(equipment_id)
         for sp in spaces:
             transfer = SpaceInfoService(client, project_id, sp.get('id'))
             current_target = await transfer.get_current_temperature_target()
             realtime_temperature = await platform.get_realtime_temperature(sp.get('id'))
+            season = await transfer.get_season()
             temp_space_params = {
                 'id': sp.get('id'),
                 'temperature_target': current_target,
@@ -81,8 +96,17 @@ async def get_fcu_control_result(project_id: str, equipment_id: str) -> FCU:
         }
         fcu = FCU(**fcu_temp_params)
 
-    fcu_controller = FCUController(fcu)
+    fcu_controller = FCUController(fcu, season)
     await fcu_controller.run()
     regulated_fcu = fcu_controller.get_results()
 
-    return regulated_fcu
+    output = {
+        'onOff': 1 if regulated_fcu.running_status else 0,
+        'mode': regulated_fcu.work_mode,
+        'speed': regulated_fcu.air_valve_speed.value,
+        'temperature': int(round_half_up(regulated_fcu.setting_temperature, 1)),
+        'water': 1 if regulated_fcu.running_status else 0
+    }
+    logger.debug(output)
+
+    return output

+ 16 - 3
app/schemas/equipment.py

@@ -18,12 +18,13 @@ class AirValveSpeed(float, Enum):
 class BaseEquipment(BaseModel):
     id: str
     running_status: Optional[bool] = False
-    setting_temperature: Optional[float] = 0.0
 
 
 class FCU(BaseEquipment):
+    work_mode: Optional[int]
     air_valve_speed: Optional[AirValveSpeed] = AirValveSpeed.off
     space: Optional[Space]
+    setting_temperature: Optional[float] = 0.0
 
 
 class VAVBox(BaseEquipment):
@@ -33,9 +34,21 @@ class VAVBox(BaseEquipment):
     supply_air_flow_set: Optional[float]
     supply_air_flow_lower_limit: Optional[float]
     supply_air_flow_upper_limit: Optional[float]
+    setting_temperature: Optional[float] = 0.0
 
 
-class AHU(BaseModel):
-    id: str
+class AHU(BaseEquipment):
     fan_freq_set: float
     supply_air_temperature_set: Optional[float]
+
+
+class VentilationFan(BaseEquipment):
+    in_cloud_status: bool
+    on_time: str
+    off_time: str
+
+
+class PAU(BaseEquipment):
+    in_cloud_status: bool
+    on_time: str
+    off_time: str