newmediamonitoring/monitor/views.py

1185 lines
66 KiB
Python
Raw Normal View History

2020-10-09 01:42:05 +00:00
import csv
2020-10-23 04:04:33 +00:00
import datetime
2020-10-09 01:42:05 +00:00
import json
from collections import Counter
import jieba
2020-11-03 10:07:53 +00:00
from django.contrib.auth.decorators import login_required
2020-10-28 15:31:17 +00:00
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
2020-10-23 04:04:33 +00:00
from django.db.models import Sum
2020-10-30 11:36:22 +00:00
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
2020-11-20 10:41:18 +00:00
from datetime import timedelta,date
# Create your views here.
2020-11-03 06:51:47 +00:00
from django.views.decorators.csrf import csrf_exempt
2020-09-29 02:48:26 +00:00
from dashboard.models import Weixin, Weixin_data, Toutiao_data, Weibo_data, Qita_jc, Group, Toutiao, Weibo, Qita, \
2020-11-18 07:48:17 +00:00
Douyin, Douyin_data, News, TimelinessMonitoring, Organization, Wrongly, NewMedia, Comment
2020-10-09 01:42:05 +00:00
from monitor.models import Test
2020-11-11 01:47:43 +00:00
2020-11-04 03:52:36 +00:00
import pandas as pd
2020-11-03 10:07:53 +00:00
@login_required
def new_media_public_opinion_weixin(request):
weixin = Weixin.objects.all()
group = Group.objects.all()
2020-09-29 02:48:26 +00:00
weixin_data = Weixin_data.objects.all().order_by('-comment')
res = []
for w in weixin_data:
o = dict()
o['id'] = str(w.id)
o['code'] = w.weixin.code
o['title'] = w.title
o['comment'] = w.comment
o['reply'] = w.reply
o['year'] = w.year
o['month'] = w.month
o['day'] = w.day
res.append(o)
2020-10-19 08:52:51 +00:00
return render(request, 'monitor/new-media-public-opinion-weixin.html',
{'res': res, 'weixin': weixin, 'group': group})
2020-11-03 10:07:53 +00:00
@login_required
def new_media_public_opinion_toutiao(request):
toutiao = Toutiao.objects.all()
group = Group.objects.all()
2020-09-29 02:48:26 +00:00
toutiao_data = Toutiao_data.objects.all().order_by('-count')
res = []
for t in toutiao_data:
o = dict()
o['id'] = str(t.id)
o['code'] = t.toutiao.code
o['image'] = t.toutiao.image
o['title'] = t.title
o['count'] = t.count
o['commentcount'] = t.commentcount
o['reply'] = t.reply
o['year'] = t.year
o['month'] = t.month
o['day'] = t.day
res.append(o)
2020-10-19 08:52:51 +00:00
return render(request, 'monitor/new-media-public-opinion-toutiao.html',
{'res': res, 'toutiao': toutiao, 'group': group})
2020-11-03 10:07:53 +00:00
@login_required
2020-09-29 02:48:26 +00:00
def new_media_public_opinion_douyin(request):
douyin = Douyin.objects.all()
group = Group.objects.all()
douyin_data = Douyin_data.objects.all().order_by('-comment')
res = []
for d in douyin_data:
o = dict()
o['id'] = str(d.id)
o['code'] = d.newmedia.code
o['image'] = d.newmedia.image
o['count'] = d.count
o['count_jc'] = d.count_jc
o['comment'] = d.comment
o['reply'] = d.reply
o['date'] = d.date
res.append(o)
2020-10-19 08:52:51 +00:00
return render(request, 'monitor/new-media-public-opinion-douyin.html',
{'res': res, 'douyin': douyin, 'group': group})
2020-11-03 10:07:53 +00:00
@login_required
def new_media_public_opinion_weibo(request):
weibo = Weibo.objects.all()
group = Group.objects.all()
2020-09-29 02:48:26 +00:00
weibo_data = Weibo_data.objects.all().order_by('-like')
res = []
for w in weibo_data:
o = dict()
o['id'] = str(w.id)
o['code'] = w.weibo.code
o['image'] = w.weibo.image
o['title'] = w.title
o['like'] = w.like
o['transpond'] = w.transpond
o['comment'] = w.comment
o['year'] = w.year
o['month'] = w.month
o['day'] = w.day
res.append(o)
2020-10-19 08:52:51 +00:00
return render(request, 'monitor/new-media-public-opinion-weibo.html', {'res': res, 'weibo': weibo, 'group': group})
2020-11-03 10:07:53 +00:00
@login_required
def new_media_public_opinion_qita(request):
qita = Qita.objects.all()
group = Group.objects.all()
2020-09-29 02:48:26 +00:00
qita_jc = Qita_jc.objects.all().order_by('-comment')
res = []
for q in qita_jc:
o = dict()
o['id'] = str(q.id)
o['type'] = q.qita.type
o['name'] = q.qita.name
o['image'] = q.qita.image
o['count'] = q.count
o['count_jc'] = q.count_jc
o['comment'] = q.comment
o['reply'] = q.reply
o['year'] = q.year
o['month'] = q.month
o['day'] = q.day
res.append(o)
2020-10-19 08:52:51 +00:00
return render(request, 'monitor/new-media-public-opinion-qita.html', {'res': res, 'qita': qita, 'group': group})
2020-11-03 10:07:53 +00:00
@login_required
2020-10-28 15:31:17 +00:00
def timeliness_monitoring_weixin(request):
2020-10-23 04:04:33 +00:00
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
2020-12-05 16:39:07 +00:00
if now.month == 12:
this_month_end = datetime.datetime(now.year, now.month , 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
else:
this_month_end = datetime.datetime(now.year, now.month, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
2020-10-28 15:31:17 +00:00
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
2020-10-23 04:04:33 +00:00
2020-10-28 15:31:17 +00:00
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
timelinessmonitoring = TimelinessMonitoring.objects.filter(n_type='微信').order_by('n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-weixin.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
2020-11-03 10:07:53 +00:00
@login_required
2020-10-28 15:31:17 +00:00
def timeliness_monitoring_weibo(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
timelinessmonitoring = TimelinessMonitoring.objects.filter(n_type='微博').order_by('n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-weibo.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
2020-11-03 10:07:53 +00:00
@login_required
2020-10-28 15:31:17 +00:00
def timeliness_monitoring_toutiao(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
2020-10-23 04:04:33 +00:00
2020-10-28 15:31:17 +00:00
timelinessmonitoring = TimelinessMonitoring.objects.filter(n_type='今日头条').order_by('n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-toutiao.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
2020-11-03 10:07:53 +00:00
@login_required
2020-10-28 15:31:17 +00:00
def timeliness_monitoring_douyin(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
2020-10-23 04:04:33 +00:00
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
2020-10-28 15:31:17 +00:00
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
timelinessmonitoring = TimelinessMonitoring.objects.filter(n_type__contains='抖音').order_by('n_name')
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
2020-10-23 04:04:33 +00:00
2020-10-28 15:31:17 +00:00
return render(request, 'monitor/timeliness-monitoring-douyin.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
2020-11-03 10:07:53 +00:00
@login_required
2020-10-28 15:31:17 +00:00
def timeliness_monitoring_qita(request):
now = datetime.datetime.now()
# 本周第一天和最后一天
this_week_start = now - timedelta(days=now.weekday())
this_week_end = now + timedelta(days=6 - now.weekday())
# 本月第一天和最后一天
this_month_start = datetime.datetime(now.year, now.month, 1)
this_month_end = datetime.datetime(now.year, now.month + 1, 1) - timedelta(days=1) + datetime.timedelta(
hours=23, minutes=59, seconds=59)
# 新媒体数量
new_media_count = int(Weixin.objects.all().count()) + int(Weibo.objects.all().count()) + int(
Toutiao.objects.all().count()) + int(Douyin.objects.all().count()) + int(Qita.objects.all().count())
new_media_count_month = int(Weixin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Weibo.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Douyin.objects.filter(created__range=(this_month_start, this_month_end)).count()) + int(
Qita.objects.filter(created__range=(this_month_start, this_month_end)).count())
new_media_count_week = int(Weixin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Weibo.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Toutiao.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Douyin.objects.filter(created__range=(this_week_start, this_week_end)).count()) + int(
Qita.objects.filter(created__range=(this_week_start, this_week_end)).count())
# 内容更新次数
update_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('update'))['nums']
# update_count_month = TimelinessMonitoring.objects.filter(created__range=(this_month_start,this_month_end)).aggregate(nums=Sum('update'))['nums']
# update_count_week = TimelinessMonitoring.objects.filter(created__range=(this_week_start,this_week_end)).aggregate(nums=Sum('update'))['nums']
comment_count = TimelinessMonitoring.objects.all().aggregate(nums=Sum('comment'))['nums']
wrongly_count = Wrongly.objects.all().count
sensitive_count = None
organization_count = Organization.objects.all().count()
organization_count_month = Organization.objects.filter(created__range=(this_month_start, this_month_end)).count()
organization_count_week = Organization.objects.filter(created__range=(this_week_start, this_week_end)).count()
2020-10-29 07:19:15 +00:00
timelinessmonitoring = TimelinessMonitoring.objects.exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).order_by(
'n_name')
2020-10-28 15:31:17 +00:00
res = []
if timelinessmonitoring is not None:
paginator = Paginator(timelinessmonitoring, 6)
page = int(request.GET.get('page', 1))
try:
timelinessmonitoring = paginator.page(page)
except PageNotAnInteger:
timelinessmonitoring = paginator.page(1)
except EmptyPage:
timelinessmonitoring = paginator.page(paginator.num_pages)
for t in timelinessmonitoring:
o = dict()
o['n_type'] = t.n_type
o['count'] = TimelinessMonitoring.objects.filter(n_name=t.n_name).aggregate(nums=Sum('update'))['nums']
o['n_name'] = t.n_name
o['o_type'] = t.o_type
o['o_name'] = t.o_name
o['city'] = t.city
o['counties'] = t.counties
o['remark'] = t.remark
o['results'] = t.results
o['update'] = t.update
o['silet'] = t.silet
o['start_data'] = t.start_data
o['end_data'] = t.end_data
o['comment'] = t.comment
o['date'] = t.date
o['wrongly'] = Wrongly.objects.filter(n_name=t.n_name).count()
res.append(o)
return render(request, 'monitor/timeliness-monitoring-qita.html',
{'new_media_count': new_media_count, 'new_media_count_month': new_media_count_month,
'new_media_count_week': new_media_count_week, 'wrongly_count': wrongly_count,
'organization_count': organization_count, 'update_count': update_count,
'comment_count': comment_count, 'organization_count_month': organization_count_month,
'organization_count_week': organization_count_week, 'res': res,
'timelinessmonitoring': timelinessmonitoring})
2020-10-19 08:52:51 +00:00
2020-11-03 10:07:53 +00:00
@login_required
2020-09-30 12:29:10 +00:00
def error_monitoring(request):
2020-10-29 07:19:15 +00:00
wrongly = Wrongly.objects.all()
paginator = Paginator(wrongly, 8)
page = int(request.GET.get('page', 1))
try:
wrongly = paginator.page(page)
except PageNotAnInteger:
wrongly = paginator.page(1)
except EmptyPage:
wrongly = paginator.page(paginator.num_pages)
return render(request, 'monitor/error-monitoring.html',{'wrongly':wrongly})
2020-10-19 08:52:51 +00:00
2020-11-03 10:07:53 +00:00
@login_required
2020-09-30 12:29:10 +00:00
def sensitive_word_monitoring(request):
2020-10-29 07:19:15 +00:00
data = range(1,8)
return render(request, 'monitor/sensitive-word-monitoring.html',{'data':data})
2020-10-19 08:52:51 +00:00
2020-11-03 10:07:53 +00:00
@login_required
2020-09-30 12:29:10 +00:00
def comment_on_interactive_monitoring(request):
2020-11-18 07:48:17 +00:00
comment = Comment.objects.all().order_by('-date')
paginator = Paginator(comment, 8)
page = int(request.GET.get('page', 1))
try:
comment = paginator.page(page)
except PageNotAnInteger:
comment = paginator.page(1)
except EmptyPage:
comment = paginator.page(paginator.num_pages)
return render(request, 'monitor/comment-on-interactive-monitoring.html',{"comment":comment})
2020-10-19 08:52:51 +00:00
2020-11-03 10:07:53 +00:00
@login_required
2020-10-09 01:42:05 +00:00
def comment_on_interactive_monitoring_json(request):
2020-11-18 07:48:17 +00:00
data = Comment.objects.all()
2020-10-09 01:42:05 +00:00
r = []
for d in data:
2020-11-18 07:48:17 +00:00
content = d.comment
2020-10-09 01:42:05 +00:00
r.append(content)
# result = jieba.analyse.textrank(content, topK=400, withWeight=True)
seg_list = jieba.cut(str(r)) # 对文本进行分词
c = Counter()
for x in seg_list: # 进行词频统计
if len(x) > 1 and x != '\r\n':
c[x] += 1
res = []
2020-11-18 07:48:17 +00:00
for (k, v) in c.most_common(250): # 遍历输出高频词
2020-10-19 03:41:23 +00:00
# print('%s%s %s %d' % (' ' * (5 - len(k)), k, '*', v))
2020-10-19 08:52:51 +00:00
# 剔除不是汉字的值
if all(map(lambda c: '\u4e00' <= c <= '\u9fa5', k)):
2020-10-19 03:41:23 +00:00
o = dict()
o['name'] = k
o['value'] = v
res.append(o)
2020-10-09 01:42:05 +00:00
return HttpResponse(json.dumps({
2020-10-19 08:52:51 +00:00
"res": res
2020-10-09 01:42:05 +00:00
}))
2020-10-19 08:52:51 +00:00
2020-11-03 10:07:53 +00:00
@login_required
2020-09-30 12:29:10 +00:00
def monitoring_report(request):
2020-10-19 08:52:51 +00:00
news = News.objects.filter(type='3').order_by('-date')
count = News.objects.filter(type='3').count()
2020-10-30 11:36:22 +00:00
2020-10-28 15:31:17 +00:00
return render(request, 'monitor/monitoring-report.html', {'news': news, 'count': count})
2020-11-03 10:07:53 +00:00
@login_required
2020-10-30 11:36:22 +00:00
def monitoring_report_json(request):
news = News.objects.filter(type='3').order_by('date')
# year_now = datetime.datetime.now().year
# year = range(2019, int(year_now) + 1)
# month = range(1, 13)
news_list = []
for n in news:
o = dict()
# o['date'] = n.date
o['count'] = 1
o['year'] = str(n.date).split('-')[0]
o['month'] = str(n.date).split('-')[1]
news_list.append(o)
return JsonResponse(news_list,safe=False)
2020-10-09 01:42:05 +00:00
def test(request):
2020-10-19 08:52:51 +00:00
return render(request, 'monitor/test.html')
2020-11-03 10:07:53 +00:00
@login_required
2020-10-09 01:42:05 +00:00
def test_json(request):
res = []
2020-10-19 08:52:51 +00:00
with open('D:/2020/舆论监测平台/新媒体监测数据/平凉/Result_PL.csv', encoding='utf-8') as csvfile:
2020-10-09 01:42:05 +00:00
reader = csv.reader(csvfile)
results = []
try:
for r in reader:
print(r[0])
results.append(r[5])
except:
print("777777777777777777777777777777777777777777777777")
seg_list = jieba.cut(str(results)) # 对文本进行分词
c = Counter()
for x in seg_list: # 进行词频统计
if len(x) > 1 and x != '\r\n':
c[x] += 1
for (k, v) in c.most_common(200): # 遍历输出高频词
2020-10-19 08:52:51 +00:00
if all(map(lambda c: '\u4e00' <= c <= '\u9fa5', k)):
2020-10-19 06:43:13 +00:00
o = dict()
o['name'] = k
o['value'] = v
res.append(o)
2020-10-09 01:42:05 +00:00
return HttpResponse(json.dumps({
"res": res
}))
2020-10-29 07:19:15 +00:00
2020-11-03 10:07:53 +00:00
@login_required
2020-10-29 07:19:15 +00:00
def timeliness_monitoring_json(request):
2020-11-02 13:51:05 +00:00
# timelinessmonitoring_lanzhou_weixin = \
# TimelinessMonitoring.objects.filter(city='兰州市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_lanzhou_weibo = \
# TimelinessMonitoring.objects.filter(city='兰州市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_lanzhou_toutiao = \
# TimelinessMonitoring.objects.filter(city='兰州市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_lanzhou_douyin = \
# TimelinessMonitoring.objects.filter(city='兰州市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_lanzhou_qita = \
# TimelinessMonitoring.objects.filter(city='兰州市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_jiayuguan_weixin = \
# TimelinessMonitoring.objects.filter(city__contains='嘉峪关', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jiayuguan_weibo = \
# TimelinessMonitoring.objects.filter(city__contains='嘉峪关', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jiayuguan_toutiao = \
# TimelinessMonitoring.objects.filter(city__contains='嘉峪关', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jiayuguan_douyin = \
# TimelinessMonitoring.objects.filter(city__contains='嘉峪关', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jiayuguan_qita = \
# TimelinessMonitoring.objects.filter(city__contains='嘉峪关').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_jinchang_weixin = \
# TimelinessMonitoring.objects.filter(city='金昌市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jinchang_weibo = \
# TimelinessMonitoring.objects.filter(city='金昌市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jinchang_toutiao = \
# TimelinessMonitoring.objects.filter(city='金昌市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jinchang_douyin = \
# TimelinessMonitoring.objects.filter(city='金昌市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jinchang_qita = \
# TimelinessMonitoring.objects.filter(city='金昌市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_jiuquan_weixin = \
# TimelinessMonitoring.objects.filter(city='酒泉市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jiuquan_weibo = \
# TimelinessMonitoring.objects.filter(city='酒泉市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jiuquan_toutiao = \
# TimelinessMonitoring.objects.filter(city='酒泉市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jiuquan_douyin = \
# TimelinessMonitoring.objects.filter(city='酒泉市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_jiuquan_qita = \
# TimelinessMonitoring.objects.filter(city='酒泉市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_zhangye_weixin = \
# TimelinessMonitoring.objects.filter(city='张掖市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_zhangye_weibo = \
# TimelinessMonitoring.objects.filter(city='张掖市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_zhangye_toutiao = \
# TimelinessMonitoring.objects.filter(city='张掖市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_zhangye_douyin = \
# TimelinessMonitoring.objects.filter(city='张掖市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_zhangye_qita = \
# TimelinessMonitoring.objects.filter(city='张掖市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_wuwei_weixin = \
# TimelinessMonitoring.objects.filter(city='武威市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_wuwei_weibo = \
# TimelinessMonitoring.objects.filter(city='武威市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_wuwei_toutiao = \
# TimelinessMonitoring.objects.filter(city='武威市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_wuwei_douyin = \
# TimelinessMonitoring.objects.filter(city='武威市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_wuwei_qita = \
# TimelinessMonitoring.objects.filter(city='武威市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_baiyin_weixin = \
# TimelinessMonitoring.objects.filter(city='白银市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_baiyin_weibo = \
# TimelinessMonitoring.objects.filter(city='白银市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_baiyin_toutiao = \
# TimelinessMonitoring.objects.filter(city='白银市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_baiyin_douyin = \
# TimelinessMonitoring.objects.filter(city='白银市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_baiyin_qita = \
# TimelinessMonitoring.objects.filter(city='白银市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_tianshui_weixin = \
# TimelinessMonitoring.objects.filter(city='天水市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_tianshui_weibo = \
# TimelinessMonitoring.objects.filter(city='天水市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_tianshui_toutiao = \
# TimelinessMonitoring.objects.filter(city='天水市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_tianshui_douyin = \
# TimelinessMonitoring.objects.filter(city='天水市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_tianshui_qita = \
# TimelinessMonitoring.objects.filter(city='天水市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_pingliang_weixin = \
# TimelinessMonitoring.objects.filter(city='平凉市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_pingliang_weibo = \
# TimelinessMonitoring.objects.filter(city='平凉市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_pingliang_toutiao = \
# TimelinessMonitoring.objects.filter(city='平凉市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_pingliang_douyin = \
# TimelinessMonitoring.objects.filter(city='平凉市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_pingliang_qita = \
# TimelinessMonitoring.objects.filter(city='平凉市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_qingyang_weixin = \
# TimelinessMonitoring.objects.filter(city='庆阳市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_qingyang_weibo = \
# TimelinessMonitoring.objects.filter(city='庆阳市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_qingyang_toutiao = \
# TimelinessMonitoring.objects.filter(city='庆阳市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_qingyang_douyin = \
# TimelinessMonitoring.objects.filter(city='庆阳市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_qingyang_qita = \
# TimelinessMonitoring.objects.filter(city='庆阳市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_dingxi_weixin = \
# TimelinessMonitoring.objects.filter(city='定西市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_dingxi_weibo = \
# TimelinessMonitoring.objects.filter(city='定西市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_dingxi_toutiao = \
# TimelinessMonitoring.objects.filter(city='定西市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_dingxi_douyin = \
# TimelinessMonitoring.objects.filter(city='定西市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_dingxi_qita = \
# TimelinessMonitoring.objects.filter(city='定西市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_longnan_weixin = \
# TimelinessMonitoring.objects.filter(city='陇南市', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_longnan_weibo = \
# TimelinessMonitoring.objects.filter(city='陇南市', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_longnan_toutiao = \
# TimelinessMonitoring.objects.filter(city='陇南市', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_longnan_douyin = \
# TimelinessMonitoring.objects.filter(city='陇南市', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_longnan_qita = \
# TimelinessMonitoring.objects.filter(city='陇南市').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_gannan_weixin = \
# TimelinessMonitoring.objects.filter(city__contains='甘南', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_gannan_weibo = \
# TimelinessMonitoring.objects.filter(city__contains='甘南', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_gannan_toutiao = \
# TimelinessMonitoring.objects.filter(city__contains='甘南', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_gannan_douyin = \
# TimelinessMonitoring.objects.filter(city__contains='甘南', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_gannan_qita = \
# TimelinessMonitoring.objects.filter(city__contains='甘南').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
#
# timelinessmonitoring_linxia_weixin = \
# TimelinessMonitoring.objects.filter(city__contains='临夏', n_type='微信').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_linxia_weibo = \
# TimelinessMonitoring.objects.filter(city__contains='临夏', n_type='微博').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_linxia_toutiao = \
# TimelinessMonitoring.objects.filter(city__contains='临夏', n_type='今日头条').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_linxia_douyin = \
# TimelinessMonitoring.objects.filter(city__contains='临夏', n_type='抖音').aggregate(nums=Sum('update'))['nums']
# timelinessmonitoring_linxia_qita = \
# TimelinessMonitoring.objects.filter(city__contains='临夏').exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
# nums=Sum('update'))['nums']
# weixin = [timelinessmonitoring_lanzhou_weixin,timelinessmonitoring_jiayuguan_weixin,timelinessmonitoring_jinchang_weixin,timelinessmonitoring_jiuquan_weixin,timelinessmonitoring_zhangye_weixin,timelinessmonitoring_wuwei_weixin,timelinessmonitoring_baiyin_weixin,timelinessmonitoring_tianshui_weixin,timelinessmonitoring_pingliang_weixin,timelinessmonitoring_qingyang_weixin,timelinessmonitoring_dingxi_weixin,timelinessmonitoring_longnan_weixin,timelinessmonitoring_gannan_weixin,timelinessmonitoring_linxia_weixin]
# weibo = [timelinessmonitoring_lanzhou_weibo,timelinessmonitoring_jiayuguan_weibo,timelinessmonitoring_jinchang_weibo,timelinessmonitoring_jiuquan_weibo,timelinessmonitoring_zhangye_weibo,timelinessmonitoring_wuwei_weibo,timelinessmonitoring_baiyin_weibo,timelinessmonitoring_tianshui_weibo,timelinessmonitoring_pingliang_weibo,timelinessmonitoring_qingyang_weibo,timelinessmonitoring_dingxi_weibo,timelinessmonitoring_longnan_weibo,timelinessmonitoring_gannan_weibo,timelinessmonitoring_linxia_weibo]
# toutiao = [timelinessmonitoring_lanzhou_toutiao,timelinessmonitoring_jiayuguan_toutiao,timelinessmonitoring_jinchang_toutiao,timelinessmonitoring_jiuquan_toutiao,timelinessmonitoring_zhangye_toutiao,timelinessmonitoring_wuwei_toutiao,timelinessmonitoring_baiyin_toutiao,timelinessmonitoring_tianshui_toutiao,timelinessmonitoring_pingliang_toutiao,timelinessmonitoring_qingyang_toutiao,timelinessmonitoring_dingxi_toutiao,timelinessmonitoring_longnan_toutiao,timelinessmonitoring_gannan_toutiao,timelinessmonitoring_linxia_toutiao]
# douyin = [timelinessmonitoring_lanzhou_douyin,timelinessmonitoring_jiayuguan_douyin,timelinessmonitoring_jinchang_douyin,timelinessmonitoring_jiuquan_douyin,timelinessmonitoring_zhangye_douyin,timelinessmonitoring_wuwei_douyin,timelinessmonitoring_baiyin_douyin,timelinessmonitoring_tianshui_douyin,timelinessmonitoring_pingliang_douyin,timelinessmonitoring_qingyang_douyin,timelinessmonitoring_dingxi_douyin,timelinessmonitoring_longnan_douyin,timelinessmonitoring_gannan_douyin,timelinessmonitoring_linxia_douyin]
# qita = [timelinessmonitoring_lanzhou_qita,timelinessmonitoring_jiayuguan_qita,timelinessmonitoring_jinchang_qita,timelinessmonitoring_jiuquan_qita,timelinessmonitoring_zhangye_qita,timelinessmonitoring_wuwei_qita,timelinessmonitoring_baiyin_qita,timelinessmonitoring_tianshui_qita,timelinessmonitoring_pingliang_qita,timelinessmonitoring_qingyang_qita,timelinessmonitoring_dingxi_qita,timelinessmonitoring_longnan_qita,timelinessmonitoring_gannan_qita,timelinessmonitoring_linxia_qita]
# print(weixin)
# print(weibo)
# print(toutiao)
# print(douyin)
# print(qita)
date = TimelinessMonitoring.objects.distinct('date')
date_list = []
lanzhou = []
jiayuguan = []
jinchang = []
jiuquan = []
zhangye = []
wuwei = []
baiyin = []
tianshui = []
pingliang = []
qingyang = []
dingxi = []
longnan = []
gannan = []
linxia = []
for d in date:
date_list.append(d.date)
lanzhou.append(TimelinessMonitoring.objects.filter(city__contains='兰州',date=d.date).aggregate(nums=Sum('update'))['nums'])
jiayuguan.append(TimelinessMonitoring.objects.filter(city__contains='嘉峪关',date=d.date).aggregate(nums=Sum('update'))['nums'])
jinchang.append(TimelinessMonitoring.objects.filter(city__contains='金昌',date=d.date).aggregate(nums=Sum('update'))['nums'])
jiuquan.append(TimelinessMonitoring.objects.filter(city__contains='酒泉',date=d.date).aggregate(nums=Sum('update'))['nums'])
zhangye.append(TimelinessMonitoring.objects.filter(city__contains='张掖',date=d.date).aggregate(nums=Sum('update'))['nums'])
wuwei.append(TimelinessMonitoring.objects.filter(city__contains='武威',date=d.date).aggregate(nums=Sum('update'))['nums'])
baiyin.append(TimelinessMonitoring.objects.filter(city__contains='白银',date=d.date).aggregate(nums=Sum('update'))['nums'])
tianshui.append(TimelinessMonitoring.objects.filter(city__contains='天水',date=d.date).aggregate(nums=Sum('update'))['nums'])
pingliang.append(TimelinessMonitoring.objects.filter(city__contains='平凉',date=d.date).aggregate(nums=Sum('update'))['nums'])
qingyang.append(TimelinessMonitoring.objects.filter(city__contains='庆阳',date=d.date).aggregate(nums=Sum('update'))['nums'])
dingxi.append(TimelinessMonitoring.objects.filter(city__contains='定西',date=d.date).aggregate(nums=Sum('update'))['nums'])
longnan.append(TimelinessMonitoring.objects.filter(city__contains='陇南',date=d.date).aggregate(nums=Sum('update'))['nums'])
gannan.append(TimelinessMonitoring.objects.filter(city__contains='甘南',date=d.date).aggregate(nums=Sum('update'))['nums'])
linxia.append(TimelinessMonitoring.objects.filter(city__contains='临夏',date=d.date).aggregate(nums=Sum('update'))['nums'])
2020-10-29 07:19:15 +00:00
return HttpResponse(json.dumps({
"status":"1",
2020-11-02 13:51:05 +00:00
"lanzhou":lanzhou,
"jiayuguan":jiayuguan,
"jinchang":jinchang,
"jiuquan":jiuquan,
"zhangye":zhangye,
"wuwei":wuwei,
"baiyin":baiyin,
"tianshui":tianshui,
"pingliang":pingliang,
"qingyang":qingyang,
"dingxi":dingxi,
"longnan":longnan,
"gannan":gannan,
"linxia":linxia,
"date":date_list,
2020-10-30 11:36:22 +00:00
}))
2020-11-03 10:07:53 +00:00
@login_required
def timeliness_monitoring_json_weixin(request):
date = TimelinessMonitoring.objects.distinct('date')
date_list = []
lanzhou = []
jiayuguan = []
jinchang = []
jiuquan = []
zhangye = []
wuwei = []
baiyin = []
tianshui = []
pingliang = []
qingyang = []
dingxi = []
longnan = []
gannan = []
linxia = []
for d in date:
date_list.append(d.date)
lanzhou.append(TimelinessMonitoring.objects.filter(city__contains='兰州',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
jiayuguan.append(TimelinessMonitoring.objects.filter(city__contains='嘉峪关',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
jinchang.append(TimelinessMonitoring.objects.filter(city__contains='金昌',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
jiuquan.append(TimelinessMonitoring.objects.filter(city__contains='酒泉',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
zhangye.append(TimelinessMonitoring.objects.filter(city__contains='张掖',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
wuwei.append(TimelinessMonitoring.objects.filter(city__contains='武威',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
baiyin.append(TimelinessMonitoring.objects.filter(city__contains='白银',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
tianshui.append(TimelinessMonitoring.objects.filter(city__contains='天水',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
pingliang.append(TimelinessMonitoring.objects.filter(city__contains='平凉',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
qingyang.append(TimelinessMonitoring.objects.filter(city__contains='庆阳',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
dingxi.append(TimelinessMonitoring.objects.filter(city__contains='定西',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
longnan.append(TimelinessMonitoring.objects.filter(city__contains='陇南',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
gannan.append(TimelinessMonitoring.objects.filter(city__contains='甘南',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
linxia.append(TimelinessMonitoring.objects.filter(city__contains='临夏',date=d.date,n_type='微信').aggregate(nums=Sum('update'))['nums'])
return HttpResponse(json.dumps({
"status":"1",
"lanzhou":lanzhou,
"jiayuguan":jiayuguan,
"jinchang":jinchang,
"jiuquan":jiuquan,
"zhangye":zhangye,
"wuwei":wuwei,
"baiyin":baiyin,
"tianshui":tianshui,
"pingliang":pingliang,
"qingyang":qingyang,
"dingxi":dingxi,
"longnan":longnan,
"gannan":gannan,
"linxia":linxia,
"date":date_list,
}))
@login_required
def timeliness_monitoring_json_weibo(request):
date = TimelinessMonitoring.objects.distinct('date')
date_list = []
lanzhou = []
jiayuguan = []
jinchang = []
jiuquan = []
zhangye = []
wuwei = []
baiyin = []
tianshui = []
pingliang = []
qingyang = []
dingxi = []
longnan = []
gannan = []
linxia = []
for d in date:
date_list.append(d.date)
lanzhou.append(TimelinessMonitoring.objects.filter(city__contains='兰州',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
jiayuguan.append(TimelinessMonitoring.objects.filter(city__contains='嘉峪关',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
jinchang.append(TimelinessMonitoring.objects.filter(city__contains='金昌',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
jiuquan.append(TimelinessMonitoring.objects.filter(city__contains='酒泉',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
zhangye.append(TimelinessMonitoring.objects.filter(city__contains='张掖',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
wuwei.append(TimelinessMonitoring.objects.filter(city__contains='武威',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
baiyin.append(TimelinessMonitoring.objects.filter(city__contains='白银',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
tianshui.append(TimelinessMonitoring.objects.filter(city__contains='天水',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
pingliang.append(TimelinessMonitoring.objects.filter(city__contains='平凉',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
qingyang.append(TimelinessMonitoring.objects.filter(city__contains='庆阳',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
dingxi.append(TimelinessMonitoring.objects.filter(city__contains='定西',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
longnan.append(TimelinessMonitoring.objects.filter(city__contains='陇南',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
gannan.append(TimelinessMonitoring.objects.filter(city__contains='甘南',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
linxia.append(TimelinessMonitoring.objects.filter(city__contains='临夏',date=d.date,n_type='微博').aggregate(nums=Sum('update'))['nums'])
return HttpResponse(json.dumps({
"status":"1",
"lanzhou":lanzhou,
"jiayuguan":jiayuguan,
"jinchang":jinchang,
"jiuquan":jiuquan,
"zhangye":zhangye,
"wuwei":wuwei,
"baiyin":baiyin,
"tianshui":tianshui,
"pingliang":pingliang,
"qingyang":qingyang,
"dingxi":dingxi,
"longnan":longnan,
"gannan":gannan,
"linxia":linxia,
"date":date_list,
}))
@login_required
def timeliness_monitoring_json_toutiao(request):
date = TimelinessMonitoring.objects.distinct('date')
date_list = []
lanzhou = []
jiayuguan = []
jinchang = []
jiuquan = []
zhangye = []
wuwei = []
baiyin = []
tianshui = []
pingliang = []
qingyang = []
dingxi = []
longnan = []
gannan = []
linxia = []
for d in date:
date_list.append(d.date)
lanzhou.append(TimelinessMonitoring.objects.filter(city__contains='兰州',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
jiayuguan.append(TimelinessMonitoring.objects.filter(city__contains='嘉峪关',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
jinchang.append(TimelinessMonitoring.objects.filter(city__contains='金昌',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
jiuquan.append(TimelinessMonitoring.objects.filter(city__contains='酒泉',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
zhangye.append(TimelinessMonitoring.objects.filter(city__contains='张掖',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
wuwei.append(TimelinessMonitoring.objects.filter(city__contains='武威',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
baiyin.append(TimelinessMonitoring.objects.filter(city__contains='白银',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
tianshui.append(TimelinessMonitoring.objects.filter(city__contains='天水',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
pingliang.append(TimelinessMonitoring.objects.filter(city__contains='平凉',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
qingyang.append(TimelinessMonitoring.objects.filter(city__contains='庆阳',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
dingxi.append(TimelinessMonitoring.objects.filter(city__contains='定西',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
longnan.append(TimelinessMonitoring.objects.filter(city__contains='陇南',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
gannan.append(TimelinessMonitoring.objects.filter(city__contains='甘南',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
linxia.append(TimelinessMonitoring.objects.filter(city__contains='临夏',date=d.date,n_type__contains='头条').aggregate(nums=Sum('update'))['nums'])
return HttpResponse(json.dumps({
"status":"1",
"lanzhou":lanzhou,
"jiayuguan":jiayuguan,
"jinchang":jinchang,
"jiuquan":jiuquan,
"zhangye":zhangye,
"wuwei":wuwei,
"baiyin":baiyin,
"tianshui":tianshui,
"pingliang":pingliang,
"qingyang":qingyang,
"dingxi":dingxi,
"longnan":longnan,
"gannan":gannan,
"linxia":linxia,
"date":date_list,
}))
@login_required
def timeliness_monitoring_json_douyin(request):
date = TimelinessMonitoring.objects.distinct('date')
date_list = []
lanzhou = []
jiayuguan = []
jinchang = []
jiuquan = []
zhangye = []
wuwei = []
baiyin = []
tianshui = []
pingliang = []
qingyang = []
dingxi = []
longnan = []
gannan = []
linxia = []
for d in date:
date_list.append(d.date)
lanzhou.append(TimelinessMonitoring.objects.filter(city__contains='兰州',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
jiayuguan.append(TimelinessMonitoring.objects.filter(city__contains='嘉峪关',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
jinchang.append(TimelinessMonitoring.objects.filter(city__contains='金昌',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
jiuquan.append(TimelinessMonitoring.objects.filter(city__contains='酒泉',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
zhangye.append(TimelinessMonitoring.objects.filter(city__contains='张掖',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
wuwei.append(TimelinessMonitoring.objects.filter(city__contains='武威',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
baiyin.append(TimelinessMonitoring.objects.filter(city__contains='白银',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
tianshui.append(TimelinessMonitoring.objects.filter(city__contains='天水',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
pingliang.append(TimelinessMonitoring.objects.filter(city__contains='平凉',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
qingyang.append(TimelinessMonitoring.objects.filter(city__contains='庆阳',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
dingxi.append(TimelinessMonitoring.objects.filter(city__contains='定西',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
longnan.append(TimelinessMonitoring.objects.filter(city__contains='陇南',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
gannan.append(TimelinessMonitoring.objects.filter(city__contains='甘南',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
linxia.append(TimelinessMonitoring.objects.filter(city__contains='临夏',date=d.date,n_type__contains='抖音').aggregate(nums=Sum('update'))['nums'])
return HttpResponse(json.dumps({
"status":"1",
"lanzhou":lanzhou,
"jiayuguan":jiayuguan,
"jinchang":jinchang,
"jiuquan":jiuquan,
"zhangye":zhangye,
"wuwei":wuwei,
"baiyin":baiyin,
"tianshui":tianshui,
"pingliang":pingliang,
"qingyang":qingyang,
"dingxi":dingxi,
"longnan":longnan,
"gannan":gannan,
"linxia":linxia,
"date":date_list,
}))
@login_required
def timeliness_monitoring_json_qita(request):
date = TimelinessMonitoring.objects.distinct('date')
date_list = []
lanzhou = []
jiayuguan = []
jinchang = []
jiuquan = []
zhangye = []
wuwei = []
baiyin = []
tianshui = []
pingliang = []
qingyang = []
dingxi = []
longnan = []
gannan = []
linxia = []
for d in date:
date_list.append(d.date)
lanzhou.append(TimelinessMonitoring.objects.filter(city__contains='兰州',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
jiayuguan.append(TimelinessMonitoring.objects.filter(city__contains='嘉峪关',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
jinchang.append(TimelinessMonitoring.objects.filter(city__contains='金昌',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
jiuquan.append(TimelinessMonitoring.objects.filter(city__contains='酒泉',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
zhangye.append(TimelinessMonitoring.objects.filter(city__contains='张掖',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
wuwei.append(TimelinessMonitoring.objects.filter(city__contains='武威',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
baiyin.append(TimelinessMonitoring.objects.filter(city__contains='白银',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
tianshui.append(TimelinessMonitoring.objects.filter(city__contains='天水',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
pingliang.append(TimelinessMonitoring.objects.filter(city__contains='平凉',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
qingyang.append(TimelinessMonitoring.objects.filter(city__contains='庆阳',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
dingxi.append(TimelinessMonitoring.objects.filter(city__contains='定西',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
longnan.append(TimelinessMonitoring.objects.filter(city__contains='陇南',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
gannan.append(TimelinessMonitoring.objects.filter(city__contains='甘南',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
linxia.append(TimelinessMonitoring.objects.filter(city__contains='临夏',date=d.date).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(nums=Sum('update'))['nums'])
return HttpResponse(json.dumps({
"status":"1",
"lanzhou":lanzhou,
"jiayuguan":jiayuguan,
"jinchang":jinchang,
"jiuquan":jiuquan,
"zhangye":zhangye,
"wuwei":wuwei,
"baiyin":baiyin,
"tianshui":tianshui,
"pingliang":pingliang,
"qingyang":qingyang,
"dingxi":dingxi,
"longnan":longnan,
"gannan":gannan,
"linxia":linxia,
"date":date_list,
}))
@login_required
2020-11-03 06:51:47 +00:00
def index_map(request):
2020-11-20 10:41:18 +00:00
name = request.GET.get('name').split('')[0]
2020-11-03 06:51:47 +00:00
timelinessmonitoring_weixin = \
TimelinessMonitoring.objects.filter(city__contains=name, n_type='微信').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_weibo = \
TimelinessMonitoring.objects.filter(city__contains=name, n_type='微博').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_toutiao = \
TimelinessMonitoring.objects.filter(city__contains=name, n_type='今日头条').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_douyin = \
TimelinessMonitoring.objects.filter(city__contains=name, n_type='抖音').aggregate(nums=Sum('update'))['nums']
timelinessmonitoring_qita = \
TimelinessMonitoring.objects.filter(city__contains=name).exclude(n_type__in=['微信', '微博', '今日头条', '抖音']).aggregate(
nums=Sum('update'))['nums']
return HttpResponse(json.dumps({
"status":"1",
"timelinessmonitoring_weixin":timelinessmonitoring_weixin,
"timelinessmonitoring_weibo":timelinessmonitoring_weibo,
"timelinessmonitoring_toutiao":timelinessmonitoring_toutiao,
"timelinessmonitoring_douyin":timelinessmonitoring_douyin,
"timelinessmonitoring_qita":timelinessmonitoring_qita,
2020-11-04 03:05:43 +00:00
}))
def index_newmedia_count(request):
2020-11-04 03:52:36 +00:00
date_list = [x.strftime('%Y-%m-%d') for x in list(pd.date_range(start='2020-09-01',end=datetime.datetime.now()))]
2020-11-04 03:05:43 +00:00
weixin_list = []
weibo_list = []
toutiao_list = []
douyin_list = []
qita_list = []
for d in date_list:
s = str(d).split('-')
weixin = Weixin.objects.filter(created__year=s[0],created__month=s[1],created__day=s[2]).count()
weixin_list.append(weixin)
weibo = Weibo.objects.filter(created__year=s[0],created__month=s[1],created__day=s[2]).count()
weibo_list.append(weibo)
toutiao = Toutiao.objects.filter(created__year=s[0],created__month=s[1],created__day=s[2]).count()
toutiao_list.append(toutiao)
douyin = Douyin.objects.filter(created__year=s[0],created__month=s[1],created__day=s[2]).count()
douyin_list.append(douyin)
qita = Qita.objects.filter(created__year=s[0],created__month=s[1],created__day=s[2]).count()
qita_list.append(qita)
return HttpResponse(json.dumps({
"status":"1",
2020-11-04 03:52:36 +00:00
"date_list":date_list,
2020-11-04 03:05:43 +00:00
"weixin":weixin_list,
"weibo":weibo_list,
"toutiao":toutiao_list,
"douyin":douyin_list,
"qita":qita_list,
}))
2020-11-04 03:52:36 +00:00
def index_warning_count(request):
2020-11-20 10:41:18 +00:00
# date_list = [x.strftime('%Y-%m-%d') for x in list(pd.date_range(start='2019-07-01',end=datetime.datetime.now()))]
2020-11-18 07:48:17 +00:00
# data = []
2020-11-20 10:41:18 +00:00
# for d in date_list:
# news = News.objects.filter(type='3',date=d).count()
2020-11-18 07:48:17 +00:00
# data.append(news)
2020-11-20 10:41:18 +00:00
# print(str(data)+"6666666666666666666666666666666")
date = News.objects.distinct('date').order_by('-date')
data = []
date_list = []
for d in date:
date_list.append(str(d.date))
news = News.objects.filter(type='3', date=str(d.date)).count()
data.append(news)
2020-11-04 03:52:36 +00:00
return HttpResponse(json.dumps({
"status":"1",
"data":data,
"date_list":date_list
}))