newmediamonitoring/polls/views/monitor.py

135 lines
4.8 KiB
Python
Raw Normal View History

2020-09-12 07:31:50 +00:00
from django.shortcuts import render
2020-10-09 12:09:15 +00:00
from django.views.decorators.csrf import csrf_exempt
2020-09-22 03:48:12 +00:00
from dashboard.models import Douyin, NewMedia, Qita, Toutiao, Weibo, Weixin
from django.db.models import Count, Sum
COMPARTMENTS = {
'620100000000': '兰州市',
'620200000000': '嘉峪关市',
'620300000000': '金昌市',
'620400000000': '白银市',
'620500000000': '天水市',
'620600000000': '武威市',
'620700000000': '张掖市',
'620800000000': '平凉市',
'620900000000': '酒泉市',
'621000000000': '庆阳市',
'621100000000': '定西市',
'621200000000': '陇南市',
'622900000000': '临夏回族自治州',
'623000000000': '甘南藏族自治州',
2020-09-26 04:27:19 +00:00
'620171000000': '兰州新区',
'': '未知',
2020-09-22 03:48:12 +00:00
}
2020-09-20 11:14:54 +00:00
2020-09-12 07:31:50 +00:00
2020-10-09 12:09:15 +00:00
@csrf_exempt
2020-09-12 07:31:50 +00:00
def monitor_statistics(request):
2020-10-22 04:05:23 +00:00
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()
2020-09-22 03:48:12 +00:00
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()
2020-10-22 04:05:23 +00:00
q = Weixin.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
2020-09-22 03:48:12 +00:00
'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q:
code = row['organization__cities']
2020-10-22 04:05:23 +00:00
if not code:
continue
2020-09-22 03:48:12 +00:00
compartment = COMPARTMENTS[code]
if code in results:
nums = results[compartment]
nums.append(row['num_media'])
else:
results[compartment] = [row['num_media']]
2020-10-22 04:05:23 +00:00
q = Weibo.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
2020-09-22 03:48:12 +00:00
'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q:
code = row['organization__cities']
2020-10-22 04:05:23 +00:00
if not code:
continue
2020-09-22 03:48:12 +00:00
compartment = COMPARTMENTS[code]
if compartment in results:
nums = results[compartment]
nums.append(row['num_media'])
else:
results[compartment] = [row['num_media']]
2020-10-22 04:05:23 +00:00
q = Toutiao.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
2020-09-22 03:48:12 +00:00
'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q:
code = row['organization__cities']
2020-10-22 04:05:23 +00:00
if not code:
continue
2020-09-22 03:48:12 +00:00
compartment = COMPARTMENTS[code]
if compartment in results:
nums = results[compartment]
nums.append(row['num_media'])
else:
results[compartment] = [row['num_media']]
2020-10-22 04:05:23 +00:00
q = Douyin.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
2020-09-22 03:48:12 +00:00
'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q:
code = row['organization__cities']
2020-10-22 04:05:23 +00:00
if not code:
continue
2020-09-22 03:48:12 +00:00
compartment = COMPARTMENTS[code]
if compartment in results:
nums = results[compartment]
nums.append(row['num_media'])
else:
results[compartment] = [row['num_media']]
2020-10-22 04:05:23 +00:00
q = Qita.objects.exclude(organization__cities='', status=0).values('organization__cities').order_by(
2020-09-22 03:48:12 +00:00
'organization__cities').annotate(num_media=Count('organization__cities'))
for row in q:
code = row['organization__cities']
2020-10-22 04:05:23 +00:00
if not code:
continue
2020-09-22 03:48:12 +00:00
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()
2020-10-04 15:09:07 +00:00
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})
2020-09-26 10:22:59 +00:00
2020-10-09 12:09:15 +00:00
@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')
2020-09-26 10:22:59 +00:00
def monitor_result(request):
2020-10-09 12:09:15 +00:00
return render(request, 'polls/monitor_result.html')