add media feature
This commit is contained in:
parent
8f35e873a2
commit
1e6da135fe
|
@ -3,6 +3,8 @@ from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# 权限等级
|
# 权限等级
|
||||||
|
|
||||||
|
|
||||||
class Level(models.Model):
|
class Level(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
name = models.CharField('等级名', max_length=256, null=True, blank=True)
|
name = models.CharField('等级名', max_length=256, null=True, blank=True)
|
||||||
|
@ -12,6 +14,8 @@ class Level(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Group_type(models.Model):
|
class Group_type(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
type = models.CharField('矩阵类型', max_length=256, null=True, blank=True)
|
type = models.CharField('矩阵类型', max_length=256, null=True, blank=True)
|
||||||
|
@ -19,6 +23,8 @@ class Group_type(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.type
|
return self.type
|
||||||
# 矩阵
|
# 矩阵
|
||||||
|
|
||||||
|
|
||||||
class Group(models.Model):
|
class Group(models.Model):
|
||||||
GROUP_STATUS_CHOICES = (
|
GROUP_STATUS_CHOICES = (
|
||||||
('0', '关闭'),
|
('0', '关闭'),
|
||||||
|
@ -37,7 +43,8 @@ class Group(models.Model):
|
||||||
district = models.CharField('县', max_length=256, null=True, blank=True)
|
district = models.CharField('县', max_length=256, null=True, blank=True)
|
||||||
town = models.CharField('乡', max_length=256, null=True, blank=True)
|
town = models.CharField('乡', max_length=256, null=True, blank=True)
|
||||||
village = models.CharField('村', max_length=256, null=True, blank=True)
|
village = models.CharField('村', max_length=256, null=True, blank=True)
|
||||||
user = models.ForeignKey(User,on_delete=models.CASCADE,blank=True,null=True)
|
user = models.ForeignKey(
|
||||||
|
User, on_delete=models.CASCADE, blank=True, null=True)
|
||||||
|
|
||||||
created = models.DateTimeField('创建时间', auto_now_add=True)
|
created = models.DateTimeField('创建时间', auto_now_add=True)
|
||||||
updated = models.DateTimeField('更新时间', auto_now=True)
|
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||||
|
@ -46,6 +53,8 @@ class Group(models.Model):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
# 矩阵管理员
|
# 矩阵管理员
|
||||||
|
|
||||||
|
|
||||||
class Group_admin(models.Model):
|
class Group_admin(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
|
@ -58,6 +67,8 @@ class Group_admin(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.group.name
|
return self.group.name
|
||||||
# 矩阵成员
|
# 矩阵成员
|
||||||
|
|
||||||
|
|
||||||
class Group_user(models.Model):
|
class Group_user(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
|
@ -71,6 +82,8 @@ class Group_user(models.Model):
|
||||||
return self.user.username
|
return self.user.username
|
||||||
|
|
||||||
# 单位类型
|
# 单位类型
|
||||||
|
|
||||||
|
|
||||||
class Organizationtype(models.Model):
|
class Organizationtype(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
organizationtype = models.CharField(
|
organizationtype = models.CharField(
|
||||||
|
@ -94,8 +107,9 @@ class Organization(models.Model):
|
||||||
district = models.CharField('县', max_length=256, null=True, blank=True)
|
district = models.CharField('县', max_length=256, null=True, blank=True)
|
||||||
town = models.CharField('乡', max_length=256, null=True, blank=True)
|
town = models.CharField('乡', max_length=256, null=True, blank=True)
|
||||||
village = models.CharField('村', max_length=256, null=True, blank=True)
|
village = models.CharField('村', max_length=256, null=True, blank=True)
|
||||||
level = models.ForeignKey(Level,on_delete=models.CASCADE,null=True,blank=True)
|
level = models.ForeignKey(
|
||||||
directly = models.CharField('直属',max_length=256,null=True,blank=True)
|
Level, on_delete=models.CASCADE, null=True, blank=True)
|
||||||
|
directly = models.CharField('直属', max_length=256, null=True, blank=True)
|
||||||
created = models.DateTimeField('创建时间', auto_now_add=True)
|
created = models.DateTimeField('创建时间', auto_now_add=True)
|
||||||
updated = models.DateTimeField('更新时间', auto_now=True)
|
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||||
|
|
||||||
|
@ -148,8 +162,8 @@ class NewMedia(models.Model):
|
||||||
Organization, on_delete=models.CASCADE, null=True, blank=True)
|
Organization, on_delete=models.CASCADE, null=True, blank=True)
|
||||||
status = models.CharField(
|
status = models.CharField(
|
||||||
'状态', max_length=256, null=True, blank=True, choices=NEWMEDIA_STATUS_CHOICES)
|
'状态', max_length=256, null=True, blank=True, choices=NEWMEDIA_STATUS_CHOICES)
|
||||||
attention = models.CharField('关注量',null=True,blank=True,max_length=256)
|
attention = models.CharField('关注量', null=True, blank=True, max_length=256)
|
||||||
remark = models.CharField('备注',null=True,blank=True,max_length=2560)
|
remark = models.CharField('备注', null=True, blank=True, max_length=2560)
|
||||||
created = models.DateTimeField('创建时间', auto_now_add=True)
|
created = models.DateTimeField('创建时间', auto_now_add=True)
|
||||||
updated = models.DateTimeField('更新时间', auto_now=True)
|
updated = models.DateTimeField('更新时间', auto_now=True)
|
||||||
|
|
||||||
|
@ -157,16 +171,158 @@ class NewMedia(models.Model):
|
||||||
abstract = True
|
abstract = True
|
||||||
ordering = ["-created"]
|
ordering = ["-created"]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def category_one_count(cls):
|
||||||
|
t1 = Weixin.objects.exclude(
|
||||||
|
organization__province=''
|
||||||
|
).filter(
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t2 = Weibo.objects.exclude(
|
||||||
|
organization__province=''
|
||||||
|
).filter(
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t3 = Toutiao.objects.exclude(
|
||||||
|
organization__province=''
|
||||||
|
).filter(
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t4 = Douyin.objects.exclude(
|
||||||
|
organization__province=''
|
||||||
|
).filter(
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t5 = Qita.objects.exclude(
|
||||||
|
organization__province=''
|
||||||
|
).filter(
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
return t1 + t2 + t3 + t4 + t5
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def category_two_count(cls):
|
||||||
|
t1 = Weixin.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities=''
|
||||||
|
).filter(
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t2 = Weibo.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities=''
|
||||||
|
).filter(
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t3 = Toutiao.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities=''
|
||||||
|
).filter(
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t4 = Douyin.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities=''
|
||||||
|
).filter(
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t5 = Qita.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities=''
|
||||||
|
).filter(
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
return t1 + t2 + t3 + t4 + t5
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def category_three_count(cls):
|
||||||
|
t1 = Weixin.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t2 = Weibo.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t3 = Toutiao.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t4 = Douyin.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
t5 = Qita.objects.exclude(
|
||||||
|
organization__province='',
|
||||||
|
organization__cities='',
|
||||||
|
organization__district=''
|
||||||
|
).count()
|
||||||
|
return t1 + t2 + t3 + t4 + t5
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def media_list(cls, organization_id):
|
||||||
|
weixin = Weixin.objects.filter(organization_id=organization_id)
|
||||||
|
weibo = Weibo.objects.filter(organization_id=organization_id)
|
||||||
|
toutiao = Toutiao.objects.filter(organization_id=organization_id)
|
||||||
|
douyin = Douyin.objects.filter(organization_id=organization_id)
|
||||||
|
qita = Qita.objects.filter(organization_id=organization_id)
|
||||||
|
results = []
|
||||||
|
for o in weixin:
|
||||||
|
result = dict()
|
||||||
|
result['id'] = o.id
|
||||||
|
result['code'] = o.code
|
||||||
|
result['alias'] = o.alias
|
||||||
|
result['type'] = 'weixin'
|
||||||
|
results.append(result)
|
||||||
|
for o in weibo:
|
||||||
|
result = dict()
|
||||||
|
result['id'] = o.id
|
||||||
|
result['code'] = o.code
|
||||||
|
result['alias'] = o.alias
|
||||||
|
result['type'] = 'weibo'
|
||||||
|
results.append(result)
|
||||||
|
for o in toutiao:
|
||||||
|
result = dict()
|
||||||
|
result['id'] = o.id
|
||||||
|
result['code'] = o.code
|
||||||
|
result['alias'] = o.alias
|
||||||
|
result['type'] = 'toutiao'
|
||||||
|
results.append(result)
|
||||||
|
for o in douyin:
|
||||||
|
result = dict()
|
||||||
|
result['id'] = o.id
|
||||||
|
result['code'] = o.code
|
||||||
|
result['alias'] = o.alias
|
||||||
|
result['type'] = 'douyin'
|
||||||
|
results.append(result)
|
||||||
|
for o in qita:
|
||||||
|
result = dict()
|
||||||
|
result['id'] = o.id
|
||||||
|
result['code'] = o.code
|
||||||
|
result['alias'] = o.alias
|
||||||
|
result['type'] = 'qita'
|
||||||
|
results.append(result)
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.code + ':' + self.alias
|
return self.code + ':' + self.alias
|
||||||
|
|
||||||
|
|
||||||
# 微信公众号
|
# 微信公众号
|
||||||
class Weixin(NewMedia):
|
class Weixin(NewMedia):
|
||||||
weixinid = models.CharField('微信ID', max_length=256, null=True, blank=True)
|
weixinid = models.CharField('微信ID', max_length=256, null=True, blank=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 微信文章采集
|
# 微信文章采集
|
||||||
class Weixin_data(models.Model):
|
class Weixin_data(models.Model):
|
||||||
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
|
@ -349,6 +505,8 @@ class Douyin_data(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.mewnedia.code
|
return self.mewnedia.code
|
||||||
# 其他新媒体
|
# 其他新媒体
|
||||||
|
|
||||||
|
|
||||||
class Qita(NewMedia):
|
class Qita(NewMedia):
|
||||||
type = models.CharField('新媒体类型', max_length=256, null=True, blank=True)
|
type = models.CharField('新媒体类型', max_length=256, null=True, blank=True)
|
||||||
name = models.CharField('新媒体名称', max_length=256, null=True, blank=True)
|
name = models.CharField('新媒体名称', max_length=256, null=True, blank=True)
|
||||||
|
@ -387,7 +545,9 @@ class Area_code_2020(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
#新闻
|
# 新闻
|
||||||
|
|
||||||
|
|
||||||
class News(models.Model):
|
class News(models.Model):
|
||||||
NEWMEDIA_NEWS_CHOICES = (
|
NEWMEDIA_NEWS_CHOICES = (
|
||||||
('0', '政策依据'),
|
('0', '政策依据'),
|
||||||
|
@ -396,15 +556,16 @@ class News(models.Model):
|
||||||
('3', '监测通报'),
|
('3', '监测通报'),
|
||||||
('4', '舆情热点')
|
('4', '舆情热点')
|
||||||
)
|
)
|
||||||
id = models.UUIDField('id',primary_key=True,default=uuid.uuid4)
|
id = models.UUIDField('id', primary_key=True, default=uuid.uuid4)
|
||||||
type = models.CharField('文章类型',max_length=256,null=True,blank=True,choices=NEWMEDIA_NEWS_CHOICES)
|
type = models.CharField('文章类型', max_length=256, null=True,
|
||||||
source = models.CharField('文章来源',max_length=256,null=True,blank=True)
|
blank=True, choices=NEWMEDIA_NEWS_CHOICES)
|
||||||
title = models.CharField('文章标题',max_length=256,null=True,blank=True)
|
source = models.CharField('文章来源', max_length=256, null=True, blank=True)
|
||||||
|
title = models.CharField('文章标题', max_length=256, null=True, blank=True)
|
||||||
image = models.FileField(
|
image = models.FileField(
|
||||||
upload_to='news/%Y/%m/%d/', null=True, blank=True)
|
upload_to='news/%Y/%m/%d/', null=True, blank=True)
|
||||||
author = models.CharField('作者',max_length=256,null=True,blank=True)
|
author = models.CharField('作者', max_length=256, null=True, blank=True)
|
||||||
date = models.DateField('发表日期',null=True,blank=True,max_length=256)
|
date = models.DateField('发表日期', null=True, blank=True, max_length=256)
|
||||||
content = models.TextField('内容',null=True,blank=True)
|
content = models.TextField('内容', null=True, blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
<div class="flex-container">
|
<div class="flex-container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12">
|
<div class="col-xs-12">
|
||||||
<div id="chart1" style="width: 100%%;height:400px;margin-bottom:40px;"></div>
|
<div id="chart1" style="width: 100%%;height:400px;margin:20px 10px;"></div>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<div id="chart2" style="width: 100%%;height:400px;margin:10px;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,17 +18,20 @@
|
||||||
var myChart = echarts.init(document.getElementById('chart1'));
|
var myChart = echarts.init(document.getElementById('chart1'));
|
||||||
var option = {
|
var option = {
|
||||||
title: {
|
title: {
|
||||||
text: '新媒体占比',
|
text: '政务新媒体种类分布',
|
||||||
left: 'center'
|
left: 'center',
|
||||||
|
subtext: '总数量'+{{total}},
|
||||||
|
subtextStyle: {
|
||||||
|
fontSize: 16,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
trigger: 'item',
|
trigger: 'item',
|
||||||
formatter: '{a} <br/>{b} : {c} ({d}%)'
|
formatter: '{a} <br/>{b} : {c} ({d}%)'
|
||||||
},
|
},
|
||||||
legend: {
|
legend: {
|
||||||
orient: 'vertical',
|
top: '15%',
|
||||||
left: 'left',
|
data: ['微信', '微博', '头条', '抖音', '其它']
|
||||||
data: ['微博', '公众号', '头条号', '抖音', '其它']
|
|
||||||
},
|
},
|
||||||
series: [
|
series: [
|
||||||
{
|
{
|
||||||
|
@ -33,13 +39,7 @@
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
radius: '55%',
|
radius: '55%',
|
||||||
center: ['50%', '60%'],
|
center: ['50%', '60%'],
|
||||||
data: [
|
data: {{chart1_data|safe}},
|
||||||
{value: {{wbc}}, name: '微博'},
|
|
||||||
{value: {{wxc}}, name: '公众号'},
|
|
||||||
{value: {{ttc}}, name: '头条号'},
|
|
||||||
{value: {{dyc}}, name: '抖音'},
|
|
||||||
{value: {{qtc}}, name: '其它'}
|
|
||||||
],
|
|
||||||
emphasis: {
|
emphasis: {
|
||||||
itemStyle: {
|
itemStyle: {
|
||||||
shadowBlur: 10,
|
shadowBlur: 10,
|
||||||
|
@ -50,5 +50,42 @@
|
||||||
}
|
}
|
||||||
]};
|
]};
|
||||||
myChart.setOption(option);
|
myChart.setOption(option);
|
||||||
|
|
||||||
|
var myChart2 = echarts.init(document.getElementById('chart2'));
|
||||||
|
var option2 = {
|
||||||
|
title: {
|
||||||
|
text: '政务新媒体区域分布',
|
||||||
|
subtext: '省直总数{{total1}},市州总数{{total2}},县区总数{{total3}}',
|
||||||
|
subtextStyle: {
|
||||||
|
fontSize: 16,
|
||||||
|
},
|
||||||
|
left: 'center'
|
||||||
|
},
|
||||||
|
tooltip: {
|
||||||
|
trigger: 'item',
|
||||||
|
formatter: '{a} <br/>{b} : {c} ({d}%)'
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
top: '15%',
|
||||||
|
data: ['兰州市', '兰州新区', '嘉峪关市', '金昌市', '白银市', '天水市', '武威市', '张掖市', '平谅市', '酒泉市', '庆阳市', '定西市', '陇南市', '临夏回族自治州','甘南藏族自治州']
|
||||||
|
},
|
||||||
|
series: [
|
||||||
|
{
|
||||||
|
name: '总量',
|
||||||
|
type: 'pie',
|
||||||
|
radius: '50%',
|
||||||
|
center: ['50%', '70%'],
|
||||||
|
data: {{chart2_data|safe}},
|
||||||
|
emphasis: {
|
||||||
|
itemStyle: {
|
||||||
|
shadowBlur: 10,
|
||||||
|
shadowOffsetX: 0,
|
||||||
|
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]};
|
||||||
|
|
||||||
|
myChart2.setOption(option2);
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
Binary file not shown.
Binary file not shown.
|
@ -2,7 +2,7 @@ from django.http import HttpResponse, JsonResponse
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
|
|
||||||
from dashboard.models import Weixin, Weibo, Toutiao, Qita
|
from dashboard.models import NewMedia
|
||||||
from polls.decorators import polls_login_required
|
from polls.decorators import polls_login_required
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,32 +11,9 @@ from polls.decorators import polls_login_required
|
||||||
def medias(request):
|
def medias(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
return HttpResponse(status=405)
|
return HttpResponse(status=405)
|
||||||
category = request.POST.get('category', 'weixin')
|
organization_id = request.GET.get('organization_id')
|
||||||
if category == 'weixin':
|
new_medias = NewMedia.media_list(organization_id)
|
||||||
q = Weixin.objects.filter(status=1)
|
return JsonResponse({'status': 'success', 'message': new_medias}, safe=False)
|
||||||
elif category == 'weibo':
|
|
||||||
q = Weibo.objects.filter(status=1)
|
|
||||||
elif category == 'toutiao':
|
|
||||||
q = Toutiao.objects.filter(status=1)
|
|
||||||
else:
|
|
||||||
q = Qita.objects.filter(status=1)
|
|
||||||
results = []
|
|
||||||
for o in q:
|
|
||||||
result = dict()
|
|
||||||
result['id'] = o.id
|
|
||||||
result['code'] = o.code
|
|
||||||
if category == 'weixin':
|
|
||||||
result['media_id'] = o.weixinid
|
|
||||||
elif category == 'weibo':
|
|
||||||
result['media_id'] = o.weixinid
|
|
||||||
elif category == 'toutiao':
|
|
||||||
result['media_id'] = o.weixinid
|
|
||||||
else:
|
|
||||||
result['media_id'] = o.weixinid
|
|
||||||
result['alias'] = o.alias
|
|
||||||
result['thumbnail'] = request.build_absolute_uri(o.image.url)
|
|
||||||
results.append(result)
|
|
||||||
return JsonResponse(results, safe=False)
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
|
|
@ -1,5 +1,24 @@
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from dashboard.models import Douyin, Qita, Toutiao, Weibo, Weixin
|
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': '甘南藏族自治州',
|
||||||
|
'620171000000': '兰州新区'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def monitor_statistics(request):
|
def monitor_statistics(request):
|
||||||
|
@ -8,4 +27,77 @@ def monitor_statistics(request):
|
||||||
ttc = Toutiao.objects.count()
|
ttc = Toutiao.objects.count()
|
||||||
qtc = Qita.objects.count()
|
qtc = Qita.objects.count()
|
||||||
dyc = Douyin.objects.count()
|
dyc = Douyin.objects.count()
|
||||||
return render(request, 'polls/monitor_statistics.html', {'wbc': wbc, 'wxc': wxc, 'ttc': ttc, 'dyc': dyc, 'qtc': qtc})
|
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.values('organization__cities').order_by(
|
||||||
|
'organization__cities').annotate(num_media=Count('organization__cities'))
|
||||||
|
for row in q:
|
||||||
|
code = row['organization__cities']
|
||||||
|
compartment = COMPARTMENTS[code]
|
||||||
|
if code in results:
|
||||||
|
nums = results[compartment]
|
||||||
|
nums.append(row['num_media'])
|
||||||
|
else:
|
||||||
|
results[compartment] = [row['num_media']]
|
||||||
|
|
||||||
|
q = Weibo.objects.values('organization__cities').order_by(
|
||||||
|
'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']]
|
||||||
|
|
||||||
|
q = Toutiao.objects.values('organization__cities').order_by(
|
||||||
|
'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']]
|
||||||
|
|
||||||
|
q = Douyin.objects.values('organization__cities').order_by(
|
||||||
|
'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']]
|
||||||
|
|
||||||
|
q = Qita.objects.values('organization__cities').order_by(
|
||||||
|
'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()
|
||||||
|
|
||||||
|
return render(request, 'polls/monitor_statistics.html', {'chart1_data': chart1_data, 'total': total, 'chart2_data': chart2_data, 'total1': total1, 'total2': total2, 'total3': total3})
|
||||||
|
|
Loading…
Reference in New Issue