diff --git a/main.py b/main.py index b67719f..fb7ba95 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ # from controller.SpyderController import SpyderController from controller.UIController import UIController +from entity.BilibiliVideo import BilibiliVideo from test.SpyderController_test import TestSpyderController # spyderController = SpyderController() @@ -8,4 +9,29 @@ uiController = UIController() if __name__ == '__main__': # print("this is main.py!") UI = UIController() + + test_cases = [ + BilibiliVideo("BV1a4411C7i2", "视频标题1", "https://www.bilibili.com/video/BV1a4411C7i2", 1648927200, 1, + 100000, 5000, 2000, 3000, 1000, 500, "up123456", "UP主A", 1000000), + BilibiliVideo("BV1F5411S8h3", "视频标题2", "https://www.bilibili.com/video/BV1F5411S8h3", 1648830800, 2, + 80000, 4000, 1500, 2000, 800, 400, "up234567", "UP主B", 800000), + BilibiliVideo("BV1bW411d9c4", "视频标题3", "https://www.bilibili.com/video/BV1bW411d9c4", 1648734400, 3, + 60000, 3000, 1000, 1500, 600, 300, "up345678", "UP主C", 600000), + BilibiliVideo("BV1qy411z5k5", "视频标题4", "https://www.bilibili.com/video/BV1qy411z5k5", 1648638000, 4, + 40000, 2000, 800, 1000, 400, 200, "up456789", "UP主D", 400000), + BilibiliVideo("BV1R4411J0a6", "视频标题5", "https://www.bilibili.com/video/BV1R4411J0a6", 1648541600, 5, + 20000, 1000, 500, 700, 200, 100, "up567890", "UP主E", 200000), + BilibiliVideo("BV1gW411H8d7", "视频标题6", "https://www.bilibili.com/video/BV1gW411H8d7", 1648445200, 6, + 10000, 500, 300, 400, 100, 50, "up678901", "UP主F", 100000), + BilibiliVideo("BV1py411t6v8", "视频标题7", "https://www.bilibili.com/video/BV1py411t6v8", 1648348800, 7, + 5000, 300, 200, 300, 50, 30, "up789012", "UP主G", 50000), + BilibiliVideo("BV1Qy411S3x9", "视频标题8", "https://www.bilibili.com/video/BV1Qy411S3x9", 1648252400, 8, + 2000, 100, 100, 200, 20, 10, "up890123", "UP主H", 20000), + BilibiliVideo("BV1a4411C4y0", "视频标题9", "https://www.bilibili.com/video/BV1a4411C4y0", 1648156000, 9, + 1000, 50, 50, 100, 10, 5, "up901234", "UP主I", 10000), + BilibiliVideo("BV1F5411C2r1", "视频标题10", "https://www.bilibili.com/video/BV1F5411C2r1", 1648059600, + 10, 500, 30, 20, 50, 5, 3, "up012345", "UP主J", 5000) + ] + UI.scRuslt_data = test_cases + UI.main() \ No newline at end of file diff --git a/test/Excel_test.py b/test/Excel_test.py index 8dba95c..035a723 100644 --- a/test/Excel_test.py +++ b/test/Excel_test.py @@ -50,41 +50,41 @@ class TestExcel: write_to_excel(videos, "bilibili_videos.xlsx") pass - def test_WTExcel(): - # 测试数据 - test_cases = [ - BilibiliVideo("BV1a4411C7i2", "视频标题1", "https://www.bilibili.com/video/BV1a4411C7i2", 1648927200, 1, - 100000, 5000, 2000, 3000, 1000, 500, "up123456", "UP主A", 1000000), - BilibiliVideo("BV1F5411S8h3", "视频标题2", "https://www.bilibili.com/video/BV1F5411S8h3", 1648830800, 2, - 80000, 4000, 1500, 2000, 800, 400, "up234567", "UP主B", 800000), - BilibiliVideo("BV1bW411d9c4", "视频标题3", "https://www.bilibili.com/video/BV1bW411d9c4", 1648734400, 3, - 60000, 3000, 1000, 1500, 600, 300, "up345678", "UP主C", 600000), - BilibiliVideo("BV1qy411z5k5", "视频标题4", "https://www.bilibili.com/video/BV1qy411z5k5", 1648638000, 4, - 40000, 2000, 800, 1000, 400, 200, "up456789", "UP主D", 400000), - BilibiliVideo("BV1R4411J0a6", "视频标题5", "https://www.bilibili.com/video/BV1R4411J0a6", 1648541600, 5, - 20000, 1000, 500, 700, 200, 100, "up567890", "UP主E", 200000), - BilibiliVideo("BV1gW411H8d7", "视频标题6", "https://www.bilibili.com/video/BV1gW411H8d7", 1648445200, 6, - 10000, 500, 300, 400, 100, 50, "up678901", "UP主F", 100000), - BilibiliVideo("BV1py411t6v8", "视频标题7", "https://www.bilibili.com/video/BV1py411t6v8", 1648348800, 7, - 5000, 300, 200, 300, 50, 30, "up789012", "UP主G", 50000), - BilibiliVideo("BV1Qy411S3x9", "视频标题8", "https://www.bilibili.com/video/BV1Qy411S3x9", 1648252400, 8, - 2000, 100, 100, 200, 20, 10, "up890123", "UP主H", 20000), - BilibiliVideo("BV1a4411C4y0", "视频标题9", "https://www.bilibili.com/video/BV1a4411C4y0", 1648156000, 9, - 1000, 50, 50, 100, 10, 5, "up901234", "UP主I", 10000), - BilibiliVideo("BV1F5411C2r1", "视频标题10", "https://www.bilibili.com/video/BV1F5411C2r1", 1648059600, - 10, 500, 30, 20, 50, 5, 3, "up012345", "UP主J", 5000) - ] - - # 将测试数据写入 Excel 文件 - write_to_excel(test_cases, 'bilibili_videos.xlsx') - def test_c_r_a_update(): - - # 示例用法 - file_path = 'bilibili_videos.xlsx' # Excel 文件路径 - sheet_name = 'Sheet' # 工作表名称 - - tttt.calculate_ratio_and_update(file_path, sheet_name) - print("Data analysis written to the Excel file.") + def test_WTExcel(self): + # 测试数据 + test_cases = [ + BilibiliVideo("BV1a4411C7i2", "视频标题1", "https://www.bilibili.com/video/BV1a4411C7i2", 1648927200, 1, + 100000, 5000, 2000, 3000, 1000, 500, "up123456", "UP主A", 1000000), + BilibiliVideo("BV1F5411S8h3", "视频标题2", "https://www.bilibili.com/video/BV1F5411S8h3", 1648830800, 2, + 80000, 4000, 1500, 2000, 800, 400, "up234567", "UP主B", 800000), + BilibiliVideo("BV1bW411d9c4", "视频标题3", "https://www.bilibili.com/video/BV1bW411d9c4", 1648734400, 3, + 60000, 3000, 1000, 1500, 600, 300, "up345678", "UP主C", 600000), + BilibiliVideo("BV1qy411z5k5", "视频标题4", "https://www.bilibili.com/video/BV1qy411z5k5", 1648638000, 4, + 40000, 2000, 800, 1000, 400, 200, "up456789", "UP主D", 400000), + BilibiliVideo("BV1R4411J0a6", "视频标题5", "https://www.bilibili.com/video/BV1R4411J0a6", 1648541600, 5, + 20000, 1000, 500, 700, 200, 100, "up567890", "UP主E", 200000), + BilibiliVideo("BV1gW411H8d7", "视频标题6", "https://www.bilibili.com/video/BV1gW411H8d7", 1648445200, 6, + 10000, 500, 300, 400, 100, 50, "up678901", "UP主F", 100000), + BilibiliVideo("BV1py411t6v8", "视频标题7", "https://www.bilibili.com/video/BV1py411t6v8", 1648348800, 7, + 5000, 300, 200, 300, 50, 30, "up789012", "UP主G", 50000), + BilibiliVideo("BV1Qy411S3x9", "视频标题8", "https://www.bilibili.com/video/BV1Qy411S3x9", 1648252400, 8, + 2000, 100, 100, 200, 20, 10, "up890123", "UP主H", 20000), + BilibiliVideo("BV1a4411C4y0", "视频标题9", "https://www.bilibili.com/video/BV1a4411C4y0", 1648156000, 9, + 1000, 50, 50, 100, 10, 5, "up901234", "UP主I", 10000), + BilibiliVideo("BV1F5411C2r1", "视频标题10", "https://www.bilibili.com/video/BV1F5411C2r1", 1648059600, + 10, 500, 30, 20, 50, 5, 3, "up012345", "UP主J", 5000) + ] + + # 将测试数据写入 Excel 文件 + tttt.write_to_excel(test_cases, 'bilibili_videos.xlsx') + def test_c_r_a_update(self): + + # 示例用法 + file_path = 'bilibili_videos.xlsx' # Excel 文件路径 + sheet_name = 'Sheet' # 工作表名称 + + tttt.calculate_ratio_and_update(file_path, sheet_name) + print("Data analysis written to the Excel file.") diff --git a/tool/tttt.py b/tool/tttt.py index 37fce5a..48767eb 100644 --- a/tool/tttt.py +++ b/tool/tttt.py @@ -90,103 +90,103 @@ if __name__ == '__main__': +if __name__ == '__main__': + import openpyxl + from openpyxl.chart import ScatterChart, BarChart, AreaChart, Reference -import openpyxl -from openpyxl.chart import ScatterChart, BarChart, AreaChart, Reference - -# 读取Excel文件 -wb = openpyxl.load_workbook('bilibili_videos.xlsx') -ws = wb.active - -# 创建柱状图1 -bar_chart1 = BarChart() -bar_chart1.title = "观众对于视频的认可度" -bar_chart1.y_axis.title = "Data" -bar_chart1.x_axis.title = "Index" - -# 设置柱状图1数据 -bar_data1 = Reference(ws, min_col=17, min_row=2, max_row=ws.max_row) -bar_categories1 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) -bar_chart1.add_data(bar_data1, titles_from_data=True) -bar_chart1.set_categories(bar_categories1) - -# 添加柱状图1到工作表 -ws.add_chart(bar_chart1, "V1") - -# 创建柱状图 -bar_chart = BarChart() -bar_chart.title = "收益" -bar_chart.y_axis.title = "Data" -bar_chart.x_axis.title = "Index" - -# 设置柱状图数据 -bar_data = Reference(ws, min_col=18, min_row=2, max_row=ws.max_row) -bar_categories = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) -bar_chart.add_data(bar_data, titles_from_data=True) -bar_chart.set_categories(bar_categories) - -# 添加柱状图到工作表 -ws.add_chart(bar_chart, "AD1") - -# 创建面积图 -area_chart = AreaChart() -area_chart.title = "视频实用性" -area_chart.y_axis.title = "Data" -area_chart.x_axis.title = "Index" - -# 设置面积图数据 -area_data = Reference(ws, min_col=19, min_row=2, max_row=ws.max_row) -area_categories = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) -area_chart.add_data(area_data, titles_from_data=True) -area_chart.set_categories(area_categories) - -# 添加面积图到工作表 -ws.add_chart(area_chart, "AL1") - -# 创建柱状图 -bar_chart_2 = BarChart() -bar_chart_2.title = "视频惊艳程度" -bar_chart_2.y_axis.title = "Data" -bar_chart_2.x_axis.title = "Index" - -# 设置柱状图数据 -bar_data_2 = Reference(ws, min_col=20, min_row=2, max_row=ws.max_row) -bar_categories_2 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) -bar_chart_2.add_data(bar_data_2, titles_from_data=True) -bar_chart_2.set_categories(bar_categories_2) - -# 添加柱状图到工作表 -ws.add_chart(bar_chart_2, "AT1") - -# 创建柱状图 -bar_chart_3 = BarChart() -bar_chart_3.title = "视频的互动性" -bar_chart_3.y_axis.title = "Data" -bar_chart_3.x_axis.title = "Index" - -# 设置柱状图数据 -bar_data_3 = Reference(ws, min_col=21, min_row=2, max_row=ws.max_row) -bar_categories_3 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) -bar_chart_3.add_data(bar_data_3, titles_from_data=True) -bar_chart_3.set_categories(bar_categories_3) - -# 添加柱状图到工作表 -ws.add_chart(bar_chart_3, "BB1") - -# 保存Excel文件 -wb.save('bilibili_videos_with_charts.xlsx') - -def write_english_texts(file_path, sheet_name, texts): - # 打开 Excel 文件 - wb = openpyxl.load_workbook(file_path) - sheet = wb[sheet_name] - - # 循环写入不同的英文文本到第一行的第17到21列 - for i, text in enumerate(texts, start=17): - sheet.cell(row=1, column=i).value = text + # 读取Excel文件 + wb = openpyxl.load_workbook('bilibili_videos.xlsx') + ws = wb.active - # 保存文件 - wb.save(file_path) + # 创建柱状图1 + bar_chart1 = BarChart() + bar_chart1.title = "观众对于视频的认可度" + bar_chart1.y_axis.title = "Data" + bar_chart1.x_axis.title = "Index" + + # 设置柱状图1数据 + bar_data1 = Reference(ws, min_col=17, min_row=2, max_row=ws.max_row) + bar_categories1 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) + bar_chart1.add_data(bar_data1, titles_from_data=True) + bar_chart1.set_categories(bar_categories1) + + # 添加柱状图1到工作表 + ws.add_chart(bar_chart1, "V1") + + # 创建柱状图 + bar_chart = BarChart() + bar_chart.title = "收益" + bar_chart.y_axis.title = "Data" + bar_chart.x_axis.title = "Index" + + # 设置柱状图数据 + bar_data = Reference(ws, min_col=18, min_row=2, max_row=ws.max_row) + bar_categories = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) + bar_chart.add_data(bar_data, titles_from_data=True) + bar_chart.set_categories(bar_categories) + + # 添加柱状图到工作表 + ws.add_chart(bar_chart, "AD1") + + # 创建面积图 + area_chart = AreaChart() + area_chart.title = "视频实用性" + area_chart.y_axis.title = "Data" + area_chart.x_axis.title = "Index" + + # 设置面积图数据 + area_data = Reference(ws, min_col=19, min_row=2, max_row=ws.max_row) + area_categories = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) + area_chart.add_data(area_data, titles_from_data=True) + area_chart.set_categories(area_categories) + + # 添加面积图到工作表 + ws.add_chart(area_chart, "AL1") + + # 创建柱状图 + bar_chart_2 = BarChart() + bar_chart_2.title = "视频惊艳程度" + bar_chart_2.y_axis.title = "Data" + bar_chart_2.x_axis.title = "Index" + + # 设置柱状图数据 + bar_data_2 = Reference(ws, min_col=20, min_row=2, max_row=ws.max_row) + bar_categories_2 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) + bar_chart_2.add_data(bar_data_2, titles_from_data=True) + bar_chart_2.set_categories(bar_categories_2) + + # 添加柱状图到工作表 + ws.add_chart(bar_chart_2, "AT1") + + # 创建柱状图 + bar_chart_3 = BarChart() + bar_chart_3.title = "视频的互动性" + bar_chart_3.y_axis.title = "Data" + bar_chart_3.x_axis.title = "Index" + + # 设置柱状图数据 + bar_data_3 = Reference(ws, min_col=21, min_row=2, max_row=ws.max_row) + bar_categories_3 = Reference(ws, min_col=2, min_row=2, max_row=ws.max_row) + bar_chart_3.add_data(bar_data_3, titles_from_data=True) + bar_chart_3.set_categories(bar_categories_3) + + # 添加柱状图到工作表 + ws.add_chart(bar_chart_3, "BB1") + + # 保存Excel文件 + wb.save('bilibili_videos_with_charts.xlsx') + + def write_english_texts(file_path, sheet_name, texts): + # 打开 Excel 文件 + wb = openpyxl.load_workbook(file_path) + sheet = wb[sheet_name] + + # 循环写入不同的英文文本到第一行的第17到21列 + for i, text in enumerate(texts, start=17): + sheet.cell(row=1, column=i).value = text + + # 保存文件 + wb.save(file_path) file_path = 'bilibili_videos_with_charts.xlsx' # Excel 文件路径 @@ -200,6 +200,7 @@ english_texts = [ "interaction" ] # 要写入的英文文本列表 -write_english_texts(file_path, sheet_name, english_texts) +if __name__ == '__main__': + write_english_texts(file_path, sheet_name, english_texts) -print("Data analysis chart written to the Excel file.") \ No newline at end of file + print("Data analysis chart written to the Excel file.") \ No newline at end of file