164 lines
6.1 KiB
Python
164 lines
6.1 KiB
Python
from django.shortcuts import render
|
|
from django.http import HttpResponse
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from polls.models import UnqualifiedMedia
|
|
from dashboard.models import Douyin, NewMedia, Qita, Toutiao, Weibo, Weixin, Userprofile
|
|
from django.db.models import Count, Sum
|
|
|
|
COMPARTMENTS = {
|
|
'620100000000': '兰州市',
|
|
'620200000000': '嘉峪关市',
|
|
'620300000000': '金昌市',
|
|
'620400000000': '白银市',
|
|
'620500000000': '天水市',
|
|
'620600000000': '武威市',
|
|
'620700000000': '张掖市',
|
|
'620800000000': '平凉市',
|
|
'620900000000': '酒泉市',
|
|
'621000000000': '庆阳市',
|
|
'621100000000': '定西市',
|
|
'621200000000': '陇南市',
|
|
'622900000000': '临夏回族自治州',
|
|
'623000000000': '甘南藏族自治州',
|
|
'620171000000': '兰州新区',
|
|
'': '未知',
|
|
}
|
|
|
|
|
|
@csrf_exempt
|
|
def monitor_statistics(request):
|
|
|
|
profile_status_0_count = Userprofile.objects.filter(status=0).count()
|
|
profile_status_1_count = Userprofile.objects.filter(status=1).count()
|
|
user_total = profile_status_0_count + profile_status_1_count
|
|
chart4_data = []
|
|
chart4_data.append({'name': '激活', 'value': profile_status_1_count})
|
|
chart4_data.append({'name': '未激活', 'value': profile_status_0_count})
|
|
|
|
wbc = Weibo.objects.exclude(status=0).count()
|
|
wxc = Weixin.objects.exclude(status=0).count()
|
|
ttc = Toutiao.objects.exclude(status=0).count()
|
|
qtc = Qita.objects.exclude(status=0).count()
|
|
dyc = Douyin.objects.exclude(status=0).count()
|
|
total = wbc+wxc+ttc+qtc+dyc
|
|
|
|
chart1_data = []
|
|
chart1_data.append({'name': '微信', 'value': wxc})
|
|
chart1_data.append({'name': '微博', 'value': wbc})
|
|
chart1_data.append({'name': '头条', 'value': ttc})
|
|
chart1_data.append({'name': '抖音', 'value': dyc})
|
|
chart1_data.append({'name': '其它', 'value': qtc})
|
|
|
|
results = dict()
|
|
q = Weixin.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
|
|
'organization__cities').annotate(num_media=Count('organization__cities'))
|
|
for row in q:
|
|
code = row['organization__cities']
|
|
if not code:
|
|
continue
|
|
compartment = COMPARTMENTS[code]
|
|
if code in results:
|
|
nums = results[compartment]
|
|
nums.append(row['num_media'])
|
|
else:
|
|
results[compartment] = [row['num_media']]
|
|
|
|
q = Weibo.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
|
|
'organization__cities').annotate(num_media=Count('organization__cities'))
|
|
for row in q:
|
|
code = row['organization__cities']
|
|
if not code:
|
|
continue
|
|
compartment = COMPARTMENTS[code]
|
|
if compartment in results:
|
|
nums = results[compartment]
|
|
nums.append(row['num_media'])
|
|
else:
|
|
results[compartment] = [row['num_media']]
|
|
|
|
q = Toutiao.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
|
|
'organization__cities').annotate(num_media=Count('organization__cities'))
|
|
for row in q:
|
|
code = row['organization__cities']
|
|
if not code:
|
|
continue
|
|
compartment = COMPARTMENTS[code]
|
|
if compartment in results:
|
|
nums = results[compartment]
|
|
nums.append(row['num_media'])
|
|
else:
|
|
results[compartment] = [row['num_media']]
|
|
|
|
q = Douyin.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
|
|
'organization__cities').annotate(num_media=Count('organization__cities'))
|
|
for row in q:
|
|
code = row['organization__cities']
|
|
if not code:
|
|
continue
|
|
compartment = COMPARTMENTS[code]
|
|
if compartment in results:
|
|
nums = results[compartment]
|
|
nums.append(row['num_media'])
|
|
else:
|
|
results[compartment] = [row['num_media']]
|
|
|
|
q = Qita.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
|
|
'organization__cities').annotate(num_media=Count('organization__cities'))
|
|
for row in q:
|
|
code = row['organization__cities']
|
|
if not code:
|
|
continue
|
|
compartment = COMPARTMENTS[code]
|
|
if compartment in results:
|
|
nums = results[compartment]
|
|
nums.append(row['num_media'])
|
|
else:
|
|
results[compartment] = [row['num_media']]
|
|
|
|
chart2_data = []
|
|
for k in results:
|
|
chart2_data.append({'name': k, 'value': sum(results[k])})
|
|
|
|
total1 = NewMedia.category_one_count()
|
|
total2 = NewMedia.category_two_count()
|
|
total3 = NewMedia.category_three_count()
|
|
chart3_data = []
|
|
chart3_data.append({'name': '省直各部门', 'value': total1})
|
|
chart3_data.append({'name': '市州政府及部门', 'value': total2})
|
|
chart3_data.append({'name': '县区政府及部门、乡镇', 'value': total3})
|
|
return render(request, 'polls/monitor_statistics.html', {'chart1_data': chart1_data, 'total': total, 'chart2_data': chart2_data, 'chart3_data': chart3_data, 'user_total': user_total, 'chart4_data': chart4_data})
|
|
|
|
|
|
@csrf_exempt
|
|
def media_statistics(request):
|
|
return render(request, 'polls/media_statistics.html')
|
|
|
|
|
|
@csrf_exempt
|
|
def city_ranking(request):
|
|
return render(request, 'polls/city_ranking.html')
|
|
|
|
|
|
def monitor_result(request):
|
|
return render(request, 'polls/monitor_result.html')
|
|
|
|
|
|
def monitor_unqualified_result(request):
|
|
if request.method == 'POST':
|
|
return HttpResponse(status=405)
|
|
province = request.GET.get('province','')
|
|
cities = request.GET.get('cities','')
|
|
district = request.GET.get('district','')
|
|
version = request.GET.get('version', '0')
|
|
level = request.GET.get('level', '0')
|
|
q = UnqualifiedMedia.objects.filter(version=version)
|
|
if province:
|
|
q = q.filter(province=province)
|
|
if cities:
|
|
q = q.filter(cities=cities)
|
|
if district:
|
|
q = q.filter(district=district)
|
|
|
|
return render(request, 'polls/monitor_unqualified_result.html', {'medias': q, 'level': level, 'province': province, 'cities': cities, 'district': district, 'compartments': COMPARTMENTS})
|