Browse Source

fix a bug

chenhaiyang 4 years ago
parent
commit
3f00017e0e
2 changed files with 16 additions and 10 deletions
  1. 5 1
      app/controllers/equipment/ahu/basic.py
  2. 11 9
      app/services/transfer.py

+ 5 - 1
app/controllers/equipment/ahu/basic.py

@@ -60,7 +60,11 @@ async def get_freq_controlled(project_id: str, equipment_id: str) -> None:
         system = ['Sy1101050030eab54ad66b084a1cb1b919950b263280']
         press = await platform.get_realtime_supply_static_press(system[0])
         press_set = await platform.get_realtime_supply_static_press_set(system[0])
-        hot_rate = await review_service.get_fill_rate()
+        count = await review_service.get_fill_count()
+        try:
+            hot_rate = count.get('hotNum') / (count.get('hotNum') + count.get('coldNum') + count.get('normalNum'))
+        except ZeroDivisionError and KeyError:
+            hot_rate = 0.0
         supply_air_temperature_set = await platform.get_duration(
             InfoCode.supply_air_temperature_set,
             equipment_id,

+ 11 - 9
app/services/transfer.py

@@ -100,11 +100,14 @@ class SpaceInfoService(Service):
 
         try:
             pre_target_df = pd.DataFrame(raw_info.get('perTargets'))
-            normal_target_df = pd.DataFrame(raw_info.get('normalTargets'))
             pre_target_df.set_index('time', inplace=True)
-            normal_target_df.set_index('time', inplace=True)
         except KeyError:
             pre_target_df = pd.DataFrame()
+
+        try:
+            normal_target_df = pd.DataFrame(raw_info.get('normalTargets'))
+            normal_target_df.set_index('time', inplace=True)
+        except KeyError:
             normal_target_df = pd.DataFrame()
 
         return {
@@ -203,7 +206,7 @@ class Duoduo(Service):
 
         return Season(raw_info.get('data'))
 
-    async def get_fill_rate(self):
+    async def get_fill_count(self) -> Dict:
         url = self._base_url.join('duoduo-service/review-service/space/report/quarter/query')
         payload = {
             'criteria': {
@@ -221,14 +224,13 @@ class Duoduo(Service):
         }
 
         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 = raw_info.get('content')[-1]
+        except IndexError:
+            result = {}
 
-        return hot_rate
+        return result
 
     async def get_space_by_equipment(self, equipment_id: str) -> List[dict]:
         url = self._base_url.join('duoduo-service/object-service/object/space/findForServe')