|
@@ -10,11 +10,10 @@
|
|
|
import datetime
|
|
|
|
|
|
import requests
|
|
|
-from django.db.models import Count, Q, Sum
|
|
|
+from django.db.models import Q, Sum
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from Model.models import Device_Info, CountryModel, UidSetModel, DeviceTypeModel, VideoPlaybackTimeModel, \
|
|
|
- DeviceInfoSummary
|
|
|
+from Model.models import CountryModel, UidSetModel, DeviceInfoSummary
|
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
@@ -362,11 +361,11 @@ class DeviceDataView(View):
|
|
|
try:
|
|
|
device_info_summary_qs = DeviceInfoSummary.objects.filter(
|
|
|
time__range=(start_time, end_time), query_type=1).values('country', 'count')
|
|
|
- null_list = []
|
|
|
+ res = {}
|
|
|
if not device_info_summary_qs.exists():
|
|
|
- return response.json(0, null_list)
|
|
|
+ return response.json(0, res)
|
|
|
count_all = device_info_summary_qs.aggregate(total=Sum('count'))['total']
|
|
|
- res = {}
|
|
|
+
|
|
|
video_list = []
|
|
|
region_list = []
|
|
|
for item in time_list:
|
|
@@ -421,17 +420,11 @@ class DeviceDataView(View):
|
|
|
return response.json(444, {'error param': 'startTime or endTime or timeUnit'})
|
|
|
try:
|
|
|
uid_set_qs = DeviceInfoSummary.objects.filter(time__range=(start_time, end_time), query_type=0)
|
|
|
- null_list = []
|
|
|
+ res = {}
|
|
|
if not uid_set_qs.exists():
|
|
|
- return response.json(0, null_list)
|
|
|
+ return response.json(0, res)
|
|
|
count_all = uid_set_qs.aggregate(total=Sum('count'))['total']
|
|
|
# 统计该时间段的设备数量(已去重)
|
|
|
- res = {
|
|
|
- 'addDevice': '',
|
|
|
- 'region': '',
|
|
|
- 'type': '',
|
|
|
- 'version': '',
|
|
|
- }
|
|
|
info_list = []
|
|
|
region_list = []
|
|
|
type_list = []
|
|
@@ -523,17 +516,15 @@ class DeviceDataView(View):
|
|
|
统计地区设备数量
|
|
|
@param response:响应对象
|
|
|
"""
|
|
|
- all_device_qs = DeviceInfoSummary.objects.all()
|
|
|
+ all_device_qs = DeviceInfoSummary.objects.filter(query_type=0).values('continent', 'count', 'country')
|
|
|
if not all_device_qs.exists():
|
|
|
return response.json(173)
|
|
|
- all_country_qs = all_device_qs.values('count', 'country')
|
|
|
- all_continent_qs = all_device_qs.values('continent')
|
|
|
- country_count = all_country_qs.aggregate(total=Sum('count'))['total']
|
|
|
+ country_count = all_device_qs.aggregate(total=Sum('count'))['total']
|
|
|
res = {}
|
|
|
try:
|
|
|
continent_list = []
|
|
|
region_list = []
|
|
|
- for item in all_country_qs:
|
|
|
+ for item in all_device_qs:
|
|
|
country_temp_dict = eval(item['country'])
|
|
|
for x, y in country_temp_dict.items():
|
|
|
flag = 0
|
|
@@ -549,7 +540,7 @@ class DeviceDataView(View):
|
|
|
})
|
|
|
for item in region_list:
|
|
|
item['rate'] = round(item['count'] / country_count * 100, 2) if country_count else 0
|
|
|
- for item in all_continent_qs:
|
|
|
+ for item in all_device_qs:
|
|
|
continent_temp_dict = eval(item['continent'])
|
|
|
for x, y in continent_temp_dict.items():
|
|
|
flag = 0
|
|
@@ -579,7 +570,7 @@ class DeviceDataView(View):
|
|
|
@param response:响应对象
|
|
|
@return:
|
|
|
"""
|
|
|
- all_device_qs = DeviceInfoSummary.objects.filter().values('device_type', 'count')
|
|
|
+ all_device_qs = DeviceInfoSummary.objects.filter(query_type=0).values('device_type', 'count')
|
|
|
if not all_device_qs.exists():
|
|
|
return response.json(173)
|
|
|
country_count = all_device_qs.aggregate(total=Sum('count'))['total']
|
|
@@ -602,8 +593,7 @@ class DeviceDataView(View):
|
|
|
})
|
|
|
for item in device_type_list:
|
|
|
item['rate'] = round(item['count'] / country_count * 100, 2) if country_count else 0
|
|
|
-
|
|
|
- res['type'] = device_type_list
|
|
|
+ res['type'] = CommonService.list_sort(device_type_list)
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
print(e)
|