目录
1 问题描述 2
2 需求分析 2
2.1 数据需求 2
2.2 功能需求 2
2.3 非功能需求 2
3 概要设计 3
3.1抽象数据类型 3
3.2 总体设计 3
3.3 功能模块设计 4
3.4 用户界面设计 4
4 详细设计及系统实现 4
4.1 存储结构 4
4.2 核心算法 4
4.3 各功能实现 5
5 系统调试分析 10
6 课程设计总结 12
参考文献 12
附录:源码以及其它相关材料 13
2 需求分析
本系统的目标是搜集相关国家往年的GDP情况并以合适的形式显示数据(如折线图、饼图等)并计算相关指标(如GDP增速、人均GDP、GDP各项占比),然后通过分析影响GDP的各项指标及各行业对GDP的贡献占比,对未来发展提出建设性意见,如通过预测下一年的GDP各行占比来调整行业结构;下一年政府在各行业的投资占比等。
2.1 数据需求
本系统需要将从互联网站上或搜索引擎中获取的GDP相关各项数据作为输入数据,如第一、二、三产业对GDP的贡献率等,数据包含较大的整数和带小数点的百分比数。而输出数据则是以图中的以及表格中的数据来输出。
2.2 功能需求
本系统功能包括四个模块:
输入模块:从文件或直接从网站上读取相关信息;
输出模块:以多种形式保存结果(如以饼图、柱状图、折线图等显示各行业对GDP的贡献、根据相关数据预测的结果等);
显示模块:实现可视化系统;
预测模块:使用数据计算参数(如GDP增长率、人均GDP等),并根据计算的参数对下一年的发展情况作出预测(如下一年的GDP、政府下一年在某一行业的支出等)。
各功能模块实现
输入模块:“readSheetInExcel”
import pandas as pd
def read_sheet_columns_to_dict(file_path, sheet_name, column1_name, column2_name):
df = pd.read_excel(file_path, sheet_name=sheet_name)
column1_data = df[column1_name].tolist()
column2_data = df[column2_name].tolist()
data_dict = {}
data_dict[column1_name] = column1_data
data_dict[column2_name] = column2_data
return data_dict
if __name__ == "__main__":
excel_file_path = "gdp.xlsx"
sheet_name = "中国"
column1_name = "year"
column2_name = "GDP"
result_dict = read_sheet_columns_to_dict(excel_file_path, sheet_name, column1_name, column2_name)
print(result_dict)
输出模块:“chinaView、usaView、indeaView、FranchView”(以chinaView为例,包含菜单设计)
import tkinter as tk
import functools
import makePlot
class ChinaWindow(tk.Toplevel):
def __init__(self, parent, data_frame):
super().__init__(parent)
self.title("中国")
self.geometry("600x400")
self.label = tk.Label(self, text="中国自 2000 年到 2022 年 GDP 情况")
self.label.pack(pady=20)
data_frame1 = data_frame[0]
data_frame2 = data_frame[1]
data_frame3 = data_frame[2]
data_frame4 = data_frame[3]
data_frame5 = data_frame[4]
data_frame6 = data_frame[5]
ChinaWindow.year_gdp(self, data_frame1)
ChinaWindow.year_persongdp(self, data_frame2)
ChinaWindow.year_gdpworld(self, data_frame3)
ChinaWindow.year_one(self, data_frame4)
ChinaWindow.year_two(self, data_frame5)
ChinaWindow.year_three(self, data_frame6)
def year_gdp(self, data_frame):
self.gdp_button = tk.Button(self, text="全国GDP情况", command=functools.partial(makePlot.create_line_chart, data_frame))
self.gdp_button.pack(pady=10)
def year_persongdp(self, data_frame):
self.gdp_button = tk.Button(self, text="人均GDP情况", command=functools.partial(makePlot.create_line_chart, data_frame))
self.gdp_button.pack(pady=10)
def year_gdpworld(self, data_frame):
self.gdp_button = tk.Button(self, text="GDP占全世界情况", command=functools.partial(makePlot.create_line_chart, data_frame))
self.gdp_button.pack(pady=10)
def year_one(self, data_frame):
self.first_button = tk.Button(self, text="第一产业GDP", command=functools.partial(makePlot.create_line_chart, data_frame))
self.first_button.pack(pady=10)
def year_two(self, data_frame):
self.second_button = tk.Button(self, text="第二产业GDP", command=functools.partial(makePlot.create_line_chart, data_frame))
self.second_button.pack(pady=10)
def year_three(self, data_frame):
self.thirdly_button = tk.Button(self, text="第三产业GDP", command=functools.partial(makePlot.create_line_chart, data_frame))
self.thirdly_button.pack(pady=20)
“duibiFranch、duibiIndea、duibiUsa”(对比,以duibiFranch为例,包含菜单设计)
import tkinter as tk
import functools
import makeBar
class duibiWindow(tk.Toplevel):
def __init__(self, parent, data_frame):
super().__init__(parent)
self.title("对比法国")
self.geometry("600x400")
self.label = tk.Label(self, text="中国对比法国自 2000 年到 2022 年 GDP 情况")
self.label.pack(pady=20)
data_frame1 = data_frame[0]
data_frame2 = data_frame[1]
data_frame3 = data_frame[2]
data_frame4 = data_frame[3]
data_frame5 = data_frame[4]
data_frame6 = data_frame[5]
data_frame11 = data_frame[6]
data_frame21 = data_frame[7]
data_frame31 = data_frame[8]
data_frame41 = data_frame[9]
data_frame51 = data_frame[10]
data_frame61 = data_frame[11]
data_frame1_ = [data_frame1, data_frame11]
data_frame2_ = [data_frame2, data_frame21]
data_frame3_ = [data_frame3, data_frame31]
data_frame4_ = [data_frame4, data_frame41]
data_frame5_ = [data_frame5, data_frame51]
data_frame6_ = [data_frame6, data_frame61]
duibiWindow.year_gdp(self, data_frame1_)
duibiWindow.year_persongdp(self, data_frame2_)
duibiWindow.year_gdpworld(self, data_frame3_)
duibiWindow.year_one(self, data_frame4_)
duibiWindow.year_two(self, data_frame5_)
duibiWindow.year_three(self, data_frame6_)
def year_gdp(self, data_frame):
self.gdp_button = tk.Button(self, text="对比全国GDP情况", command=functools.partial(makeBar.create_bar_chart, data_frame))
self.gdp_button.pack(pady=10)
def year_persongdp(self, data_frame):
self.gdp_button = tk.Button(self, text="对比人均GDP情况", command=functools.partial(makeBar.create_bar_chart, data_frame))
self.gdp_button.pack(pady=10)
def year_gdpworld(self, data_frame):
self.gdp_button = tk.Button(self, text="对比GDP占全世界情况", command=functools.partial(makeBar.create_bar_chart, data_frame))
self.gdp_button.pack(pady=10)
def year_one(self, data_frame):
self.first_button = tk.Button(self, text="对比第一产业GDP情况", command=functools.partial(makeBar.create_bar_chart, data_frame))
self.first_button.pack(pady=10)
def year_two(self, data_frame):
self.second_button = tk.Button(self, text="对比第二产业GDP情况", command=functools.partial(makeBar.create_bar_chart, data_frame))
self.second_button.pack(pady=10)
def year_three(self, data_frame):
self.thirdly_button = tk.Button(self, text="对比第三产业GDP情况", command=functools.partial(makeBar.create_bar_chart, data_frame))
self.thirdly_button.pack(pady=20)
显示模块:“makebar”
import pandas as pd
import matplotlib.pyplot as plt
def create_bar_chart(df):
df1 = df[0]
df2 = df[1]
# 从 DataFrame 获取列名
columns_df1 = df1.columns.tolist()
columns_df2 = df2.columns.tolist()
# 确定排除第一列后的列名列表
x_column = columns_df1[0]
columns_df1 = columns_df1[1:]
columns_df2 = columns_df2[1:]
# 设置柱状图的宽度
width = 0.4
# 构造柱状图
plt.figure(figsize=(8, 6))
x_df1 = range(len(df1))
x_df2 = [x + width for x in range(len(df2))]
for i, column_name in enumerate(columns_df1):
plt.bar(x_df1, df1[column_name], width=width, label='china')
plt.bar(x_df2, df2[column_name], width=width, label='country')
# 设置 x 轴的刻度
x_ticks = [x + width / 2 for x in range(len(df1))]
plt.xticks(x_ticks, df1[x_column])
# 添加图例
plt.legend()
# 添加标题和轴标签
plt.title('Comparison of Two DataFrames')
plt.xlabel(x_column)
plt.ylabel('Values')
# 显示柱状图
plt.show()
“makePlot”
import pandas as pd
import matplotlib.pyplot as plt
def create_line_chart(data_frame):
cn = []
for column_name, column_data in data_frame.items():
cn.append(column_name)
data_frame.plot(x=cn[0], y=cn[1], kind='line', figsize=(10, 6))
plt.title('Line Chart')
plt.xlabel(cn[0])
plt.ylabel(cn[1])
plt.grid(True)
plt.legend()
plt.show()
“makePipe”(未完成)
import pandas as pd
import matplotlib.pyplot as plt
def create_pie_chart_from_data(data_frame):
categories = data_frame['Category']
values = data_frame['Value']
plt.figure(figsize=(8, 8))
plt.pie(values, labels=categories, autopct='%1.1f%%')
plt.title('Pie Chart')
plt.show()