|
@@ -45,7 +45,7 @@ class DeviceDataView(View):
|
|
|
return self.device_active(request_dict, response)
|
|
|
if operation == 'global/regional': # 全球设备分布
|
|
|
return self.global_regional(request, request_dict, response)
|
|
|
- if operation == 'golbal/type': # 全球设备类型
|
|
|
+ if operation == 'global/type': # 全球设备类型
|
|
|
return self.golbal_type(request, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
@@ -122,7 +122,7 @@ class DeviceDataView(View):
|
|
|
for item in result['result']['countries']:
|
|
|
flag = 0
|
|
|
for each in device_list:
|
|
|
- if each['name'] == item['name']:
|
|
|
+ if each['countryName'] == item['countryName']:
|
|
|
each['count'] += int(item['count'])
|
|
|
device_count += int(item['count'])
|
|
|
flag = 1
|
|
@@ -141,15 +141,16 @@ class DeviceDataView(View):
|
|
|
region_count += item['count']
|
|
|
flag = 1
|
|
|
break
|
|
|
- if flag == 0:
|
|
|
- region_list.append(item)
|
|
|
- region_count += item['count']
|
|
|
+ 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 = {
|
|
|
- 'countries': CommonService.list_sort(device_list[:20])
|
|
|
+ 'countries': CommonService.list_sort(device_list[:20]),
|
|
|
+ 'continent': region_list
|
|
|
}
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
@@ -207,93 +208,111 @@ class DeviceDataView(View):
|
|
|
info_list = []
|
|
|
count_unique = device_type_qs.count()
|
|
|
# 统计该时间段的设备数量(去重)
|
|
|
- for item in device_info_qs:
|
|
|
+ for item in time_list:
|
|
|
start_time = datetime.datetime.fromtimestamp(int(item[0]))
|
|
|
end_time = datetime.datetime.fromtimestamp(int(item[1]))
|
|
|
- device_type = device_info_qs.filter(data_joined__range=(start_time, end_time)).values(
|
|
|
- 'UID')
|
|
|
info_dict = {
|
|
|
- 'count': device_type.count(),
|
|
|
'startTime': item[0],
|
|
|
'endTime': item[1]
|
|
|
}
|
|
|
+ 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)
|
|
|
- # 统计地区设备数量
|
|
|
- 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, res)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ # 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)
|
|
|
except Exception as e:
|
|
|
return response.json(500, repr(e))
|
|
|
|