|
@@ -75,7 +75,7 @@ class UserDataView(View):
|
|
|
s_time = datetime.datetime.fromtimestamp(int(item[0]))
|
|
|
e_time = datetime.datetime.fromtimestamp(int(item[1]))
|
|
|
user_date_qs = user_qs.filter(last_login__range=(s_time, e_time))
|
|
|
- rate = round(user_date_qs.count()/count*100, 2)
|
|
|
+ rate = round(user_date_qs.count() / count * 100, 2)
|
|
|
user_dict = {
|
|
|
'count': user_date_qs.count(),
|
|
|
'rate': rate,
|
|
@@ -132,7 +132,7 @@ class UserDataView(View):
|
|
|
s_time = datetime.datetime.fromtimestamp(int(item[0]))
|
|
|
e_time = datetime.datetime.fromtimestamp(int(item[1]))
|
|
|
user_date_qs = user_qs.filter(last_login__range=(s_time, e_time))
|
|
|
- rate = round(user_date_qs.count()/count*100, 2)
|
|
|
+ rate = round(user_date_qs.count() / count * 100, 2)
|
|
|
user_dict = {
|
|
|
'count': user_date_qs.count(),
|
|
|
'rate': rate,
|
|
@@ -176,13 +176,28 @@ class UserDataView(View):
|
|
|
user_qs = Device_User.objects.all()
|
|
|
count = user_qs.count()
|
|
|
user_qs = user_qs.values('region_country').annotate(count=Count('region_country')).order_by('-count')
|
|
|
+ continent_list = []
|
|
|
for item in user_qs:
|
|
|
country_id = item['region_country']
|
|
|
- country_qs = CountryModel.objects.filter(id=country_id).values('country_name')
|
|
|
+ country_qs = CountryModel.objects.filter(id=country_id).values('country_name', 'region__name')
|
|
|
item['countryName'] = country_qs[0]['country_name'] if country_qs.exists() else '未知区域'
|
|
|
item['rate'] = round(item['count'] / count * 100, 2)
|
|
|
+ if country_qs.exists():
|
|
|
+ flag = 0
|
|
|
+ for each in continent_list:
|
|
|
+ if country_qs[0]['region__name'] == each['continentName']:
|
|
|
+ each['count'] += item['count']
|
|
|
+ flag = 1
|
|
|
+ break
|
|
|
+ if flag == 0:
|
|
|
+ continent_list.append({
|
|
|
+ 'continentName': country_qs[0]['region__name'],
|
|
|
+ 'count': item['count']
|
|
|
+ })
|
|
|
+ for item in continent_list:
|
|
|
+ item['rate'] = round(item['count'] / count * 100, 2)
|
|
|
res['countries'] = list(user_qs)
|
|
|
-
|
|
|
+ res['continent'] = continent_list
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
return response.json(500, repr(e))
|
|
@@ -222,7 +237,7 @@ class UserDataView(View):
|
|
|
user_list.append(item)
|
|
|
user_count += item['count']
|
|
|
for item in user_list:
|
|
|
- item['rate'] = round(item['count']/user_count*100, 2)
|
|
|
+ item['rate'] = round(item['count'] / user_count * 100, 2)
|
|
|
for item in result['result']['region']:
|
|
|
flag = 0
|
|
|
for each in region_list:
|
|
@@ -235,7 +250,7 @@ class UserDataView(View):
|
|
|
region_list.append(item)
|
|
|
region_count += item['count']
|
|
|
for item in region_list:
|
|
|
- item['rate'] = round(item['count']/region_count*100, 2)
|
|
|
+ item['rate'] = round(item['count'] / region_count * 100, 2)
|
|
|
else:
|
|
|
return response.json(result['result_code'])
|
|
|
res = {
|
|
@@ -281,7 +296,7 @@ class UserDataView(View):
|
|
|
user_list.append(item)
|
|
|
user_count += item['count']
|
|
|
for item in user_list:
|
|
|
- item['rate'] = round(item['count']/user_count*100, 2)
|
|
|
+ item['rate'] = round(item['count'] / user_count * 100, 2)
|
|
|
for item in result['result']['region']:
|
|
|
flag = 0
|
|
|
for each in region_list:
|
|
@@ -294,7 +309,7 @@ class UserDataView(View):
|
|
|
region_list.append(item)
|
|
|
region_count += item['count']
|
|
|
for item in region_list:
|
|
|
- item['rate'] = round(item['count']/region_count*100, 2)
|
|
|
+ item['rate'] = round(item['count'] / region_count * 100, 2)
|
|
|
else:
|
|
|
return response.json(result['result_code'])
|
|
|
res = {
|
|
@@ -319,6 +334,7 @@ class UserDataView(View):
|
|
|
'Authorization': request.META.get('HTTP_AUTHORIZATION')
|
|
|
}
|
|
|
user_list = []
|
|
|
+ region_list = []
|
|
|
user_count = 0
|
|
|
for url in url_list:
|
|
|
url = url + request.path.replace('global/', '')
|
|
@@ -340,12 +356,23 @@ class UserDataView(View):
|
|
|
for item in user_list:
|
|
|
rate = round(item['count'] / user_count * 100, 2)
|
|
|
item['rate'] = rate
|
|
|
+ for item in result['result']['continent']:
|
|
|
+ flag = 0
|
|
|
+ for each in region_list:
|
|
|
+ if each['continentName'] == item['continentName']:
|
|
|
+ each['count'] += item['count']
|
|
|
+ flag = 1
|
|
|
+ break
|
|
|
+ if flag == 0:
|
|
|
+ region_list.append(region_list)
|
|
|
+ for item in region_list:
|
|
|
+ item['rate'] = round(item['count'] / user_count * 100, 2)
|
|
|
else:
|
|
|
return response.json(result['result_code'])
|
|
|
res = {
|
|
|
- 'countries': CommonService.list_sort(user_list[:20])
|
|
|
+ 'countries': CommonService.list_sort(user_list[:20]),
|
|
|
+ 'continent': region_list
|
|
|
}
|
|
|
return response.json(0, res)
|
|
|
except Exception as e:
|
|
|
return response.json(500, repr(e))
|
|
|
-
|