This commit is contained in:
2025-09-11 14:59:21 +08:00
2 changed files with 44 additions and 37 deletions

View File

@@ -28,44 +28,51 @@ class RuYuanZaiYuanModel:
@staticmethod @staticmethod
def generate_preschool_education_config(): 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)
# 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) # 转换为万人
xAxis = ["2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026"] if not yunnan_enroll:
series_data_0 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6] return {}
series_data_1 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6]
series_data_2 = [2.4, 5.2, 8.0, 25.4, 27.7, 73.7, 155.6] # # 构建学前教育数据
series_data_3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3] urban_data = [] # 城区数据
series_data_4 = [None, None, None, None, None, None, None, 105.6714, 105.6714, 105.6714], town_data = [] # 镇区数据
data = {"xAxis_data": xAxis, rural_data = [] # 乡村数据
"series_data_0": series_data_0, total_enroll = [] # 总入园数
"series_data_1": series_data_1,
"series_data_2": series_data_2, # 提取年份数据(2015-2024)
"series_data_3": series_data_3, years = [str(year) for year in range(2015, 2025)]
"series_data_4": series_data_4
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年之前不显示
data = {"xAxis_data": years,
"series_data_0": urban_data, # 城区
"series_data_1": town_data, # 镇区
"series_data_2": rural_data, # 乡村
"series_data_3": total_enroll, # 总入园数
"series_data_4": base_2022_line # 2022年基数
} }
return data return data