diff --git a/BookDouban250.csv b/BookDouban250.csv index 991f0c8..07997eb 100644 --- a/BookDouban250.csv +++ b/BookDouban250.csv @@ -1,76 +1,76 @@ 书名,豆瓣链接,作者,译者,出版社,出版日期,价格,评分,评分人数,一句话评价 红楼梦,https://book.douban.com/subject/1007305/,[清] 曹雪芹 著 ,, 人民文学出版社 , 1996-12 , 59.70元,9.6,"( - 424885人评价 + 424932人评价 )",都云作者痴,谁解其中味? 活着,https://book.douban.com/subject/4913064/,余华 ,, 作家出版社 , 2012-8 , 20.00元,9.4,"( - 835583人评价 + 835699人评价 )",生的苦难与伟大 1984,https://book.douban.com/subject/4820710/,[英] 乔治·奥威尔 , 刘绍铭 , 北京十月文艺出版社 , 2010-4-1 , 28.00,9.4,"( - 285215人评价 + 285264人评价 )",栗树荫下,我出卖你,你出卖我 哈利·波特,https://book.douban.com/subject/24531956/,J.K.罗琳 (J.K.Rowling) , 苏农 , 人民文学出版社 , 2008-12-1 , 498.00元,9.7,"( - 107799人评价 + 107828人评价 )",从9¾站台开始的旅程 三体全集,https://book.douban.com/subject/6518605/,刘慈欣 ,, 重庆出版社 , 2012-1 , 168.00元,9.5,"( - 188276人评价 + 188309人评价 )",地球往事三部曲 百年孤独,https://book.douban.com/subject/6082808/,[哥伦比亚] 加西亚·马尔克斯 , 范晔 , 南海出版公司 , 2011-6 , 39.50元,9.3,"( - 426649人评价 + 426699人评价 )",魔幻现实主义文学代表作 飘,https://book.douban.com/subject/1068920/,[美国] 玛格丽特·米切尔 , 李美华 , 译林出版社 , 2000-9 , 40.00元,9.3,"( - 212846人评价 + 212872人评价 )",革命时期的爱情,随风而逝 动物农场,https://book.douban.com/subject/2035179/,[英] 乔治·奥威尔 , 荣如德 , 上海译文出版社 , 2007-3 , 10.00元,9.3,"( - 160464人评价 + 160481人评价 )",太阳底下并无新事 房思琪的初恋乐园,https://book.douban.com/subject/27614904/,林奕含 ,, 北京联合出版公司 , 2018-2 , 45.00元,9.2,"( - 380660人评价 + 380731人评价 )",向死而生的文学绝唱 三国演义(全二册),https://book.douban.com/subject/1019568/,[明] 罗贯中 ,, 人民文学出版社 , 1998-05 , 39.50元,9.3,"( - 168830人评价 + 168841人评价 )",是非成败转头空 福尔摩斯探案全集(上中下),https://book.douban.com/subject/1040211/,[英] 阿·柯南道尔 , 丁钟华 等 , 群众出版社 , 1981-8 , 53.00元/68.00元,9.3,"( - 133835人评价 + 133838人评价 )",名侦探的代名词 白夜行,https://book.douban.com/subject/10554308/,[日] 东野圭吾 , 刘姿君 , 南海出版公司 , 2013-1-1 , 39.50元,9.2,"( - 476436人评价 + 476505人评价 )",一宗离奇命案牵出跨度近20年步步惊心的故事 小王子,https://book.douban.com/subject/1084336/,[法] 圣埃克苏佩里 , 马振骋 , 人民文学出版社 , 2003-8 , 22.00元,9.1,"( - 757268人评价 + 757307人评价 )",献给长成了大人的孩子们 安徒生童话故事集,https://book.douban.com/subject/1046209/,(丹麦)安徒生 , 叶君健 , 人民文学出版社 , 1997-08 , 25.00元,9.3,"( - 132974人评价 + 132988人评价 )",为了争取未来的一代 天龙八部,https://book.douban.com/subject/1255625/,金庸 ,, 生活·读书·新知三联书店 , 1994-5 , 96.00元,9.2,"( - 133154人评价 + 133163人评价 )",有情皆孽,无人不冤 呐喊,https://book.douban.com/subject/1449351/,鲁迅 ,, 人民文学出版社 , 1973-3 , 0.36元,9.2,"( - 160853人评价 + 160877人评价 )",新文学的第一声呐喊 撒哈拉的故事,https://book.douban.com/subject/1060068/,三毛 ,, 哈尔滨出版社 , 2003-8 , 15.80元,9.2,"( - 175479人评价 + 175517人评价 )",游荡的自由灵魂 悉达多,https://book.douban.com/subject/26980487/,[德] 赫尔曼·黑塞 , 姜乙 , 天津人民出版社 , 2017-1 , 32.00元,9.3,"( - 106788人评价 + 106870人评价 )", 邓小平时代,https://book.douban.com/subject/20424526/,【美】傅高义 (Ezra.F.Vogel) , 冯克利 , 生活·读书·新知三联书店 , 2013-1-18 , 88.00元,9.3,"( - 71146人评价 + 71166人评价 )",个人命运背后的历史变局 杀死一只知更鸟,https://book.douban.com/subject/6781808/,[美] 哈珀·李 , 高红梅 , 译林出版社 , 2012-9 , 32.00元,9.2,"( - 147208人评价 + 147222人评价 )",有一种东西不能遵循从众原则,那就是——人的良心 明朝那些事儿(1-9),https://book.douban.com/subject/3674537/,当年明月 ,, 中国海关出版社 , 2009-4 , 358.20元,9.2,"( - 175540人评价 + 175585人评价 )",不拘一格的历史书写 失踪的孩子,https://book.douban.com/subject/30172069/,[意] 埃莱娜·费兰特 , 陈英 , 人民文学出版社 , 2018-7 , 62.00元,9.2,"( - 81932人评价 + 81962人评价 )",我的整个生命,只是一场为了提升社会地位的低俗斗争。 新名字的故事,https://book.douban.com/subject/26986954/,[意] 埃莱娜·费兰特 , 陈英 , 人民文学出版社 , 2017-4 , 59.00元,9.2,"( - 92504人评价 + 92527人评价 )",探索青年时代的激情、困惑、挣扎、背叛和失去 野草,https://book.douban.com/subject/1915958/,鲁迅 ,, 人民文学出版社 , 1973-3 , 0.20元,9.5,"( - 47629人评价 + 47638人评价 )",我以这一丛野草,在明与暗,生与死,过去与未来之际,献于友与仇,人与兽,爱者与不爱者之前作证。 沉默的大多数,https://book.douban.com/subject/1054685/,王小波 ,, 中国青年出版社 , 1997-10 , 27.00元,9.1,"( - 151766人评价 + 151786人评价 )",沉默是沉默者的通行证 diff --git a/GUI.py b/GUI.py index 5573431..fe15124 100644 --- a/GUI.py +++ b/GUI.py @@ -3,154 +3,143 @@ from pyecharts.charts import Bar,Page,Line,Timeline from pyecharts.commons.utils import JsCode from pyecharts.globals import ThemeType from pyecharts.charts import Pie +import sql from pyecharts.faker import Faker -from main import book_list_data +# from main import book_list_data from collections import Counter - - -book_list_data_sortBystart = sorted(book_list_data, key=lambda x: (x.star, x.star_people), reverse=True) -book_list_data_sortBystart=book_list_data_sortBystart[:10] -book_list_data_sortBystart=book_list_data_sortBystart[::-1] -# 从book_list_data中提取书籍名称和评分数据 -book_names = [book.name for book in book_list_data_sortBystart] -book_stars = [book.star for book in book_list_data_sortBystart] -x_data = list(range(1, len(book_names) + 1)) -# 创建柱状图 -bar = ( -Bar(init_opts=opts.InitOpts(theme="shine",width="850px",height='400px')) - .add_xaxis(book_names) - .add_yaxis("评分", book_stars,color="red") - .reversal_axis() # 实现旋转 - .set_global_opts( - title_opts=opts.TitleOpts(title="评分前10榜", pos_bottom="bottom", pos_left="center"), - xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=0)), - yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-45)) +class Book: + def __init__(self, name, url, star, star_people, author, translater, publisher, pub_year, price, comment): + self.name = name + self.url = url + self.star = star + self.star_people = star_people + self.author = author + self.translater = translater + self.publisher = publisher + self.pub_year = pub_year + self.price = price + self.comment = comment +db = sql.BookDatabase(host='localhost', user='root', password='123456', database='xiaosuo', table_name='books') +db.initialize_table() +def show(): + data = db.get_book_list() + book_list_data = [] + for book in data: + book_list_data.append( + Book(book["name"], book["url"], book["star"], book["star_people"], book["author"], book["translater"], + book["publisher"], book["pub_year"], book["price"], book["comment"])) + + book_list_data_sortBystart = sorted(book_list_data, key=lambda x: (x.star, x.star_people), reverse=True) + book_list_data_sortBystart = book_list_data_sortBystart[:10] + book_list_data_sortBystart = book_list_data_sortBystart[::-1] + # 从book_list_data中提取书籍名称和评分数据 + book_names = [book.name for book in book_list_data_sortBystart] + book_stars = [book.star for book in book_list_data_sortBystart] + x_data = list(range(1, len(book_names) + 1)) + # 创建柱状图 + bar = ( + Bar(init_opts=opts.InitOpts(theme="shine", width="850px", height='400px')) + .add_xaxis(book_names) + .add_yaxis("评分", book_stars, color="red") + .reversal_axis() # 实现旋转 + .set_global_opts( + title_opts=opts.TitleOpts(title="评分前10榜", pos_bottom="bottom", pos_left="center"), + xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=0)), + yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-45)) + ) + # .render("bar_datazoom_slider.html") ) -# .render("bar_datazoom_slider.html") -) - - -publisher_list = [book.publisher for book in book_list_data] -# 使用Counter来计算每个出版商的数量 -publisher_counter = Counter(publisher_list) -publisher_names = list(publisher_counter.keys()) -publisher_counts = list(publisher_counter.values()) -colors = [ - "#5470c6", "#91cc75", "#fac858", "#ee6666", "#73c0de", - "#3ba272", "#fc8452", "#9a60b4", "#ea7ccc", "#bb60b4", - "#8B008B", "#FF1493", "#1E90FF", "#20B2AA", "#2E8B57", - "#B22222", "#FF4500", "#4682B4", "#DAA520", "#32CD32" -] - -# 使用Pyecharts创建饼图 -pie = ( - Pie() - .add("", [list(z) for z in zip(publisher_names, publisher_counts)]) - .set_colors(colors) # 设置颜色 - .set_global_opts(title_opts=opts.TitleOpts(title="出版商分布饼图", pos_left="center",pos_bottom="bottom")) - .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) -) - -prices = [float(book.price) for book in book_list_data ] -print(prices) -# 将价格分组到不同的区间 -price_intervals = [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, float('inf')] # 设置价格区间 -price_counts = [0] * (len(price_intervals) - 1) # 初始化每个区间的计数为0 -prices_intervalsStr=["0-50","50-100","100-150","150-200","200-250","250-300","300-350","350-400","400-450","450-500","500以上"] -# 统计每个价格区间的数量 -for price in prices: - for i in range(len(price_intervals) - 1): - if price>=500: - price_counts[len(price_intervals) - 1] += 1 - break - if price_intervals[i] <= price and price < price_intervals[i + 1]: - price_counts[i] += 1 - break -# print(price_counts) -# 生成价格区间与书籍数量折线图 -line = ( - Line() - .add_xaxis([str(interval) for interval in prices_intervalsStr[:-1]]) # X轴标签为价格区间 - .add_yaxis("书籍数量", price_counts, symbol="circle", is_smooth=True, markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")])) - .set_global_opts(title_opts=opts.TitleOpts(title="价格区间与书籍数量折线图", pos_left="center",pos_bottom="bottom"), - xaxis_opts=opts.AxisOpts(name="价格区间"), - yaxis_opts=opts.AxisOpts(name="书籍数量"), - datazoom_opts=opts.DataZoomOpts(range_start=0, range_end=100),) -) - -# 生成时间与书籍数量折线图# 假设您的书籍数据保存在book_list_data中 -# 提取每本书的出版年份 -publish_dates = [int(book.pub_year.replace('-', '.').split('.')[0]) for book in book_list_data] -print(publish_dates) -# 使用Counter来计算每年出版的书的数量 -publish_year_counter = Counter(publish_dates) -print(publish_year_counter) -# 确保结果包含连续的年份范围,并且将缺失的年份对应的数量设为 0 -full_year_range = range(min(publish_dates), max(publish_dates) + 1) -print(full_year_range) -pub_year_counts = [(year, publish_year_counter[year]) for year in full_year_range] -# 提取年份和对应的书籍数量 -years = [str(year) for year, count in pub_year_counts] -counts = [count for year, count in pub_year_counts] -print(pub_year_counts) -# -# # 创建动态的时间曲线图 -# line_year_count = ( -# Line() -# .add_xaxis(xaxis_data=years) -# .add_yaxis( -# series_name="出版数量", -# y_axis=counts, -# ) -# .set_global_opts( -# title_opts=opts.TitleOpts(title="每年出版书籍数量变化"), -# xaxis_opts=opts.AxisOpts(name="年份"), -# yaxis_opts=opts.AxisOpts(name="书籍数量"), -# datazoom_opts=opts.DataZoomOpts(type_="inside"), -# tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"), -# ) -# ) - -# timeline = Timeline() -# for i, year in enumerate(years): -line_year_count = ( -Line() - .add_xaxis(years) - .add_yaxis( - series_name="出版书籍数量", - y_axis=counts, - markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max", name="最大值"), - opts.MarkPointItem(type_="min", name="最小值")]), - markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average", name="平均值")]), - ) - .set_global_opts(title_opts=opts.TitleOpts(title="年份与出版书籍数量变化"), - xaxis_opts=opts.AxisOpts(name="年份"), - yaxis_opts=opts.AxisOpts(name="书籍数量"), + publisher_list = [book.publisher for book in book_list_data] + # 使用Counter来计算每个出版商的数量 + publisher_counter = Counter(publisher_list) + publisher_names = list(publisher_counter.keys()) + publisher_counts = list(publisher_counter.values()) + colors = [ + "#5470c6", "#91cc75", "#fac858", "#ee6666", "#73c0de", + "#3ba272", "#fc8452", "#9a60b4", "#ea7ccc", "#bb60b4", + "#8B008B", "#FF1493", "#1E90FF", "#20B2AA", "#2E8B57", + "#B22222", "#FF4500", "#4682B4", "#DAA520", "#32CD32" + ] + + # 使用Pyecharts创建饼图 + pie = ( + Pie() + .add("", [list(z) for z in zip(publisher_names, publisher_counts)]) + .set_colors(colors) # 设置颜色 + .set_global_opts(title_opts=opts.TitleOpts(title="出版商分布饼图", pos_left="center", pos_bottom="bottom")) + .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}")) ) - + prices = [float(book.price) for book in book_list_data] + print(prices) + # 将价格分组到不同的区间 + price_intervals = [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, float('inf')] # 设置价格区间 + price_counts = [0] * (len(price_intervals) - 1) # 初始化每个区间的计数为0 + prices_intervalsStr = ["0-50", "50-100", "100-150", "150-200", "200-250", "250-300", "300-350", "350-400", + "400-450", "450-500", "500以上"] + # 统计每个价格区间的数量 + for price in prices: + for i in range(len(price_intervals) - 1): + if price >= 500: + price_counts[len(price_intervals) - 1] += 1 + break + if price_intervals[i] <= price and price < price_intervals[i + 1]: + price_counts[i] += 1 + break + # print(price_counts) + # 生成价格区间与书籍数量折线图 + line = ( + Line() + .add_xaxis([str(interval) for interval in prices_intervalsStr[:-1]]) # X轴标签为价格区间 + .add_yaxis("书籍数量", price_counts, symbol="circle", is_smooth=True, + markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")])) + .set_global_opts( + title_opts=opts.TitleOpts(title="价格区间与书籍数量折线图", pos_left="center", pos_bottom="bottom"), + xaxis_opts=opts.AxisOpts(name="价格区间"), + yaxis_opts=opts.AxisOpts(name="书籍数量"), + datazoom_opts=opts.DataZoomOpts(range_start=0, range_end=100), ) ) -# timeline.add(line_year_count, time_point=str(year)) -# timeline.add_schema( -# play_interval=1000, # 播放的时间间隔 -# is_auto_play=False, # 是否自动播放 -# pos_left="center", # 时间轴组件的位置 -# pos_bottom="bottom", -# ) - - - -# 生成html文件(可选) -# pie.render("publisher_pie_chart.html") -# 创建一个页面 -page = Page() -# 将柱状图和饼图添加到页面中 -page.add(line_year_count) -page.add(bar) -page.add(pie) -page.add(line) -# 生成HTML文件 -page.render("book_analysis.html") + # 生成时间与书籍数量折线图# 假设您的书籍数据保存在book_list_data中 + # 提取每本书的出版年份 + publish_dates = [int(book.pub_year.replace('-', '.').split('.')[0]) for book in book_list_data] + print(publish_dates) + # 使用Counter来计算每年出版的书的数量 + publish_year_counter = Counter(publish_dates) + print(publish_year_counter) + # 确保结果包含连续的年份范围,并且将缺失的年份对应的数量设为 0 + full_year_range = range(min(publish_dates), max(publish_dates) + 1) + print(full_year_range) + pub_year_counts = [(year, publish_year_counter[year]) for year in full_year_range] + + # 提取年份和对应的书籍数量 + years = [str(year) for year, count in pub_year_counts] + counts = [count for year, count in pub_year_counts] + print(pub_year_counts) + + line_year_count = ( + Line() + .add_xaxis(years) + .add_yaxis( + series_name="出版书籍数量", + y_axis=counts, + markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max", name="最大值"), + opts.MarkPointItem(type_="min", name="最小值")]), + markline_opts=opts.MarkLineOpts(data=[opts.MarkLineItem(type_="average", name="平均值")]), + ) + .set_global_opts(title_opts=opts.TitleOpts(title="年份与出版书籍数量变化"), + xaxis_opts=opts.AxisOpts(name="年份"), + yaxis_opts=opts.AxisOpts(name="书籍数量"), + ) + ) + # 创建一个页面 + page = Page() + # 将柱状图和饼图添加到页面中 + page.add(line_year_count) + page.add(bar) + page.add(pie) + page.add(line) + # 生成HTML文件 + page.render("book_analysis.html") \ No newline at end of file diff --git a/Python程序设计课程设计报告模板 2024年.doc b/Python程序设计课程设计报告模板 2024年.doc index 5b1f3c0..77fa5b0 100644 Binary files a/Python程序设计课程设计报告模板 2024年.doc and b/Python程序设计课程设计报告模板 2024年.doc differ diff --git a/book_analysis.html b/book_analysis.html deleted file mode 100644 index 3d28b63..0000000 --- a/book_analysis.html +++ /dev/null @@ -1,1130 +0,0 @@ - - -
- -