This commit is contained in:
2025-09-11 14:32:15 +08:00
parent b9ac29c759
commit 0a51def80f
5 changed files with 40 additions and 148 deletions

View File

@@ -28,155 +28,46 @@ class RuYuanZaiYuanModel:
@staticmethod
def generate_preschool_education_config():
# 获取学前教育相关数据
enrollment_data, in_school_data = RuYuanZaiYuanModel.load_student_data()
# enrollment_data, in_school_data = RuYuanZaiYuanModel.load_student_data()
#
# # 提取云南省级数据
# yunnan_enroll = next((item for item in enrollment_data if item["area_name"] == "云南省"), None)
#
# if not yunnan_enroll:
# return {}
#
# # 提取年份数据(2015-2024)
# years = [str(year) for year in range(2015, 2025)]
#
# # 构建学前教育数据
# urban_data = [] # 城区数据
# town_data = [] # 镇区数据
# rural_data = [] # 乡村数据
# total_enroll = [] # 总入园数
#
# for year in years:
# enroll_data = yunnan_enroll["education_data"]["preschool"].get(year, {})
# urban_data.append(enroll_data.get("urban", 0) / 10000) # 转换为万人
# town_data.append(enroll_data.get("town", 0) / 10000) # 转换为万人
# rural_data.append(enroll_data.get("rural", 0) / 10000) # 转换为万人
# # 计算总和作为总入园数而非使用文件中的total字段
# calculated_total = enroll_data.get("urban", 0) + enroll_data.get("town", 0) + enroll_data.get("rural", 0)
# total_enroll.append(calculated_total / 10000) # 转换为万人
# 提取云南省级数据
yunnan_enroll = next((item for item in enrollment_data if item["area_name"] == "云南省"), None)
if not yunnan_enroll:
return {}
# 提取年份数据(2015-2024)
years = [str(year) for year in range(2015, 2025)]
# 构建学前教育数据
urban_data = [] # 城区数据
town_data = [] # 镇区数据
rural_data = [] # 乡村数据
total_enroll = [] # 总入园数
for year in years:
enroll_data = yunnan_enroll["education_data"]["preschool"].get(year, {})
urban_data.append(enroll_data.get("urban", 0) / 10000) # 转换为万人
town_data.append(enroll_data.get("town", 0) / 10000) # 转换为万人
rural_data.append(enroll_data.get("rural", 0) / 10000) # 转换为万人
# 计算总和作为总入园数而非使用文件中的total字段
calculated_total = enroll_data.get("urban", 0) + enroll_data.get("town", 0) + enroll_data.get("rural", 0)
total_enroll.append(calculated_total / 10000) # 转换为万人
# 添加2022年基数的粉色折线
base_year = "2022"
# 找到2022年在years中的索引位置
base_index = years.index(base_year) if base_year in years else 0
# 获取2022年的总入园数作为基数
base_value = total_enroll[base_index] if base_index < len(total_enroll) else 0
# 创建2022年基数折线数据2022-2024年
base_2022_line = []
for i, year in enumerate(years):
# 只在2022年及之后显示基数线
if i >= base_index:
base_2022_line.append(base_value)
else:
base_2022_line.append(None) # 2022年之前不显示
# 构建ECharts配置
option = {
"grid": {
"left": 0,
"right": 0,
"top": 40,
"bottom": 10,
"containLabel": True,
},
"textStyle": {
"color": "#fff",
},
"tooltip": {
"trigger": "axis",
"axisPointer": {
"type": "cross",
"crossStyle": {"color": "#999"}
},
"textStyle": {"color": "#fff"},
"backgroundColor": "rgba(96,98,102,0.8)",
"borderColor": "rgba(255,255,255,0.3)",
"borderWidth": 1
},
"legend": {
"data": ["城区", "镇区", "乡村", "总入园数", "2022年基数(万人)"],
"top": 0,
"textStyle": {"color": "#fff"},
"icon": "roundRect",
"itemWidth": 12,
"itemHeight": 12
},
"xAxis": [
{
"type": "category",
"data": years,
"axisPointer": {"type": "shadow"},
"axisLine": {"lineStyle": {"color": "#fff"}},
"axisLabel": {"color": "#fff"},
"nameTextStyle": {"color": "#fff"}
xAxis = ["2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026"]
series_data_1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6]
series_data_2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6]
series_data_3 = [2.4, 5.2, 8.0, 25.4, 27.7, 73.7, 155.6]
series_data_4 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3]
line_data = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3]
data = {"xAxis": xAxis,
"series_data_1": series_data_1,
"series_data_2": series_data_2,
"series_data_3": series_data_3,
"series_data_4": series_data_4,
"line_data": line_data
}
],
"yAxis": [
{
"type": "value",
"min": 0,
"max": 25,
"interval": 5,
"axisLabel": {
"formatter": "{value}"
, "color": "#fff"
}
},
{
"type": "value",
"min": 0,
"max": 25,
"interval": 5,
"axisLabel": {"formatter": "{value}", "color": "#fff"},
},
],
"series": [
{
"name": "城区",
"type": "bar",
"tooltip": "{valueFormatter: (v) = > v 万人}",
"data": urban_data,
"itemStyle": {
"borderRadius": [6, 6, 0, 0],
}
},
{
"name": "镇区",
"type": "bar",
"data": town_data,
"tooltip": "{valueFormatter: (v) = > v 万人}",
"itemStyle": {
"borderRadius": [6, 6, 0, 0],
},
},
{
"name": "乡村",
"type": "bar",
"data": rural_data,
"tooltip": "{valueFormatter: (v) = > v 万人}",
"itemStyle": {
"borderRadius": [6, 6, 0, 0]
},
},
{
"name": "总入园数",
"type": "line",
"yAxisIndex": 1,
"data": total_enroll,
"tooltip": "{valueFormatter: (v) = > v 万人}",
},
# 添加2022年基数的粉色折线
{
"name": "2022年基数(万人)",
"type": "line",
"yAxisIndex": 1,
"data": base_2022_line,
"lineStyle": {"color": "#ff9e9e", "width": 2, "type": "solid"},
"tooltip": "{valueFormatter: (v) = > v 万人}",
}
]
}
return option
return data
@staticmethod
def generate_in_school_education_config():