大家好!我是程序员一帆,感谢您阅读本文,欢迎一键三连哦。
🎀当前专栏: Python毕业设计
精彩专栏推荐👇🏻👇🏻👇🏻
开发环境
- 开发语言:Python
- 数据库:mysql 5.7
- 数据库工具:Navicat12
- 开发软件:pycharm
- 浏览器:谷歌浏览器
源码下载地址:
https://download.csdn.net/download/2301_76953549/87951209
论文目录
【如需全文请按文末获取联系】
一、项目简介
本次是通过利用Python技术来进行一款系统数据分析的系统,以B站数据为数据源,通过大数据分析来对B站中的UP主账号进行数据可视化的方式。在数据可视化中,可以通过本次的系统开发来进行UP最喜欢发布的视频类型、视频标签以及对UP主的粉丝数、获赞数等进行柱状图等图形模式来进行分析。另外,本次的设计还需要通过对用户观看视频的内容等进行分析,包括喜欢互动、喜欢分享以及一键三联的视频类型。通过此次的分析,可以将粉丝榜、播放榜等进行均量和总量的图形展示。为有需要的企业提供了数据支持,为对应UP主和用户的观影行为提供了有效的数据分析参考。
二、系统设计
2.1软件功能模块设计
此次设计的相关功能具体展示如下图:
2.2数据库设计
本次设计的数据库的概念主要以实体的分析为主,确保实体与实体之间可以有效地实现良好的联系实现。具体的E-R图展示如下:
三、系统项目部分截图
3.1用户注册登录界面
本次设计的登录界面中,是将登录和注册均设计在了同一个登录的画面下,在该画面下可以通过选择登录或者注册来进行不同的内容选择。在用户的注册过程中,需要用户输入密码、邮箱以及用户名等信息来完成注册,用户的注册界面展示如下:
3.2up主分析
当进入到up主分析的页面时,可以看到按照设计的需求,能够在up主的分析中通过柱状图和折线图的方式来进行相关的数据分析。在该页面中能够看到up主最喜爱发布的视频类型统计,有搞笑、家庭等内容分析,在当前up主发布视频的时间规律上,可以看到有以星期和发布数量形成的X轴和Y轴,并且有折线图来进行每天发布视频数量的信息数据统计,如下图所示:
3.3综合分析界面
在综合分析中,可以看到有三个不同的统计口径,分别为按时、按周和按月三个选择,以下图为例,在按时进行统计时,在柱状图的分析中能够看到该网站内UP主视频发布的数量统计分析,在该图中可以看出7点左右是视频发布数量最多的时段。而在前二十的排名中,可以有视频标签类型的排名,可以看出娱乐的视频发布的数量最多。在平均播放量上,综艺的平均播放量最高。在总播放量上,育婴、美食的播放量相对较高。而在粉丝数量的排名上,也能够看到具体的up主的粉丝数量排名。如下图所示:
3.4多维分析
在多维分析中,系统会根据视频量、播放量以及粉丝量三个指标来进行维度的分析,通过以点状图的方式来进行内容的展示工作,多维分析的界面展示如下图所示:
四、部分核心代码
from django.db.models import Count
from django.forms import model_to_dict
from django.shortcuts import render, HttpResponse, redirect
from django.http import JsonResponse, HttpResponseRedirect
from . import models
from common.auto_send_mail import Send_Email
from common.public_method import MD5_Content, create_code
from django.contrib.auth.decorators import login_required
from django.contrib import auth
from django.urls import reverse
from bilibili_analysis import settings
from common.mypagination import Pagination
# Create your views here.
# 登录接口
def login(request):
if request.method == 'POST':
back_dic = {
'code': 2000,
'msg': ''
}
username = request.POST.get('username')
password = request.POST.get('password')
# 对上传上来的密码进行加密
# md5_password = MD5_Content(pwd=password).create_md5()
# print(md5_password)
user_exist = models.UserInfo.objects.filter(username=username)
user_obj = auth.authenticate(username=username, password=password)
if user_exist:
if user_obj and user_obj.is_active:
# 记录用户登录状态
auth.login(request, user_obj)
back_dic['msg'] = '登录成功!'
back_dic['url'] = '/b_station/up_analysis'
else:
back_dic['code'] = 3000
back_dic['msg'] = '密码错误!'
else:
back_dic['code'] = 3000
back_dic['msg'] = '该用户不存在!'
return JsonResponse(back_dic)
return render(request, 'login.html', locals())
# 注册接口
def register(request):
if request.method == 'POST':
back_dic = {
'code': 2000,
'msg': ''
}
# print(request.POST)
username = request.POST.get('username')
password = request.POST.get('password')
re_password = request.POST.get('re_password')
email = request.POST.get('email')
print(username, password, re_password, email)
# 先校验用户是否存在
user_exist = models.UserInfo.objects.filter(username=username)
if user_exist:
print('该用户名已经存在!')
back_dic['code'] = 3000
back_dic['msg'] = '该用户名已经存在!'
else:
# 判断密码与确认密码是否一致
if password == re_password:
# 对密码进行加密
# password = MD5_Content(pwd=password).create_md5()
# 创建用户
models.UserInfo.objects.create_user(username=username, password=password, email=email, is_active=True)
back_dic['msg'] = '注册成功!'
back_dic['url'] = '/b_station/login/'
else:
back_dic['code'] = 3000
back_dic['msg'] = '两次密码输入不一致!'
return JsonResponse(back_dic)
return render(request, 'register.html', locals())
# 忘记密码接口
def forget_pwd(request):
if request.method == 'POST':
back_dic = {
'code': 2000,
'msg': ''
}
username = request.POST.get('username')
password = request.POST.get('password')
email_password = request.POST.get('email_password').upper()
email_password_localstorage = request.POST.get('email_password_localstorage').upper()
email = request.POST.get('email')
# 对秘钥进行验证
print(email_password, email_password_localstorage)
if email_password == email_password_localstorage:
# 对密码进行加密
# password = MD5_Content(pwd=password).create_md5()
# 修改密码
user = models.UserInfo.objects.get(username=username, email=email)
user.set_password(password)
user.save()
back_dic['url'] = '/b_station/login/'
else:
back_dic['code'] = 3000
back_dic['msg'] = '密钥错误!'
return JsonResponse(back_dic)
return render(request, 'forget_pwd.html', locals())
def user_analysis(request):
fav_type_obj = models.UsrAnl.objects.extra(select={'fav_type': "fav_type"}).values(
"fav_type").annotate(count=Count("id")).order_by()
fav_type_obj_type = []
fav_type_obj_count = []
for j in fav_type_obj:
fav_type_obj_type.append(j['fav_type'])
fav_type_obj_count.append(j['count'])
fav_share_obj = models.UsrAnl.objects.extra(select={'fav_share': "fav_share"}).values(
"fav_share").annotate(count=Count("id")).order_by()
fav_share_obj_type = []
fav_share_obj_count = []
for j in fav_share_obj:
fav_share_obj_type.append(j['fav_share'])
fav_share_obj_count.append(j['count'])
fav_obj = models.UsrAnl.objects.extra(select={'fav_bp': "fav_bp"}).values(
"fav_bp").annotate(count=Count("id")).order_by()
fav_collect = models.UsrAnl.objects.extra(select={'fav_collect': "fav_collect"}).values(
"fav_collect").annotate(count=Count("id")).order_by()
fav_sl = models.UsrAnl.objects.extra(select={'fav_sl': "fav_sl"}).values(
"fav_sl").annotate(count=Count("id")).order_by()
fav_obj_type = []
fav_obj_count = []
print(fav_obj,fav_sl,fav_collect)
fav_co1 = {}
for i in fav_collect:
fav_co1[i['fav_collect']]=i['count']
fav_bp1 = {}
for i in fav_obj:
fav_bp1[i['fav_bp']]= i['count']
fav_sl1 = {}
for i in fav_sl:
fav_sl1[i['fav_sl']]= i['count']
print(fav_co1,fav_bp1,fav_sl1)
print(type(fav_co1))
b = dict_union(fav_co1,fav_bp1)
c = dict_union(b,fav_sl1)
print(c)
three_type = []
three_count =[]
for key,value in c.items():
three_count.append(value)
three_type.append(key)
print(three_type,three_count)
for j in fav_obj:
fav_obj_type.append(j['fav_bp'])
fav_obj_count.append(j['count'])
return render(request, 'user_analysis.html',locals())
def dict_union(d1, d2):
keys = d1.keys() | d2.keys()
temp = {}
for key in keys:
temp[key] = sum([d.get(key, 0) for d in (d1, d2)])
return temp
def up_analysis(request):
current_user = models.TimeW.objects.filter(name=request.user.username).first()
current_user_data_x = [current_user.mon, current_user.tue, current_user.web, current_user.thur, current_user.fri,
current_user.sat, current_user.sun]
current_user_data_y = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日']
up_anl_obj = models.UpAnl.objects.all()
up_anl_obj_list = [['products', '粉丝数', '获赞总数', '总播放数', '阅读数']]
for i in up_anl_obj:
a = [i.name, i.fan_num, i.total_fan, i.total_st, i.read_num]
up_anl_obj_list.append(a)
fav_type_obj = models.UpAnl.objects.extra(select={'fav_type': "fav_type"}).values(
"fav_type").annotate(count=Count("id")).order_by()
fav_type_obj_type = []
fav_type_obj_count = []
for j in fav_type_obj:
fav_type_obj_type.append(j['fav_type'])
fav_type_obj_count.append(j['count'])
fav_tag_obj = models.UpAnl.objects.extra(select={'fav_tag': "fav_tag"}).values(
"fav_tag").annotate(count=Count("id")).order_by()
fav_tag_obj_type = []
fav_tag_obj_count = []
for j in fav_tag_obj:
fav_tag_obj_type.append(j['fav_tag'])
fav_tag_obj_count.append(j['count'])
return render(request, 'up_analysis.html', locals())
# 发送忘记密码邮件
def send_email(request):
if request.method == "POST":
back_dic = {
'code': 2000,
'msg': ''
}
username = request.POST.get('username')
email = request.POST.get('email')
user_exist = models.UserInfo.objects.filter(username=username)
if user_exist:
db_email = models.UserInfo.objects.filter(username=username).first().email
# print(db_email)
if db_email == email:
secret_key = create_code()
# print(type(secret_key))
print('secret_key:', secret_key)
# 将生成的密钥,保存到session中
# 发送邮件
# Send_Email(mail_receiver=email, content=secret_key, type_msg=2).run()
back_dic['msg'] = '邮件已经发送!'
back_dic['secret_key'] = secret_key
Send_Email(mail_receiver=email, content=secret_key, type_msg=2).run()
else:
back_dic['code'] = 3000
back_dic['msg'] = '邮箱不是用户绑定的邮箱!'
else:
back_dic['code'] = 3000
back_dic['msg'] = '用户不存在!'
return JsonResponse(back_dic)
# 首页接口
@login_required(login_url='/b_station/login/')
def home(request):
return render(request, 'home.html', locals())
# 注销
@login_required(login_url='/b_station/login/')
def logout(request):
auth.logout(request)
return redirect(reverse("my_login"))
# 详情页
@login_required(login_url='/b_station/login/')
def detail1(request):
return render(request, 'page.html', locals())
@login_required(login_url='/b_station/login/')
def detail2(request):
return render(request, 'page_2.html', locals())
@login_required(login_url='/b_station/login/')
def detail3(request):
return render(request, 'page_3.html', locals())
@login_required(login_url='/b_station/login/')
def detail4(request):
return render(request, 'page_4.html', locals())
# 用户详情
@login_required(login_url='/b_station/login/')
def info(request):
user = request.user
return render(request, 'info.html', locals())
# 修改用户详情
@login_required(login_url='/b_station/login/')
def change_info(request):
user = request.user
if request.method == "POST":
loginName = request.POST.get('loginName')
accountImg = request.FILES.get('accountImg')
trueName = request.POST.get('trueName')
city = request.POST.get('city')
phone = request.POST.get('phone')
email = request.POST.get('email')
# print(loginName, trueName, city, phone, email, accountImg.__dict__['_name'])
if accountImg:
path = request.user.username + '_' + accountImg.__dict__['_name']
t_path = settings.MEDIA_ROOT + '/avatar/' + path
with open(t_path, 'wb') as f:
for chunk in accountImg.chunks():
f.write(chunk)
# 以上步骤实现了图片的后台保存,还需要修改当前用户数据库中的头像路径。
request.user.avatar = '/avatar/' + path
request.user.save()
# 将其他用户信息更新
models.UserInfo.objects.filter(username=user.username).update(login_name=loginName, phone=phone, city=city,
email=email, true_name=trueName)
return HttpResponseRedirect("/b_station/info")
return render(request, 'info-edit.html', locals())
# 弹幕词云分析
def wordcloud(request):
results = models.UpAnl.objects.extra(select={'fav_tag': "fav_tag"}).values(
"fav_tag").annotate(count=Count("id")).order_by()
cloud = []
for result in results:
cloud.append({"name":result['fav_tag'],"value":result["count"]})
return render(request, 'wordcloud.html', locals())
def test_analysis(request):
results = models.UpAnl.objects.all()
names = []
fan_count = []
bf_count =[]
tg_count = []
total_count = []
read_count =[]
for i in results:
names.append(i.name)
fan_count.append([i.name,int(i.fan_num)])
bf_count.append([i.name,i.total_st])
tg_count.append([i.name,i.total_vi])
read_count.append([i.name,i.read_num])
total_count.append([i.name,int(i.fan_num)+int(i.read_num)+int(i.total_vi)+int(i.total_st)])
return render(request,'test_analysis.html',locals())
def three_analysis(req):
results = models.UpAnl.objects.all()
lists=[]
for i in results:
lists.append([int(i.total_vi),int(i.total_st),int(i.fan_num),i.name])
return render(req,'three_analysis.html',locals())
def all_analysis(req):
results = models.TotalW.objects.all()
time_w_lists=[]
time_w = ['星期一','星期二','星期三','星期四','星期五','星期六','星期日']
for i in results:
time_w_lists.append(int(i.mon))
time_w_lists.append(int(i.tue))
time_w_lists.append(int(i.web))
time_w_lists.append( int(i.thur))
time_w_lists.append(int(i.fri))
time_w_lists.append(int(i.sat))
time_w_lists.append(int(i.sun))
results = models.TotalM.objects.all()
total_m_lists = []
total_m = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
for i in results:
total_m_lists.append(int(i.jan))
total_m_lists.append(int(i.feb))
total_m_lists.append(int(i.mar))
total_m_lists.append(int(i.apr))
total_m_lists.append(int(i.may))
total_m_lists.append(int(i.jun))
total_m_lists.append(int(i.jul))
total_m_lists.append(int(i.aug))
total_m_lists.append(int(i.sep))
total_m_lists.append(int(i.oct))
total_m_lists.append(int(i.nov))
total_m_lists.append(int(i.dec))
results = models.TotalH.objects.all()
total_h_lists = []
total_h = ['1:00', '2:00', '3:00', '4:00','5:00', '6:00','7:00', '8:00','9:00', '10:00','11:00', '12:00','13:00', '14:00','15:00', '16:00','17:00', '18:00','19:00', '20:00','21:00', '22:00','23:00', '24:00',]
for i in results:
total_h_lists.append(int(i.one_hour))
total_h_lists.append(int(i.two_hour))
total_h_lists.append(int(i.three_hour))
total_h_lists.append(int(i.four_hour))
total_h_lists.append(int(i.five_hour))
total_h_lists.append(int(i.six_hour))
total_h_lists.append(int(i.seven_hour))
total_h_lists.append(int(i.eight_hour))
total_h_lists.append(int(i.nine_hour))
total_h_lists.append(int(i.ten_hour))
total_h_lists.append(int(i.eleven_hour))
total_h_lists.append(int(i.twelve_hour))
total_h_lists.append(int(i.thirteen_hour))
total_h_lists.append(int(i.fourteen_hour))
total_h_lists.append(int(i.fifteen_hour))
total_h_lists.append(int(i.sixteen_hour))
total_h_lists.append(int(i.seventeen_hour))
total_h_lists.append(int(i.eighteen_hour))
total_h_lists.append(int(i.nineteen_hour))
total_h_lists.append(int(i.twenty_hour))
total_h_lists.append(int(i.twenty_one_hour))
total_h_lists.append(int(i.twenty_two_hour))
total_h_lists.append(int(i.twenty_three_hour))
total_h_lists.append(int(i.twenty_four_hour))
tag_name = []
tag_list = []
results = models.Bq.objects.all()
for i in results:
tag_name.append(i.tag)
tag_list.append(int(i.num))
tag_avg_name = []
tag_avg_list = []
results = models.BqAvlStTop.objects.all()
for i in results:
tag_avg_name.append(i.tag)
tag_avg_list.append(int(i.num))
tag_total_name = []
tag_total_list = []
results = models.BqStTop.objects.all()
for i in results:
tag_total_name.append(i.tag)
tag_total_list.append(int(i.num))
fans_name = []
fans_list = []
bf_list = []
results = models.UpAnl.objects.all()
for i in results:
fans_name.append(i.name)
fans_list.append(int(i.fan_num))
return render(req,'all_analysis.html',locals())
获取源码或论文
如需对应的论文或源码,以及其他定制需求,也可以下方微❤联系。