소스 검색

优化设备数据统计接口(当总数为零时输出零)

guanhailong 2 년 전
부모
커밋
a6df4f7320
1개의 변경된 파일25개의 추가작업 그리고 10개의 파일을 삭제
  1. 25 10
      AdminController/dataSystemManagement/DeviceDataController.py

+ 25 - 10
AdminController/dataSystemManagement/DeviceDataController.py

@@ -89,7 +89,10 @@ class DeviceDataView(View):
                             device_list.append(item)
                             device_count += item['count']
                     for item in device_list:
-                        item['rate'] = round(item['count'] / device_count * 100, 2)
+                        if device_count != 0:
+                            item['rate'] = round(item['count'] / device_count * 100, 2)
+                        else:
+                            break
                     for item in result['result']['region']:
                         flag = 0
                         for each in region_list:
@@ -102,7 +105,10 @@ class DeviceDataView(View):
                             region_list.append(item)
                             region_count += item['count']
                     for item in region_list:
-                        item['rate'] = round(item['count'] / region_count * 100, 2)
+                        if region_count != 0:
+                            item['rate'] = round(item['count'] / region_count * 100, 2)
+                        else:
+                            break
                     for item in result['result']['type']:
                         flag = 0
                         for each in type_list:
@@ -115,7 +121,10 @@ class DeviceDataView(View):
                             type_list.append(item)
                             type_count += item['count']
                     for item in type_list:
-                        item['rate'] = round(item['count'] / type_count * 100, 2)
+                        if type_count != 0:
+                            item['rate'] = round(item['count'] / type_count * 100, 2)
+                        else:
+                            break
                     for item in result['result']['version']:
                         flag = 0
                         for each in order_list:
@@ -128,7 +137,10 @@ class DeviceDataView(View):
                             order_list.append(item)
                             order_count += item['count']
                     for item in order_list:
-                        item['rate'] = round(item['count'] / order_count * 100, 2)
+                        if order_count != 0:
+                            item['rate'] = round(item['count'] / order_count * 100, 2)
+                        else:
+                            break
                 else:
                     return response.json(result['result_code'])
             res = {
@@ -176,7 +188,10 @@ class DeviceDataView(View):
                             type_list.append(item)
                             type_count += item['count']
                     for item in type_list:
-                        item['rate'] = round(item['count'] / type_count * 100, 2)
+                        if type_count != 0:
+                            item['rate'] = round(item['count'] / type_count * 100, 2)
+                        else:
+                            break
                     for item in result['result']['region']:
                         flag = 0
                         for each in region_list:
@@ -189,7 +204,10 @@ class DeviceDataView(View):
                             region_list.append(item)
                             region_count += item['count']
                     for item in region_list:
-                        item['rate'] = round(item['count'] / region_count * 100, 2)
+                        if region_count != 0:
+                            item['rate'] = round(item['count'] / region_count * 100, 2)
+                        else:
+                            break
                 else:
                     return response.json(result['result_code'])
 
@@ -324,15 +342,12 @@ class DeviceDataView(View):
         e_time = datetime.datetime.fromtimestamp(int(end_time))
         time_list = CommonService.cutting_time(s_time, e_time, unit_time)
         try:
-            # video_playback_time_qs = VideoPlaybackTimeModel.objects.filter(
-            #     startTime__range=(start_time, end_time)).values('uid', 'startTime')
             video_playback_time_qs = VideoPlaybackTimeModel.objects.filter(
                      startTime__range=(start_time, end_time)).values('uid').order_by('uid').distinct()
             null_list = []
             if not video_playback_time_qs.exists():
                 return response.json(0, null_list)
             count_all = video_playback_time_qs.count()
-            # video_playback_uid_qs = video_playback_time_qs.values('uid').order_by('uid').distinct()
             res = {}
             video_list = []
             region_list = []
@@ -491,7 +506,7 @@ class DeviceDataView(View):
         """
         uid_set_qs = UidSetModel.objects.values('tb_country')
         if not uid_set_qs.exists():
-            return response.json(444)
+            return response.json(173)
         tb_country_qs = uid_set_qs.values('tb_country').annotate(
             count=Count('tb_country')).order_by('-count')
         res = {}