new functions
This commit is contained in:
@@ -158,3 +158,14 @@ class Liuyan(models.Model): # 定义留言板模型
|
||||
verbose_name = '留言'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
class Chat_info(models.Model): # 定义聊天板模型
|
||||
# article = models.ForeignKey(to=Article, on_delete=models.DO_NOTHING, verbose_name='评论文章')
|
||||
chat_content = models.TextField(verbose_name='留言内容')
|
||||
user_chat_name = models.CharField(verbose_name='聊天人姓名', max_length=128, null=False, blank=False) #留言人id
|
||||
chat_time = models.DateTimeField(auto_now_add=True, verbose_name='留言时间')
|
||||
|
||||
class Meta:
|
||||
db_table = 'chat_tb'
|
||||
verbose_name = '聊天'
|
||||
verbose_name_plural = verbose_name
|
||||
|
||||
|
||||
+47
-12
@@ -1,8 +1,11 @@
|
||||
import json
|
||||
import time
|
||||
from wordcloud import WordCloud
|
||||
# python的可视化库,也是二级考试推荐的可视化库
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
from django.shortcuts import render
|
||||
from server.models import Task,StudentandTercher,Comment,Liuyan,CooperationMind,Jiaoben
|
||||
from server.models import Task,StudentandTercher,Comment,Liuyan,CooperationMind,Jiaoben,Chat_info
|
||||
from server_auth.models import MindUser
|
||||
|
||||
def front_comment(type):
|
||||
@@ -162,6 +165,16 @@ def to_qunti(request):
|
||||
xyz = []
|
||||
xyz2 = []
|
||||
all_student = MindUser.objects.all()
|
||||
chat_content = []
|
||||
sui1 = []
|
||||
sui2 = []
|
||||
sui3 = []
|
||||
sui4 = []
|
||||
sui5 = []
|
||||
sui6 = []
|
||||
sui7 = []
|
||||
sui8 = []
|
||||
sui9 = []
|
||||
# 遍历所有记录
|
||||
for stu in all_student:
|
||||
class_name = json.loads(stu.select_class)['class']
|
||||
@@ -180,22 +193,31 @@ def to_qunti(request):
|
||||
it3.append(str(it1) + "第" + str(it2) + "小组")
|
||||
if name in it3:
|
||||
student.append(stu.username)
|
||||
print("-----------------------------------------------")
|
||||
print(stu.username)
|
||||
chat_info = Chat_info.objects.filter(user_chat_name=stu.username).values('chat_content')
|
||||
id = MindUser.objects.get(username=stu.username).id
|
||||
pinglun_info = Comment.objects.filter(pinglun_id=id).values('comment_content')
|
||||
print("-----------------------------------------------")
|
||||
print(len(chat_info))
|
||||
sui2.append(len(chat_info))
|
||||
sui1.append(len(pinglun_info))
|
||||
if len(chat_info) != 0:
|
||||
for i in range(len(chat_info)):
|
||||
chat_content.append(chat_info[i]['chat_content'])
|
||||
if len(pinglun_info) != 0:
|
||||
for i in range(len(pinglun_info)):
|
||||
chat_content.append(pinglun_info[i]['comment_content'])
|
||||
print("-----------------------------------------------")
|
||||
print(pinglun_info)
|
||||
# chat_content.append()
|
||||
data.append([random.uniform(110,150),random.uniform(100,150),random.uniform(100,150)])
|
||||
data_time.append([random.uniform(10,20),random.uniform(20,40),random.uniform(40,60),random.uniform(60,80),random.uniform(80,100)])
|
||||
xyz.append(random.uniform(300,800))
|
||||
xyz2.append(random.uniform(200,600))
|
||||
sui1 = []
|
||||
sui2 = []
|
||||
sui3 = []
|
||||
sui4 = []
|
||||
sui5 = []
|
||||
sui6 = []
|
||||
sui7 = []
|
||||
sui8 = []
|
||||
sui9 = []
|
||||
print("-----------------------------------------------")
|
||||
print(chat_content)
|
||||
for i in range(len(student)):
|
||||
sui1.append(random.uniform(200, 600))
|
||||
sui2.append(random.uniform(100, 400))
|
||||
sui3.append(random.uniform(300, 700))
|
||||
sui4.append(random.uniform(200, 600))
|
||||
sui5.append(random.uniform(500, 900))
|
||||
@@ -206,6 +228,19 @@ def to_qunti(request):
|
||||
|
||||
|
||||
print(remove_digits(kecheng['belong'][0]))
|
||||
text_cut = '/'.join(chat_content)
|
||||
|
||||
# 看一下连接后的样子
|
||||
# 关键点 text_cut 是词云要处理的内容
|
||||
print(text_cut)
|
||||
wordcloud = WordCloud(background_color='white', font_path='msyh.ttc', width=1000, height=860, margin=2).generate(
|
||||
text_cut)
|
||||
# 显示图片
|
||||
plt.imshow(wordcloud)
|
||||
plt.axis('off')
|
||||
plt.savefig('./static/pic/wordcloud.png') # 保存为PNG格式,你可以根据需要更改文件名和格式
|
||||
# plt.show()
|
||||
|
||||
datas = zip(student,data)
|
||||
datas2 = zip(student,data)
|
||||
datas3 = zip(student,xyz,xyz2)
|
||||
|
||||
Reference in New Issue
Block a user