Browse Source

amend Duoduo service's name and add some function for platform service

chenhaiyang 4 years ago
parent
commit
56000d72c0

+ 2 - 3
app/controllers/equipment/ahu/basic.py

@@ -8,7 +8,7 @@ from loguru import logger
 from app.schemas.equipment import AHU
 from app.schemas.system import ACAT
 from app.services.platform import DataPlatformService, InfoCode
-from app.services.transfer import ReviewService, EquipmentInfoService
+from app.services.transfer import Duoduo
 from app.services.weather import WeatherService
 
 
@@ -66,8 +66,7 @@ class AHUController:
 async def get_freq_controlled(project_id: str, equipment_id: str) -> None:
     async with AsyncClient() as client:
         platform = DataPlatformService(client, project_id)
-        review_service = ReviewService(client, project_id)
-        # equip_service = EquipmentInfoService(client, project_id)
+        review_service = Duoduo(client, project_id)
 
         fan_freq_set = await platform.get_realtime_fan_freq_set(equipment_id)
         # system = await equip_service.get_system_by_equipment(equipment_id)

+ 2 - 2
app/controllers/equipment/fcu/q_learning.py

@@ -8,7 +8,7 @@ from loguru import logger
 
 from app.controllers.events import q_learning_models
 from app.services.platform import DataPlatformService
-from app.services.transfer import EquipmentInfoService, SpaceInfoService
+from app.services.transfer import Duoduo, SpaceInfoService
 from app.services.transfer import Season
 
 
@@ -95,7 +95,7 @@ class QLearningCommandBuilder:
 @logger.catch()
 async def get_fcu_q_learning_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)

+ 2 - 2
app/controllers/equipment/vav.py

@@ -10,7 +10,7 @@ from app.controllers.equipment.controller import EquipmentController
 from app.schemas.equipment import VAVBox, FCU
 from app.schemas.space import Space
 from app.services.platform import DataPlatformService
-from app.services.transfer import EquipmentInfoService, SpaceInfoService
+from app.services.transfer import Duoduo, SpaceInfoService
 
 
 class VAVController(EquipmentController):
@@ -88,7 +88,7 @@ class VAVController(EquipmentController):
 @logger.catch()
 async def get_vav_control_result(project_id: str, equipment_id: str) -> VAVBox:
     async with AsyncClient() as client:
-        duo_duo = EquipmentInfoService(client, project_id)
+        duo_duo = Duoduo(client, project_id)
         platform = DataPlatformService(client, project_id)
 
         _AHU_LIST = [

+ 14 - 0
app/services/platform.py

@@ -28,6 +28,7 @@ class InfoCode(str, Enum):
     fan_freq_set = 'FanFreqSet'
     supply_static_press = 'SupplyStaticPress'
     supply_static_press_set = 'SupplyStaticPressSet'
+    running_status = 'RunStatus'
 
 
 class DataPlatformService(Service):
@@ -209,6 +210,16 @@ class DataPlatformService(Service):
 
         return lower, upper
 
+    async def get_schedule(self, equipment_id: str) -> Tuple[str, str]:
+        on_time = await self.get_static_info('ctm-OnTime', equipment_id)
+        off_time = await self.get_static_info('ctm-OffTime', equipment_id)
+        if not on_time:
+            on_time = '080000'
+        if not off_time:
+            off_time = '190000'
+
+        return on_time, off_time
+
     async def get_realtime_fan_freq_set(self, equipment_id: str) -> float:
         return await self.get_realtime_data(InfoCode.fan_freq_set, equipment_id)
 
@@ -218,6 +229,9 @@ class DataPlatformService(Service):
     async def get_realtime_supply_static_press_set(self, system_id: str) -> float:
         return await self.get_realtime_data(InfoCode.supply_static_press_set, system_id)
 
+    async def get_realtime_running_status(self, equipment_id: str) -> float:
+        return await self.get_realtime_data(InfoCode.running_status, equipment_id)
+
     async def set_code_value(self, object_id: str, code: InfoCode, value: float):
         url = self._base_url.join('data-platform-3/parameter/setting')
         params = self._common_parameters()

+ 40 - 34
app/services/transfer.py

@@ -188,14 +188,41 @@ class SpaceInfoService(Service):
         return result
 
 
-class EquipmentInfoService(Service):
+class Duoduo(Service):
 
     def __init__(self, client: AsyncClient, project_id: str, server_settings=settings):
-        super(EquipmentInfoService, self).__init__(client)
+        super(Duoduo, self).__init__(client)
         self._project_id = project_id
         self._base_url = URL(server_settings.TRANSFER_HOST)
         self._now_time = get_time_str()
 
+    async def get_fill_rate(self):
+        url = self._base_url.join('duoduo-service/review-service/space/report/quarter/query')
+        payload = {
+            'criteria': {
+                'projectId': self._project_id,
+                'date': arrow.get(self._now_time, TIME_FMT).date().strftime('%Y%m%d')
+            },
+            'orders': [
+                {
+                    'column': 'time',
+                    'asc': False
+                }
+            ],
+            'page': 1,
+            'size': 1
+        }
+
+        raw_info = await self._post(url, payload=payload)
+        try:
+            content = raw_info.get('content')[-1]
+            hot_rate = (content.get('hotNum')
+                        / (content.get('normalNum') + content.get('hotNum') + content.get('coldNum')))
+        except KeyError and ZeroDivisionError:
+            hot_rate = 0.0
+
+        return hot_rate
+
     async def get_space_by_equipment(self, equipment_id: str) -> List[dict]:
         url = self._base_url.join('duoduo-service/object-service/object/space/findForServe')
         params = {
@@ -225,38 +252,17 @@ class EquipmentInfoService(Service):
 
         return system_list
 
-
-class ReviewService(Service):
-
-    def __init__(self, client: AsyncClient, project_id: str, server_settings=settings):
-        super(ReviewService, self).__init__(client)
-        self._project_id = project_id
-        self._base_url = URL(server_settings.TRANSFER_HOST)
-        self._now_time = get_time_str()
-
-    async def get_fill_rate(self):
-        url = self._base_url.join('duoduo-service/review-service/space/report/quarter/query')
-        payload = {
-            'criteria': {
-                'projectId': self._project_id,
-                'date': arrow.get(self._now_time, TIME_FMT).date().strftime('%Y%m%d')
-            },
-            'orders': [
-                {
-                    'column': 'time',
-                    'asc': False
-                }
-            ],
-            'page': 1,
-            'size': 1
+    async def get_day_type(self) -> Dict:
+        url = self._base_url.join('duoduo-service/custom-service/custom/getDateInfo')
+        params = {
+            'projectId': self._project_id,
+            'date': arrow.get(self._now_time, TIME_FMT).date().strftime('%Y%m%d')
         }
+        raw_info = await self._get(url, params)
 
-        raw_info = await self._post(url, payload=payload)
-        try:
-            content = raw_info.get('content')[-1]
-            hot_rate = (content.get('hotNum')
-                        / (content.get('normalNum') + content.get('hotNum') + content.get('coldNum')))
-        except KeyError and ZeroDivisionError:
-            hot_rate = 0.0
+        result = {
+            'day_type': raw_info.get('dayType'),
+            'season': raw_info.get('seasonType')
+        }
 
-        return hot_rate
+        return result