|
@@ -10,7 +10,7 @@
|
|
|
import datetime
|
|
|
|
|
|
import requests
|
|
|
-from django.db.models import Count, Q
|
|
|
+from django.db.models import Count
|
|
|
from django.views.generic.base import View
|
|
|
|
|
|
from Model.models import Device_Info, CountryModel, UidSetModel, DeviceTypeModel, VideoPlaybackTimeModel
|
|
@@ -51,23 +51,6 @@ class DeviceDataView(View):
|
|
|
if operation == 'global/addDevice': # 全球新增设备数据
|
|
|
return self.golbal_add_device(request, request_dict, response)
|
|
|
|
|
|
- # if operation == 'ip/country': #
|
|
|
- # return self.ip_country(response)
|
|
|
- # else:
|
|
|
- # return response.json(414)
|
|
|
- #
|
|
|
- # @staticmethod
|
|
|
- # def ip_country(response):
|
|
|
- # uid_set_qs = UidSetModel.objects.filter(~Q(ip='') & Q(tb_country=0)).values('ip')
|
|
|
- # for uid_set in uid_set_qs:
|
|
|
- # ip = uid_set['ip']
|
|
|
- # ipInfo = CommonService.getIpIpInfo(ip, 'CN')
|
|
|
- # country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('id')
|
|
|
- # if country_qs.exists():
|
|
|
- # country = country_qs[0]['id']
|
|
|
- # uid_set_qs.filter(ip=ip).update(tb_country=country)
|
|
|
- # return response.json(0)
|
|
|
-
|
|
|
@classmethod
|
|
|
def golbal_add_device(cls, request, request_dict, response):
|
|
|
"""
|
|
@@ -430,13 +413,13 @@ class DeviceDataView(View):
|
|
|
device_info_country_qs = uid_set_qs.values('tb_country').annotate(
|
|
|
count=Count('tb_country')).order_by(
|
|
|
'-count')
|
|
|
+ country_qs = uid_set_qs.values('tb_country')
|
|
|
+ country_list = [item[key] for item in country_qs for key in item]
|
|
|
for item in device_info_country_qs:
|
|
|
country_id = item['tb_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 = uid_set_qs.values('tb_country')
|
|
|
- total_list = [item[key] for item in country_qs for key in item]
|
|
|
- country_count = total_list.count(country_id)
|
|
|
+ country_count = country_list.count(country_id)
|
|
|
rate = round(country_count / count_all * 100, 2)
|
|
|
country_dict = {
|
|
|
'countryName': country_name,
|
|
@@ -456,13 +439,13 @@ class DeviceDataView(View):
|
|
|
'count': count_remain,
|
|
|
'rate': rate
|
|
|
})
|
|
|
+ type_qs = device_info_type_qs.values('Type')
|
|
|
+ device_type_list = [item[key] for item in type_qs for key in item]
|
|
|
for device_type in device_type_qs:
|
|
|
Type = device_type['Type']
|
|
|
device_type_name_qs = DeviceTypeModel.objects.filter(type=Type).values('name')
|
|
|
name = device_type_name_qs[0]['name'] if device_type_name_qs.exists() else '未知类型'
|
|
|
- type_qs = device_info_type_qs.values('Type')
|
|
|
- test_list = [item[key] for item in type_qs for key in item]
|
|
|
- type_count = test_list.count(Type)
|
|
|
+ type_count = device_type_list.count(Type)
|
|
|
rate = round(type_count / count_all * 100, 2)
|
|
|
type_list.append({
|
|
|
'type': name,
|
|
@@ -528,7 +511,7 @@ class DeviceDataView(View):
|
|
|
else:
|
|
|
name = '未知地区'
|
|
|
count = uid_set_qs.filter(
|
|
|
- tb_country=device_country['tb_country']).values('uid').annotate(
|
|
|
+ tb_country=country_id).values('uid').annotate(
|
|
|
count=Count('uid', distinct=True)).order_by('-count').count()
|
|
|
|
|
|
device_country_list.append({
|