赞
踩
[毕业设计]2023-2024年最新最全计算机专业毕设选题推荐汇总
感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人 。
随着互联网技术的发展,音乐成为了人们生活中不可或缺的一部分,而网易云音乐作为国内最受欢迎的音乐平台之一,积累了大量的用户和歌单数据。针对这些数据,开发者们可以进行各种分析和挖掘,从而更好地理解用户需求和市场趋势。
本项目就是基于这个背景而设计的,旨在通过Python技术实现对网易云音乐热门歌单数据的采集、清洗、处理和可视化分析,并将结果保存到MySQL数据库中,最终通过Flask构建的数据服务接口实现数据的展示和管理。
运行环境:推荐Python3.6及以上,推荐python3.7;
开发工具:PyChram(推荐);
操作系统:windows 10 8G内存以上(其他windows以及macOS支持,但不推荐);
浏览器:Firefox(推荐)、Google Chrome(推荐)、Edge;
数据库:MySQL8.0(推荐)及其他版本(支持,但容易异常尤其MySQL5.7(不含)以下版本);
数据库可视化工具:Navicat Premium 15(推荐)以及其他Navicat版本
后端:Flask、PyMySql、pandas、requests、bs4
前端:HTML、Jquery、Ajax、LayUI、Echarts
详细:
本项目主要采用了Python的request库、bs4库实现了网易云歌单数据的采集,然后使用pymysql将数据保存到MySQL数据库中。在数据清洗和处理方面,采用了Pandas等库来进行数据清洗和处理,从而得到干净、规范的数据。
在可视化分析方面,采用了Echarts技术实现歌单创建省份数量中国地图、最受欢迎的歌单类型TOP7,歌单分享量和评论数变化,歌单歌曲数量范围,最受欢迎的歌单TOP5、歌单收藏量变化、语种类型歌单播放量等多种分析图表,使得数据更加直观、易于理解。
在后台数据管理方面,采用了Layui技术实现了用户登陆注册、用户管理、公告管理以及歌单数据管理等多种功能,方便管理员对数据进行管理和维护。
本项目实现了以下主要功能:
网易云歌单数据的采集和处理,包括歌单基本信息、歌曲列表、评论数、分享量、创建时间等多种数据。
将数据保存到MySQL数据库中,以便后续进行数据分析和管理。
实现了数据可视化分析功能,包括歌单创建省份数量中国地图、最受欢迎的歌单类型TOP7,歌单分享量和评论数变化,歌单歌曲数量范围,最受欢迎的歌单TOP5、歌单收藏量变化、语种类型歌单播放量等多种分析图表。
实现了后台数据管理功能,包括用户登陆注册、用户管理、公告管理以及歌单数据管理等多种功能。
1、用户管理界面
2、歌曲管理界面
3、注册登录界面
4、后台首页
5、数据采集爬虫界面
from flask import Flask, render_template, url_for import json import pandas as pd import pymysql import re import decimal from flask import Flask as _Flask, flash from flask import request, session from flask.json import JSONEncoder as _JSONEncoder, jsonify import service.users_data as user_service import service.notice_data as notice_data import service.music_data as music_service import datetime class JSONEncoder(_JSONEncoder): def default(self, o): if isinstance(o, decimal.Decimal): return float(o) super(_JSONEncoder, self).default(o) class Flask(_Flask): json_encoder = JSONEncoder import os app = Flask(__name__) app.config['SESSION_TYPE'] = 'filesystem' app.config['SECRET_KEY'] = os.urandom(24) conn = pymysql.connect( host='127.0.0.1', user='root', password='123456', port=3306, # 端口 database='cloud_music', charset='utf8' ) df = pd.read_sql('SELECT * FROM playlists,users WHERE users.id=playlists.id', con=conn) # 登录 @app.route('/login', methods=['POST']) def login(): if request.method == 'POST': account = request.form.get('account') password = request.form.get('password') if not all([account, password]): flash('参数不完整') return "300" res = user_service.get_user(account, password) if res and res[0][0] > 0: session['is_login'] = True session['role'] = res[0][1] return "200" else: return "300" # 登录页面跳转 @app.route('/admin') def admin(): if session.get("is_login"): if session.get('role') == 0: return render_template('admin.html') else: return render_template('admin1.html') else: return render_template('login.html') @app.route('/logout') def logout(): try: session.pop("is_login") return render_template('login.html') except Exception: return render_template('login.html') # 后台首页面跳转 @app.route('/html/welcome') def welcome(): return render_template('html/welcome.html') # 后台注册跳转 @app.route('/html/reg') def html_reg(): return render_template('reg.html') # -----------------用户管理模块START----------------- # 用户管理页面 @app.route('/html/user') def user_manager(): return render_template('html/user.html') # 获取用户数据分页 @app.route('/user/list', methods=["POST"]) def user_list(): get_data = request.form.to_dict() page_size = get_data.get('page_size') page_no = get_data.get('page_no') param = get_data.get('param') data, count, page_list, max_page = user_service.get_user_list(int(page_size), int(page_no), param) return jsonify({"data": data, "count": count, "page_no": page_no, "page_list": page_list, "max_page": max_page}) # 注册用户数据 @app.route('/user/reg', methods=["POST"]) def user_reg(): get_data = request.form.to_dict() name = str(get_data.get('username')) account = str(get_data.get('account')) password = str(get_data.get('password')) company = "平台注册" phone = " " mail = " " type = 1 return user_service.add_user(name, account, password, company, phone, mail, type) # 添加用户数据 @app.route('/user/add', methods=["POST"]) def user_add(): get_data = request.form.to_dict() name = get_data.get('name') account = get_data.get('account') password = get_data.get('password') company = get_data.get('company') phone = get_data.get('phone') mail = get_data.get('mail') type = get_data.get('type') return user_service.add_user(name, account, password, company, phone, mail, type) # 修改用户数据 @app.route('/user/edit', methods=["PUT"]) def user_edit(): get_data = request.form.to_dict() id = get_data.get('id') name = get_data.get('name') password = get_data.get('password') company = get_data.get('company') phone = get_data.get('phone') mail = get_data.get('mail') type = get_data.get('type') user_service.edit_user(id, name, password, company, phone, mail, type) return '200' # 删除用户数据 @app.route('/user/delete', methods=["DELETE"]) def user_delete(): get_data = request.form.to_dict() id = get_data.get('id') user_service.del_user(id) return '200' # -----------------用户管理模块END----------------- # -----------------公告管理模块START----------------- # 公告管理页面 @app.route('/html/notice') def notice_manager(): return render_template('html/notice.html') # 获取最新公告 @app.route('/notice/new', methods=["POST"]) def notice_new(): res = notice_data.get_notice() return jsonify({"title": res[1], "content": res[2], "user_name": res[3], "create_time": str(res[4])}) # 获取公告数据分页 @app.route('/notice/list', methods=["POST"]) def notice_list(): get_data = request.form.to_dict() page_size = get_data.get('page_size') page_no = get_data.get('page_no') param = get_data.get('param') data, count, page_list, max_page = notice_data.get_notice_list(int(page_size), int(page_no), param) return jsonify({"data": data, "count": count, "page_no": page_no, "page_list": page_list, "max_page": max_page}) # 新增公告数据 @app.route('/notice/add', methods=["POST"]) def notice_add(): get_data = request.form.to_dict() title = get_data.get('title') content = get_data.get('content') user_name = get_data.get('user_name') return notice_data.add_notice(title, content, user_name) # 修改公告数据 @app.route('/notice/edit', methods=["PUT"]) def notice_edit(): get_data = request.form.to_dict() id = get_data.get('id') title = get_data.get('title') content = get_data.get('content') user_name = get_data.get('user_name') notice_data.edit_notice(id, title, content, user_name) return '200' # 删除公告数据 @app.route('/notice/delete', methods=["DELETE"]) def notice_delete(): get_data = request.form.to_dict() id = get_data.get('id') notice_data.del_notice(id) return '200' # -----------------公告管理模块END----------------- # -----------------歌单管理模块START----------------- # 歌单管理页面 @app.route('/html/music') def music_manager(): return render_template('html/music.html') # 获取歌单数据分页 @app.route('/music/list', methods=["POST"]) def music_list(): get_data = request.form.to_dict() page_size = get_data.get('page_size') page_no = get_data.get('page_no') param = get_data.get('param') data, count, page_list, max_page = music_service.get_musiclist_list(int(page_size), int(page_no), param) return jsonify({"data": data, "count": count, "page_no": page_no, "page_list": page_list, "max_page": max_page}) # 添加歌单数据 @app.route('/music/add', methods=["POST"]) def music_add(): get_data = request.form.to_dict() name = get_data.get('name') type = get_data.get('type') tags = get_data.get('tags') create_time = get_data.get('create_time') tracks_num = get_data.get('tracks_num') play_count = get_data.get('play_count') subscribed_count = get_data.get('subscribed_count') share_count = get_data.get('share_count') comment_count = get_data.get('comment_count') nickname = get_data.get('nickname') gender = get_data.get('gender') province = get_data.get('province') return music_service.add_musiclist(name, type, tags, create_time, tracks_num, play_count, subscribed_count, share_count, comment_count, nickname, gender, province) # 修改歌单数据 @app.route('/music/edit', methods=["PUT"]) def music_edit(): get_data = request.form.to_dict() id = get_data.get('id') name = get_data.get('name') type = get_data.get('type') tags = get_data.get('tags') tracks_num = get_data.get('tracks_num') play_count = get_data.get('play_count') subscribed_count = get_data.get('subscribed_count') share_count = get_data.get('share_count') comment_count = get_data.get('comment_count') nickname = get_data.get('nickname') gender = get_data.get('gender') province = get_data.get('province') music_service.edit_musiclist(id, name, type, tags, tracks_num, play_count, subscribed_count, share_count, comment_count, nickname, gender, province); return '200' # 删除歌单数据 @app.route('/music/delete', methods=["DELETE"]) def music_delete(): get_data = request.form.to_dict() id = get_data.get('id') music_service.del_user(id) return '200' # -----------------歌单但管理模块END----------------- """最受欢迎的歌单类型""" @app.route('/get_hot_type') def get_hot_type(): hot_type_df = df[['type', 'play_count']].groupby(df['type']).sum().sort_values('play_count', ascending=False).reset_index() hot_type_top7 = hot_type_df.head(7) playlist_type = hot_type_top7['type'].tolist() play_count = hot_type_top7['play_count'].tolist() return json.dumps({'playlist_type': playlist_type, 'play_count': play_count}, ensure_ascii=False) """最受欢迎的歌单""" @app.route('/get_hot_playlist') def get_hot_playlist(): hot_playlist_df = df[['name', 'play_count']].sort_values('play_count', ascending=False).reset_index() hot_playlist_top5 = hot_playlist_df.head(5) playlist_name = hot_playlist_top5['name'].tolist() play_count = hot_playlist_top5['play_count'].tolist() return json.dumps({'playlist_name': playlist_name, 'play_count': play_count}, ensure_ascii=False) """歌单数据随月份变化""" @app.route('/get_month_data') def get_month_data(): yearList = [] # 获取当前日期和时间 current_date = datetime.datetime.now() # 获取今年年份 this_year = current_date.year # 获取去年年份 last_year = this_year - 1 for year in [last_year, this_year]: year = str(year) yearList.append({ "year": year, "data": [ df[df['create_time'].str[:4] == year].groupby(df['create_time'].str[5:7]).sum().reset_index()[ 'share_count'].tolist(), df[df['create_time'].str[:4] == year].groupby(df['create_time'].str[5:7]).sum().reset_index()[ 'comment_count'].tolist() ] }) month = df[df['create_time'].str[:4] == str(this_year)].groupby(df['create_time'].str[5:7]).sum().reset_index()[ 'create_time'].tolist() yearData = { "yearData": yearList, "monthList": [str(int(x)) + '月' for x in month] } return json.dumps(yearData, ensure_ascii=False) """歌单数据随天数变化""" @app.route('/get_day_data') def get_day_data(): non_vip_df = df[df['vip_type'] == '0'].groupby(df['create_time'].str[8:10]).sum().reset_index()[ ['create_time', 'subscribed_count']] vip_df = \ df[(df['vip_type'] == '10') | (df['vip_type'] == '11')].groupby( df['create_time'].str[8:10]).sum().reset_index()[ ['create_time', 'subscribed_count']] vip_type_df = pd.merge(non_vip_df, vip_df, left_on='create_time', right_on='create_time', how='inner') sub_data = { "day": [str(int(x)) for x in vip_type_df["create_time"].tolist()], "vip": vip_type_df["subscribed_count_y"].tolist(), "nonvip": vip_type_df["subscribed_count_x"].tolist(), } return json.dumps(sub_data, ensure_ascii=False) """歌单歌曲数量分布""" @app.route('/get_track_data') def get_track_data(): bins = [0, 50, 150, 500, 100000] cuts = pd.cut(df['tracks_num'], bins=bins, right=False, include_lowest=True) data_count = cuts.value_counts() data = dict(zip([str(x) for x in data_count.index.tolist()], data_count.tolist())) map_data = [{'name': name, 'value': value} for name, value in data.items()] track_value = {'t_v': map_data} return json.dumps(track_value, ensure_ascii=False) """语种类型歌单播放量""" @app.route('/get_type_data') def get_type_data(): playlist_type_df = df[['type', 'play_count']].groupby(df['type']).sum() playlist_type_df = playlist_type_df.loc[['华语', '欧美', '日语', '韩语', '粤语'], :] data = dict(zip(playlist_type_df.index.tolist(), playlist_type_df['play_count'].tolist())) map_data = [{'name': name, 'value': value} for name, value in data.items()] type_sum = {'t_s': map_data} return json.dumps(type_sum, ensure_ascii=False) def replace_str(x): rep_list = ['省', '市', '维吾尔', '自治区', '壮族', '回族', '维吾尔族', '特别行政区'] for rep in rep_list: x = re.sub(rep, '', x) # 利用正则表达式实现替换处理 return x def add_province(df_data, province): # 所有年份 years = df_data['create_time'].drop_duplicates().tolist() for year in years: # 每年的省份 new_province = df_data.loc[df_data['create_time'] == year, :]['province'].drop_duplicates().tolist() # 缺失的省份 = 所有省份 - 每年的省份 rest_province = [x for x in province if x not in new_province] # 对缺失的省份生成一个DataFrame,填充0值,并与原DataFrame合并 if len(rest_province): rest_df = pd.DataFrame([[year, x, 0] for x in rest_province], columns=df_data.columns) df_data = pd.concat([df_data, rest_df], ignore_index=True) return df_data """动态地图""" @app.route('/get_map_data') def get_map_data(): time_df = df.groupby([df['create_time'].str[:4], df['province'].apply(replace_str)]) time_df = time_df['play_count'].count().reset_index() re_time_df = time_df[time_df['province'] != '海外'] province = re_time_df['province'].drop_duplicates().tolist() re_time_df2 = add_province(re_time_df, province) final_time_df = re_time_df2.sort_values(by=['create_time', 'province']).reset_index(drop=True) final_province = final_time_df['province'].drop_duplicates().tolist() final_year = final_time_df['create_time'].drop_duplicates().tolist() playlist_num = [] for year in final_year: playlist_num.append(final_time_df.loc[final_time_df['create_time'] == year, 'play_count'].tolist()) playlist_data = {"year": final_year, "province": final_province, "playlist_num": playlist_num} return json.dumps(playlist_data, ensure_ascii=False) @app.route('/') def index(): gender_df = df[['gender']].groupby(df['gender']).count() gender_data = {'男': gender_df.loc['男', 'gender'], '女': gender_df.loc['女', 'gender']} return render_template('index.html', gender_data=gender_data) if __name__ == "__main__": app.run()
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/742309
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。