'commit'
This commit is contained in:
@@ -8,15 +8,15 @@ router = APIRouter(prefix="/RuYuanZaiYuan", tags=["入校、在校人数统计"]
|
||||
|
||||
@router.get("/school/chart")
|
||||
async def get_education_chart_config(
|
||||
education_stage: str = Query(default="preschool", pattern="^(preschool|primary|junior|senior)$",
|
||||
description="教育阶段: preschool(学前), primary(小学), junior(初中), senior(高中)")
|
||||
education_stage: str = Query(default="preschool", pattern="^(preschool|primary|junior|senior|vocational)$",
|
||||
description="教育阶段: preschool(学前), primary(小学), junior(初中), senior(高中), vocational(中职)")
|
||||
):
|
||||
return RuYuanZaiYuanModel.generate_preschool_education_config(education_stage)
|
||||
|
||||
@router.get("/school/inschool/chart")
|
||||
async def get_in_school_chart_config(
|
||||
education_stage: str = Query(default="preschool", pattern="^(preschool|primary|junior|senior)$",
|
||||
description="教育阶段: preschool(学前), primary(小学), junior(初中), senior(高中)")
|
||||
education_stage: str = Query(default="preschool", pattern="^(preschool|primary|junior|senior|vocational)$",
|
||||
description="教育阶段: preschool(学前), primary(小学), junior(初中), senior(高中), vocational(中职)")
|
||||
):
|
||||
return RuYuanZaiYuanModel.generate_in_school_education_config(education_stage)
|
||||
|
||||
|
Binary file not shown.
@@ -7,7 +7,8 @@ class RuYuanZaiYuanModel:
|
||||
'preschool': '学前',
|
||||
'primary': '小学',
|
||||
'junior': '初中',
|
||||
'senior': '高中'
|
||||
'senior': '高中',
|
||||
'vocational': '中职'
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
@@ -52,12 +53,21 @@ class RuYuanZaiYuanModel:
|
||||
for year in years:
|
||||
# 使用传入的教育阶段参数
|
||||
enroll_data = yunnan_enroll["education_data"].get(education_stage, {}).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) # 转换为万人
|
||||
# 计算总和作为总人数
|
||||
calculated_total = enroll_data.get("urban", 0) + enroll_data.get("town", 0) + enroll_data.get("rural", 0)
|
||||
total_enroll.append(calculated_total / 10000) # 转换为万人
|
||||
|
||||
# 特殊处理中职数据格式(只有total字段)
|
||||
if education_stage == 'vocational':
|
||||
total_value = enroll_data.get("total", 0)
|
||||
urban_data.append(0) # 中职没有城区数据
|
||||
town_data.append(0) # 中职没有镇区数据
|
||||
rural_data.append(0) # 中职没有乡村数据
|
||||
total_enroll.append(total_value / 10000) # 转换为万人
|
||||
else:
|
||||
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) # 转换为万人
|
||||
# 计算总和作为总人数
|
||||
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"
|
||||
@@ -99,32 +109,33 @@ class RuYuanZaiYuanModel:
|
||||
if not yunnan_in_school:
|
||||
return {}
|
||||
|
||||
# 提取年份数据(2015-2024)
|
||||
years = [str(year) for year in range(2015, 2025)]
|
||||
|
||||
# 构建数据
|
||||
# 构建在校生数据
|
||||
urban_data = [] # 城区数据
|
||||
town_data = [] # 镇区数据
|
||||
rural_data = [] # 乡村数据
|
||||
total_in_school = [] # 总人数
|
||||
|
||||
# 提取年份数据(2015-2024)
|
||||
years = [str(year) for year in range(2015, 2025)]
|
||||
|
||||
for year in years:
|
||||
# 使用传入的教育阶段参数
|
||||
in_school_year_data = yunnan_in_school["student_data"].get(education_stage, {}).get(year, {})
|
||||
|
||||
# 先获取原始数据
|
||||
urban_val = in_school_year_data.get("urban", 0)
|
||||
town_val = in_school_year_data.get("town", 0)
|
||||
rural_val = in_school_year_data.get("rural", 0)
|
||||
|
||||
# 转换为万人并添加到各自列表
|
||||
urban_data.append(urban_val / 10000) # 转换为万人
|
||||
town_data.append(town_val / 10000) # 转换为万人
|
||||
rural_data.append(rural_val / 10000) # 转换为万人
|
||||
|
||||
# 计算总和并转换为万人
|
||||
calculated_total = (urban_val + town_val + rural_val) / 10000 # 先计算总和再转换为万人
|
||||
total_in_school.append(calculated_total)
|
||||
|
||||
# 特殊处理中职数据格式(只有total字段)
|
||||
if education_stage == 'vocational':
|
||||
total_value = in_school_year_data.get("total", 0)
|
||||
urban_data.append(0) # 中职没有城区数据
|
||||
town_data.append(0) # 中职没有镇区数据
|
||||
rural_data.append(0) # 中职没有乡村数据
|
||||
total_in_school.append(total_value / 10000) # 转换为万人
|
||||
else:
|
||||
urban_data.append(in_school_year_data.get("urban", 0) / 10000) # 转换为万人
|
||||
town_data.append(in_school_year_data.get("town", 0) / 10000) # 转换为万人
|
||||
rural_data.append(in_school_year_data.get("rural", 0) / 10000) # 转换为万人
|
||||
# 计算总和作为总人数
|
||||
calculated_total = in_school_year_data.get("urban", 0) + in_school_year_data.get("town", 0) + in_school_year_data.get("rural", 0)
|
||||
total_in_school.append(calculated_total / 10000) # 转换为万人
|
||||
|
||||
# 添加2022年基数的粉色折线
|
||||
base_year = "2022"
|
||||
|
Binary file not shown.
@@ -11,7 +11,8 @@ test_education_stages = [
|
||||
("preschool", "学前"),
|
||||
("primary", "小学"),
|
||||
("junior", "初中"),
|
||||
("senior", "高中")
|
||||
("senior", "高中"),
|
||||
("vocational", "中职") # 添加中职教育阶段
|
||||
]
|
||||
|
||||
# 测试年份
|
||||
|
Reference in New Issue
Block a user