|
@@ -225,14 +225,12 @@ class DeviceDataView(View):
|
|
|
res = requests.get(url=url, params=request_dict, headers=headers)
|
|
|
result = res.json()
|
|
|
if result['result_code'] == 0:
|
|
|
- for item in result['result']['region']:
|
|
|
+ for item in result['result']['type']:
|
|
|
flag = 0
|
|
|
for each in type_list:
|
|
|
- if item['countryName'] == each['countryName']:
|
|
|
+ if item['type'] == each['type']:
|
|
|
each['count'] += item['count']
|
|
|
type_count += item['count']
|
|
|
- each['countryType'] += item['countryType']
|
|
|
- type_count += item['countryType']
|
|
|
flag = 1
|
|
|
break
|
|
|
if flag == 0:
|
|
@@ -355,13 +353,9 @@ class DeviceDataView(View):
|
|
|
'userID__region_country').annotate(count=Count('userID__region_country')).order_by('-count')
|
|
|
for item in type_country_qs:
|
|
|
country_id = item['userID__region_country']
|
|
|
- country_qs = CountryModel.objects.filter(id=country_id).values('country_name')
|
|
|
- country_name = country_qs[0]['country_name'] if country_qs.exists() else '未知区域'
|
|
|
- country_qs = vod_hls_model_qs.filter(uid__in=uid_list).values('uid').order_by(
|
|
|
- 'uid').distinct()
|
|
|
- total_list = [item[key] for item in country_qs for key in item]
|
|
|
- country_count = len(total_list)
|
|
|
- rate = round(country_count / count_all * 100, 2)
|
|
|
+ country_name_qs = CountryModel.objects.filter(id=country_id).values('country_name')
|
|
|
+ country_name = country_name_qs[0]['country_name'] if country_name_qs.exists() else '未知区域'
|
|
|
+ rate = round(item['count'] / count_all * 100, 2)
|
|
|
country_dict = {
|
|
|
'countryName': country_name,
|
|
|
'count': item['count'],
|
|
@@ -515,7 +509,7 @@ class DeviceDataView(View):
|
|
|
device_country_qs = Device_Info.objects.all().values('userID__region_country').annotate(
|
|
|
count=Count('userID__region_country')).order_by('-count')
|
|
|
device_info_qs = Device_Info.objects.values('UID').order_by('UID').distinct()
|
|
|
- count = device_info_qs.count()
|
|
|
+ count_all = device_info_qs.count()
|
|
|
if not device_country_qs.exists():
|
|
|
return response.json(444)
|
|
|
res = {}
|
|
@@ -550,7 +544,7 @@ class DeviceDataView(View):
|
|
|
'count': count
|
|
|
})
|
|
|
for item in continent_list:
|
|
|
- item['rate'] = round(item['count'] / count * 100, 2)
|
|
|
+ item['rate'] = round(item['count'] / count_all * 100, 2)
|
|
|
res['countries'] = device_country_list
|
|
|
res['continent'] = continent_list
|
|
|
return response.json(0, res)
|
|
@@ -581,41 +575,7 @@ class DeviceDataView(View):
|
|
|
'type': name,
|
|
|
'count': count
|
|
|
})
|
|
|
-
|
|
|
- device_country_qs = Device_Info.objects.all().values('userID__region_country').annotate(
|
|
|
- count=Count('userID__region_country')).order_by('-count')
|
|
|
- device_country_list = []
|
|
|
- for device_country in device_country_qs:
|
|
|
- country_id = device_country['userID__region_country']
|
|
|
- country_qs = CountryModel.objects.filter(id=country_id).values('country_name', 'region__name')
|
|
|
- if not country_qs.exists():
|
|
|
- country_name = '未知地区'
|
|
|
- else:
|
|
|
- country_name = country_qs[0]['country_name']
|
|
|
- device_type_qs = Device_Info.objects.filter(userID__region_country=country_id).values('Type').annotate(
|
|
|
- count=Count('Type', distinct=True)).order_by('-count')
|
|
|
- country_type_list = []
|
|
|
- for device_type in device_type_qs:
|
|
|
- type = device_type['Type']
|
|
|
- name = DEVICE_TYPE.get(type, '未知类型')
|
|
|
- name = name if name != 'UNKOWN' else '未知类型'
|
|
|
- count = device_type_qs.filter(Type=device_type['Type']).values('UID').annotate(
|
|
|
- count=Count('UID', distinct=True)).order_by('-count').count()
|
|
|
- country_type_list.append({
|
|
|
- 'type': name,
|
|
|
- 'count': count
|
|
|
- })
|
|
|
- count = Device_Info.objects.filter(
|
|
|
- userID__region_country=device_country['userID__region_country']).values('UID').annotate(
|
|
|
- count=Count('UID', distinct=True)).order_by('-count').count()
|
|
|
-
|
|
|
- device_country_list.append({
|
|
|
- 'countryName': country_name,
|
|
|
- 'count': count,
|
|
|
- 'countryType': country_type_list
|
|
|
- })
|
|
|
res['type'] = device_info_list
|
|
|
- res['region'] = device_country_list
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
print(e)
|