newmediamonitoring/polls/views/monitor.py

113 lines
4.4 KiB
Python
Raw Normal View History

2020-09-12 07:31:50 +00:00
from django.shortcuts import render
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
def monitor_statistics(request):
2020-09-20 11:14:54 +00:00
wbc = Weibo.objects.count()
wxc = Weixin.objects.count()
ttc = Toutiao.objects.count()
qtc = Qita.objects.count()
dyc = Douyin.objects.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-09-26 04:27:19 +00:00
q = Weixin.objects.exclude(organization__cities='').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:
2020-09-26 04:27:19 +00:00
print(row)
2020-09-22 03:48:12 +00:00
code = row['organization__cities']
2020-09-26 01:47:24 +00:00
print(code)
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-09-26 04:27:19 +00:00
q = Weibo.objects.exclude(organization__province='', organization__cities='').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']
compartment = COMPARTMENTS[code]
if compartment in results:
nums = results[compartment]
nums.append(row['num_media'])
else:
results[compartment] = [row['num_media']]
2020-09-26 04:27:19 +00:00
q = Toutiao.objects.exclude(organization__province='', organization__cities='').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']
compartment = COMPARTMENTS[code]
if compartment in results:
nums = results[compartment]
nums.append(row['num_media'])
else:
results[compartment] = [row['num_media']]
2020-09-26 04:27:19 +00:00
q = Douyin.objects.exclude(organization__province='', organization__cities='').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']
compartment = COMPARTMENTS[code]
if compartment in results:
nums = results[compartment]
nums.append(row['num_media'])
else:
results[compartment] = [row['num_media']]
2020-09-26 04:27:19 +00:00
q = Qita.objects.exclude(organization__province='', organization__cities='').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']
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
def monitor_result(request):
return render(request, 'polls/monitor_result.html')