|
@@ -14,7 +14,7 @@ from django.db.models import Count
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from Ansjer.config import DEVICE_TYPE
|
|
|
-from Model.models import Device_Info, CountryModel, Order_Model
|
|
|
+from Model.models import Device_Info, CountryModel, Order_Model, VodHlsModel
|
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
@@ -47,13 +47,17 @@ class DeviceDataView(View):
|
|
|
return self.global_regional(request, request_dict, response)
|
|
|
if operation == 'global/type': # 全球设备类型
|
|
|
return self.golbal_type(request, request_dict, response)
|
|
|
+ if operation == 'global/active': # 全球设备活跃分布
|
|
|
+ return self.golbal_active(request, request_dict, response)
|
|
|
+ if operation == 'global/addDevice': # 全球新增设备数据
|
|
|
+ return self.golbal_add_device(request, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
|
@classmethod
|
|
|
- def golbal_type(cls, request, request_dict, response):
|
|
|
+ def golbal_add_device(cls, request, request_dict, response):
|
|
|
"""
|
|
|
- 全球设备类型分布
|
|
|
+ 全球新增设备数据
|
|
|
@param request:请求
|
|
|
@param request_dict:请求参数
|
|
|
@param response: 响应对象
|
|
@@ -63,21 +67,170 @@ class DeviceDataView(View):
|
|
|
headers = {
|
|
|
'Authorization': request.META.get('HTTP_AUTHORIZATION')
|
|
|
}
|
|
|
+ device_list = []
|
|
|
+ device_count = 0
|
|
|
type_list = []
|
|
|
type_count = 0
|
|
|
+ region_list = []
|
|
|
+ region_count = 0
|
|
|
+ order_list = []
|
|
|
+ order_count = 0
|
|
|
for url in url_list:
|
|
|
url = url + request.path.replace('global/', '')
|
|
|
res = requests.get(url=url, params=request_dict, headers=headers)
|
|
|
result = res.json()
|
|
|
if result['result_code'] == 0:
|
|
|
+ for item in result['result']['addDevice']:
|
|
|
+ flag = 0
|
|
|
+ for each in device_list:
|
|
|
+ if item['startTime'] == each['startTime'] and item['endTime'] == each['endTime']:
|
|
|
+ each['count'] += item['count']
|
|
|
+ device_count += item['count']
|
|
|
+ flag = 1
|
|
|
+ break
|
|
|
+ if flag == 0:
|
|
|
+ device_list.append(item)
|
|
|
+ device_count += item['count']
|
|
|
+ for item in device_list:
|
|
|
+ item['rate'] = round(item['count'] / device_count * 100, 2)
|
|
|
for item in result['result']['region']:
|
|
|
+ flag = 0
|
|
|
+ for each in region_list:
|
|
|
+ if item['countryName'] == each['countryName']:
|
|
|
+ each['count'] += item['count']
|
|
|
+ region_count += item['count']
|
|
|
+ flag = 1
|
|
|
+ break
|
|
|
+ if flag == 0:
|
|
|
+ region_list.append(item)
|
|
|
+ region_count += item['count']
|
|
|
+ for item in region_list:
|
|
|
+ item['rate'] = round(item['count'] / region_count * 100, 2)
|
|
|
+ for item in result['result']['type']:
|
|
|
flag = 0
|
|
|
for each in type_list:
|
|
|
+ if item['type'] == each['type']:
|
|
|
+ each['count'] += item['count']
|
|
|
+ type_count += item['count']
|
|
|
+ flag = 1
|
|
|
+ break
|
|
|
+ if flag == 0:
|
|
|
+ type_list.append(item)
|
|
|
+ type_count += item['count']
|
|
|
+ for item in type_list:
|
|
|
+ item['rate'] = round(item['count'] / type_count * 100, 2)
|
|
|
+ for item in result['result']['version']:
|
|
|
+ flag = 0
|
|
|
+ for each in order_list:
|
|
|
+ if item['type'] == each['type']:
|
|
|
+ each['count'] += item['count']
|
|
|
+ order_count += item['count']
|
|
|
+ flag = 1
|
|
|
+ break
|
|
|
+ if flag == 0:
|
|
|
+ order_list.append(item)
|
|
|
+ order_count += item['count']
|
|
|
+ for item in order_list:
|
|
|
+ item['rate'] = round(item['count'] / order_count * 100, 2)
|
|
|
+ else:
|
|
|
+ return response.json(result['result_code'])
|
|
|
+ res = {
|
|
|
+ 'device': device_list,
|
|
|
+ 'type': type_list,
|
|
|
+ 'region': CommonService.list_sort(region_list),
|
|
|
+ 'version': order_list
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def golbal_active(cls, request, request_dict, response):
|
|
|
+ """
|
|
|
+ 全球设备活跃分布
|
|
|
+ @param request:请求
|
|
|
+ @param request_dict:请求参数
|
|
|
+ @param response: 响应对象
|
|
|
+ """
|
|
|
+ url_list = CommonService.get_domain_name()
|
|
|
+ try:
|
|
|
+ headers = {
|
|
|
+ 'Authorization': request.META.get('HTTP_AUTHORIZATION')
|
|
|
+ }
|
|
|
+ type_list = []
|
|
|
+ type_count = 0
|
|
|
+ region_list = []
|
|
|
+ region_count = 0
|
|
|
+ for url in url_list:
|
|
|
+ url = url + request.path.replace('global/', '')
|
|
|
+ res = requests.get(url=url, params=request_dict, headers=headers)
|
|
|
+ result = res.json()
|
|
|
+ if result['result_code'] == 0:
|
|
|
+ for item in result['result']['vodHls']:
|
|
|
+ flag = 0
|
|
|
+ for each in type_list:
|
|
|
+ if item['startTime'] == each['startTime'] and item['endTime'] == each['endTime']:
|
|
|
+ each['count'] += item['count']
|
|
|
+ type_count += item['count']
|
|
|
+ flag = 1
|
|
|
+ break
|
|
|
+ if flag == 0:
|
|
|
+ type_list.append(item)
|
|
|
+ type_count += item['count']
|
|
|
+ for item in type_list:
|
|
|
+ item['rate'] = round(item['count'] / type_count * 100, 2)
|
|
|
+ for item in result['result']['region']:
|
|
|
+ flag = 0
|
|
|
+ for each in region_list:
|
|
|
if item['countryName'] == each['countryName']:
|
|
|
+ each['count'] += item['count']
|
|
|
+ region_count += item['count']
|
|
|
+ flag = 1
|
|
|
+ break
|
|
|
+ if flag == 0:
|
|
|
+ region_list.append(item)
|
|
|
+ region_count += item['count']
|
|
|
+ for item in region_list:
|
|
|
+ item['rate'] = round(item['count'] / region_count * 100, 2)
|
|
|
+ else:
|
|
|
+ return response.json(result['result_code'])
|
|
|
+
|
|
|
+ res = {
|
|
|
+ 'device': type_list,
|
|
|
+ 'region': CommonService.list_sort(region_list)
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def golbal_type(cls, request, request_dict, response):
|
|
|
+ """
|
|
|
+ 全球设备类型分布
|
|
|
+ @param request:请求
|
|
|
+ @param request_dict:请求参数
|
|
|
+ @param response: 响应对象
|
|
|
+ """
|
|
|
+ url_list = CommonService.get_domain_name()
|
|
|
+ try:
|
|
|
+ headers = {
|
|
|
+ 'Authorization': request.META.get('HTTP_AUTHORIZATION')
|
|
|
+ }
|
|
|
+ type_list = []
|
|
|
+ type_count = 0
|
|
|
+ for url in url_list:
|
|
|
+ url = url + request.path.replace('global/', '')
|
|
|
+ res = requests.get(url=url, params=request_dict, headers=headers)
|
|
|
+ result = res.json()
|
|
|
+ if result['result_code'] == 0:
|
|
|
+ for item in result['result']['type']:
|
|
|
+ flag = 0
|
|
|
+ for each in type_list:
|
|
|
+ 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:
|
|
@@ -158,26 +311,60 @@ class DeviceDataView(View):
|
|
|
|
|
|
@classmethod
|
|
|
def device_active(cls, request_dict, response):
|
|
|
- order_type = request_dict.get('orderType', None)
|
|
|
- if not order_type:
|
|
|
- return response.json(444)
|
|
|
- order_type = int(order_type)
|
|
|
- order_type_qs = Order_Model.objects.filter(order_type=order_type).values('UID').order_by('UID').distinct()
|
|
|
+ """
|
|
|
+ 设备活跃数据
|
|
|
+ @param request_dict:请求参数
|
|
|
+ @request_dict starTime:开始时间
|
|
|
+ @request_dict endTime:结束时间
|
|
|
+ @param response:响应对象
|
|
|
+ """
|
|
|
+ start_time = request_dict.get('startTime', None) # 时间戳
|
|
|
+ end_time = request_dict.get('endTime', None)
|
|
|
+ unit_time = request_dict.get('timeUnit', None)
|
|
|
+ if not all([start_time, end_time, unit_time]):
|
|
|
+ return response.json(444, {'error param': 'startTime or endTime or timeUnit'})
|
|
|
+ s_time = datetime.datetime.fromtimestamp(int(start_time))
|
|
|
+ e_time = datetime.datetime.fromtimestamp(int(end_time))
|
|
|
+ time_list = CommonService.cutting_time(s_time, e_time, unit_time)
|
|
|
try:
|
|
|
- order_type_list = []
|
|
|
- for order in order_type_qs:
|
|
|
- UID = order['UID']
|
|
|
- device_info_qs = Device_Info.objects.filter(UID=UID).values('Type').order_by('Type').distinct()
|
|
|
- if not device_info_qs.exists():
|
|
|
- continue
|
|
|
- device_info_qs = device_info_qs[0]['Type']
|
|
|
- order_type_list.append(device_info_qs)
|
|
|
- type_list = []
|
|
|
- for i in order_type_list:
|
|
|
- if i not in type_list:
|
|
|
- type_list.append(i)
|
|
|
+ vod_hls_model_qs = VodHlsModel.objects.filter(time__range=(start_time, end_time))
|
|
|
+ if not vod_hls_model_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ device_info = list(vod_hls_model_qs.values('uid').order_by('uid').distinct())
|
|
|
+ device_info_list = [item[key] for item in device_info for key in item]
|
|
|
+ count_all = len(device_info_list)
|
|
|
+ res = {}
|
|
|
+ vod_list = []
|
|
|
+ region_list = []
|
|
|
+ for item in time_list:
|
|
|
+ vod_hls_qs = vod_hls_model_qs.filter(time__range=(item[0], item[1]))
|
|
|
+ uid_qs = vod_hls_qs.values('uid').order_by('uid').distinct()
|
|
|
+ uid_list = [item[key] for item in uid_qs for key in item]
|
|
|
+ rate = round(uid_qs.count() / count_all * 100, 2)
|
|
|
+ vod_dict = {
|
|
|
+ 'count': uid_qs.count(),
|
|
|
+ 'rate': rate,
|
|
|
+ 'startTime': item[0],
|
|
|
+ 'endTime': item[1]
|
|
|
+ }
|
|
|
+ vod_list.append(vod_dict)
|
|
|
+ res['vodHls'] = vod_list
|
|
|
+ type_country_qs = Device_Info.objects.filter(UID__in=uid_list).values(
|
|
|
+ '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_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'],
|
|
|
+ 'rate': rate
|
|
|
+ }
|
|
|
+ region_list.append(country_dict)
|
|
|
+ res['region'] = region_list
|
|
|
|
|
|
- return response.json(0, type_list)
|
|
|
+ return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return response.json(500)
|
|
@@ -193,7 +380,7 @@ class DeviceDataView(View):
|
|
|
"""
|
|
|
start_time = request_dict.get('startTime', None) # 时间戳
|
|
|
end_time = request_dict.get('endTime', None)
|
|
|
- unit_time = request_dict.get('unitTime', None)
|
|
|
+ unit_time = request_dict.get('timeUnit', None)
|
|
|
order_type = request_dict.get('orderType', None)
|
|
|
if not all([start_time, end_time, unit_time, order_type]):
|
|
|
return response.json(444, {'error param': 'startTime or endTime or timeUnit or order_type'})
|
|
@@ -203,117 +390,114 @@ class DeviceDataView(View):
|
|
|
time_list = CommonService.cutting_time(start_time, end_time, unit_time)
|
|
|
try:
|
|
|
device_info_qs = Device_Info.objects.filter(data_joined__range=(start_time, end_time))
|
|
|
- device_count_qs = device_info_qs.count()
|
|
|
- device_type_qs = device_info_qs.values('UID').order_by('UID').distinct()
|
|
|
+ device_test_qs = Device_Info.objects.filter(data_joined__lt=start_time)
|
|
|
+ device_test = list(device_test_qs.values('UID').order_by('UID').distinct())
|
|
|
+ device_info = list(device_info_qs.values('UID').order_by('UID').distinct())
|
|
|
+ test_list = [item[key] for item in device_test for key in item]
|
|
|
+ device_info_list = [item[key] for item in device_info for key in item]
|
|
|
+ part_only_list = list(set(device_info_list) - set(test_list))
|
|
|
+ count_all = len(part_only_list)
|
|
|
+ count_all = int(count_all)
|
|
|
+ # 统计该时间段的设备数量(已去重)
|
|
|
+ res = {
|
|
|
+ 'addDevice': '',
|
|
|
+ 'region': '',
|
|
|
+ 'type': '',
|
|
|
+ 'version': '',
|
|
|
+ }
|
|
|
info_list = []
|
|
|
- count_unique = device_type_qs.count()
|
|
|
- # 统计该时间段的设备数量(去重)
|
|
|
+ region_list = []
|
|
|
+ type_list = []
|
|
|
+ version_list = []
|
|
|
for item in time_list:
|
|
|
start_time = datetime.datetime.fromtimestamp(int(item[0]))
|
|
|
end_time = datetime.datetime.fromtimestamp(int(item[1]))
|
|
|
+ device_qs = device_info_qs.filter(data_joined__range=(start_time, end_time))
|
|
|
+ device_test_qs = Device_Info.objects.filter(data_joined__lt=start_time)
|
|
|
+ device_test = list(device_test_qs.values('UID').order_by('UID').distinct())
|
|
|
+ device_info = list(device_qs.values('UID').order_by('UID').distinct())
|
|
|
+ test_list = [item[key] for item in device_test for key in item]
|
|
|
+ device_info_list = [item[key] for item in device_info for key in item]
|
|
|
+ part_only_list = list(set(device_info_list) - set(test_list))
|
|
|
+ count_part = len(part_only_list)
|
|
|
+ rate = round(count_part / count_all * 100, 2)
|
|
|
info_dict = {
|
|
|
'startTime': item[0],
|
|
|
- 'endTime': item[1]
|
|
|
+ 'endTime': item[1],
|
|
|
+ 'count': len(part_only_list),
|
|
|
+ 'rate': rate
|
|
|
}
|
|
|
- count = 0
|
|
|
- for device_type in device_type_qs:
|
|
|
- uid = device_type['UID']
|
|
|
- device_test_qs = Device_Info.objects.filter(data_joined__lt=start_time, UID=uid).values()
|
|
|
- if device_test_qs.exists():
|
|
|
- continue
|
|
|
- else:
|
|
|
- count += 1
|
|
|
- device_only_qs = device_info_qs.filter(UID=uid).values()
|
|
|
- device_only = device_only_qs[0]
|
|
|
- # res = {
|
|
|
- # 'country': '',
|
|
|
- # 'count': ''
|
|
|
- # }
|
|
|
- #
|
|
|
- # for country in device_only:
|
|
|
-
|
|
|
-
|
|
|
- info_dict['count'] = count
|
|
|
info_list.append(info_dict)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # info_list.append(info_dict)
|
|
|
- # # 统计地区设备数量
|
|
|
- # device_info_country_qs = device_info_qs.values('userID__region_country').annotate(
|
|
|
- # count=Count('userID__region_country')).order_by('-count')
|
|
|
- # region_list = []
|
|
|
- # for item in device_info_country_qs:
|
|
|
- # country_id = item['userID__region_country']
|
|
|
- # country_qs = CountryModel.objects.filter(id=country_id).values('country_name', 'id')
|
|
|
- # country_name = country_qs[0]['country_name'] if country_qs.exists() else '未知区域'
|
|
|
- # count = device_info_qs.filter(userID__region_country=item['userID__region_country']).values(
|
|
|
- # 'UID').annotate(count=Count('UID', distinct=True)).order_by('-count').count()
|
|
|
- # rate = round(count / count_unique * 100, 2)
|
|
|
- # country_dict = {
|
|
|
- # 'countryName': country_name,
|
|
|
- # 'count': count,
|
|
|
- # 'rate': rate
|
|
|
- # }
|
|
|
- # region_list.append(country_dict)
|
|
|
- # # 统计设备类型数量
|
|
|
- # device_info_type_qs = device_info_qs.values('Type').annotate(
|
|
|
- # count=Count('Type', distinct=True)).order_by('-count')
|
|
|
- # count = device_info_type_qs.count()
|
|
|
- # # count_list = []
|
|
|
- # # for device_info_country in device_info_type_qs:
|
|
|
- # # type = device_info_country['Type']
|
|
|
- # # count_list.append(type)
|
|
|
- # device_info_type_qs = device_info_type_qs.values('Type').distinct()
|
|
|
- # type_list = []
|
|
|
- # for device_type in device_info_type_qs:
|
|
|
- # type = device_type['Type']
|
|
|
- # name = DEVICE_TYPE.get(type, '未知类型')
|
|
|
- # name = name if name != 'UNKOWN' else '未知类型'
|
|
|
- # total = device_info_qs.filter(Type=device_type['Type']).values('UID').annotate(
|
|
|
- # count=Count('UID', distinct=True)).order_by('-count').count()
|
|
|
- # rate = round(total / count_unique * 100, 2) # count_unique 有误,跟device_info_type_qs 总数合不上 (可以看151行)
|
|
|
- # type_dict = {
|
|
|
- # 'type': name,
|
|
|
- # 'count': total,
|
|
|
- # 'rate': rate
|
|
|
- # }
|
|
|
- # type_list.append(type_dict)
|
|
|
- # # 统计设备版本数量
|
|
|
- # device_info_type_qs = device_info_qs.values('UID').annotate(
|
|
|
- # count=Count('UID', distinct=True)).order_by('-count')
|
|
|
- # count = device_info_type_qs.count()
|
|
|
- # uid_list = []
|
|
|
- # for device_clound in device_info_type_qs:
|
|
|
- # uid = device_clound['UID']
|
|
|
- # uid_list.append(uid)
|
|
|
- # order_model_qs = Order_Model.objects.filter(UID__in=uid_list).values('UID').annotate(
|
|
|
- # count=Count('UID', distinct=True)).values('order_type').order_by('order_type')
|
|
|
- # count = order_model_qs.count()
|
|
|
- # order_type_list = []
|
|
|
- # for order_model in order_model_qs:
|
|
|
- # orderType = order_model['order_type']
|
|
|
- # order_type_list.append(orderType)
|
|
|
- # version_list = []
|
|
|
- # res = {}
|
|
|
- # if order_type == 0:
|
|
|
- # res['name'] = '云存'
|
|
|
- # elif order_type == 1:
|
|
|
- # res['name'] = 'AI'
|
|
|
- # elif order_type == 2:
|
|
|
- # res['name'] = '联通4G'
|
|
|
- # res['total'] = order_type_list.count(order_type)
|
|
|
- # version_list.append(res)
|
|
|
- #
|
|
|
- # res = {
|
|
|
- # 'info': info_list,
|
|
|
- # 'region': region_list,
|
|
|
- # 'type': type_list,
|
|
|
- # 'version': version_list
|
|
|
- # }
|
|
|
- return response.json(0, info_list)
|
|
|
+ res['addDevice'] = info_list
|
|
|
+ # 统计地区设备数量
|
|
|
+ device_info_country_qs = device_info_qs.filter(UID__in=part_only_list).values(
|
|
|
+ 'userID__region_country').annotate(
|
|
|
+ count=Count('userID__region_country')).order_by('-count')
|
|
|
+ for item in device_info_country_qs:
|
|
|
+ country_id = item['userID__region_country']
|
|
|
+ country_qs = CountryModel.objects.filter(id=country_id).values('country_name', 'id')
|
|
|
+ country_name = country_qs[0]['country_name'] if country_qs.exists() else '未知区域'
|
|
|
+ country_qs = device_info_qs.filter(UID__in=part_only_list).values('UID').order_by(
|
|
|
+ 'UID').distinct().values(
|
|
|
+ 'userID__region_country')
|
|
|
+ total_list = [item[key] for item in country_qs for key in item]
|
|
|
+ country_count = total_list.count(country_id)
|
|
|
+ rate = round(country_count / count_part * 100, 2)
|
|
|
+ country_dict = {
|
|
|
+ 'countryName': country_name,
|
|
|
+ 'count': country_count,
|
|
|
+ 'rate': rate
|
|
|
+ }
|
|
|
+ region_list.append(country_dict)
|
|
|
+ res['region'] = CommonService.list_sort(region_list)
|
|
|
+ # 统计设备类型数量
|
|
|
+ device_info_type_qs = device_info_qs.filter(UID__in=part_only_list).values('Type').annotate(
|
|
|
+ count=Count('Type', distinct=True)).order_by('-count').distinct()
|
|
|
+ count = device_info_type_qs.count()
|
|
|
+ for device_type in device_info_type_qs:
|
|
|
+ type = device_type['Type']
|
|
|
+ name = DEVICE_TYPE.get(type, '未知类型')
|
|
|
+ name = name if name != 'UNKOWN' else '未知类型'
|
|
|
+ type_qs = device_info_qs.filter(UID__in=part_only_list).values('UID').order_by(
|
|
|
+ 'UID').distinct().values(
|
|
|
+ 'Type')
|
|
|
+ test_list = [item[key] for item in type_qs for key in item]
|
|
|
+ type_count = test_list.count(type)
|
|
|
+ rate = round(type_count / count_part * 100, 2)
|
|
|
+ type_dict = {
|
|
|
+ 'type': name,
|
|
|
+ 'count': type_count,
|
|
|
+ 'rate': rate
|
|
|
+ }
|
|
|
+ type_list.append(type_dict)
|
|
|
+ res['type'] = CommonService.list_sort(type_list)
|
|
|
+ # 统计设备版本数量
|
|
|
+ order_model_qs = Order_Model.objects.filter(UID__in=part_only_list).values('UID').annotate(
|
|
|
+ count=Count('UID', distinct=True))
|
|
|
+ order_model_qs = order_model_qs.filter(order_type=order_type).values('order_type', 'UID').order_by(
|
|
|
+ 'UID')
|
|
|
+ order_type_list = []
|
|
|
+ for order_model in order_model_qs:
|
|
|
+ orderType = order_model['UID']
|
|
|
+ order_type_list.append(orderType)
|
|
|
+ res_part = {}
|
|
|
+ device_info_type_qs = device_info_qs.filter(UID__in=order_type_list).values('Type').annotate(
|
|
|
+ count=Count('Type', distinct=True)).order_by('-count').distinct()
|
|
|
+ for device_type in device_info_type_qs:
|
|
|
+ type = device_type['Type']
|
|
|
+ name = DEVICE_TYPE.get(type, '未知类型')
|
|
|
+ res_part['type'] = name if name != 'UNKOWN' else '未知类型'
|
|
|
+ type_qs = device_info_qs.filter(UID__in=order_type_list).values('UID').order_by(
|
|
|
+ 'UID').distinct().values(
|
|
|
+ 'Type')
|
|
|
+ test_list = [item[key] for item in type_qs for key in item]
|
|
|
+ res_part['count'] = test_list.count(type)
|
|
|
+ res_part['rate'] = round(res_part['count'] / count_part * 100, 2)
|
|
|
+ version_list.append(res_part)
|
|
|
+ res['version'] = version_list
|
|
|
+ return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
+ print(e)
|
|
|
return response.json(500, repr(e))
|
|
|
|
|
|
@classmethod
|
|
@@ -325,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 = {}
|
|
@@ -360,9 +544,9 @@ class DeviceDataView(View):
|
|
|
'count': count
|
|
|
})
|
|
|
for item in continent_list:
|
|
|
- item['rate'] = round(item['count'] / count * 100, 2)
|
|
|
- res['countries'] = device_country_list
|
|
|
- res['continent'] = continent_list
|
|
|
+ item['rate'] = round(item['count'] / count_all * 100, 2)
|
|
|
+ res['countries'] = CommonService.list_sort(device_country_list)
|
|
|
+ res['continent'] = CommonService.list_sort(continent_list)
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
@@ -391,40 +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)
|