'commit'
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, Query
|
||||
|
||||
from Model.RuYuanZaiYuanCountModel import RuYuanZaiYuanModel
|
||||
|
||||
@@ -10,12 +10,19 @@ router = APIRouter(prefix="/RuYuanZaiYuan", tags=["大屏展示"])
|
||||
async def root():
|
||||
return {"message": "Welcome to YunNan Education World!"}
|
||||
|
||||
@router.get("/school/preschool/chart")
|
||||
async def get_preschool_education_chart_config():
|
||||
return RuYuanZaiYuanModel.generate_preschool_education_config()
|
||||
@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(高中)")
|
||||
):
|
||||
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(高中)")
|
||||
):
|
||||
return RuYuanZaiYuanModel.generate_in_school_education_config(education_stage)
|
||||
|
||||
@router.get("/school/preschool/inschool/chart")
|
||||
async def get_preschool_in_school_chart_config():
|
||||
return RuYuanZaiYuanModel.generate_in_school_education_config()
|
||||
|
||||
|
||||
|
Binary file not shown.
@@ -1,14 +1,15 @@
|
||||
import json
|
||||
from pyecharts import options as opts
|
||||
from pyecharts.charts import Bar, Line
|
||||
from pyecharts.globals import CurrentConfig
|
||||
|
||||
from Config.Config import ONLINE_HOST
|
||||
|
||||
CurrentConfig.ONLINE_HOST = ONLINE_HOST
|
||||
|
||||
|
||||
class RuYuanZaiYuanModel:
|
||||
# 定义支持的教育阶段映射
|
||||
EDUCATION_STAGES = {
|
||||
'preschool': '学前',
|
||||
'primary': '小学',
|
||||
'junior': '初中',
|
||||
'senior': '高中'
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def load_student_data():
|
||||
try:
|
||||
@@ -26,7 +27,11 @@ class RuYuanZaiYuanModel:
|
||||
return [], []
|
||||
|
||||
@staticmethod
|
||||
def generate_preschool_education_config():
|
||||
def generate_preschool_education_config(education_stage='preschool'):
|
||||
# 验证教育阶段参数
|
||||
if education_stage not in RuYuanZaiYuanModel.EDUCATION_STAGES:
|
||||
education_stage = 'preschool' # 默认使用学前
|
||||
|
||||
# 获取学前教育相关数据
|
||||
enrollment_data, in_school_data = RuYuanZaiYuanModel.load_student_data()
|
||||
# 提取云南省级数据
|
||||
@@ -39,17 +44,18 @@ class RuYuanZaiYuanModel:
|
||||
urban_data = [] # 城区数据
|
||||
town_data = [] # 镇区数据
|
||||
rural_data = [] # 乡村数据
|
||||
total_enroll = [] # 总入园数
|
||||
total_enroll = [] # 总人数
|
||||
|
||||
# 提取年份数据(2015-2024)
|
||||
years = [str(year) for year in range(2015, 2025)]
|
||||
|
||||
for year in years:
|
||||
enroll_data = yunnan_enroll["education_data"]["preschool"].get(year, {})
|
||||
# 使用传入的教育阶段参数
|
||||
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) # 转换为万人
|
||||
# 计算总和作为总入园数,而非使用文件中的total字段
|
||||
# 计算总和作为总人数
|
||||
calculated_total = enroll_data.get("urban", 0) + enroll_data.get("town", 0) + enroll_data.get("rural", 0)
|
||||
total_enroll.append(calculated_total / 10000) # 转换为万人
|
||||
|
||||
@@ -57,7 +63,7 @@ class RuYuanZaiYuanModel:
|
||||
base_year = "2022"
|
||||
# 找到2022年在years中的索引位置
|
||||
base_index = years.index(base_year) if base_year in years else 0
|
||||
# 获取2022年的总入园数作为基数
|
||||
# 获取2022年的总人数作为基数
|
||||
base_value = total_enroll[base_index] if base_index < len(total_enroll) else 0
|
||||
# 创建2022年基数折线数据(2022-2024年)
|
||||
base_2022_line = []
|
||||
@@ -67,18 +73,24 @@ class RuYuanZaiYuanModel:
|
||||
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年基数
|
||||
}
|
||||
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年基数
|
||||
"education_stage": RuYuanZaiYuanModel.EDUCATION_STAGES.get(education_stage, '学前') # 添加教育阶段名称
|
||||
}
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def generate_in_school_education_config():
|
||||
# 获取学前教育相关数据
|
||||
def generate_in_school_education_config(education_stage='preschool'):
|
||||
# 验证教育阶段参数
|
||||
if education_stage not in RuYuanZaiYuanModel.EDUCATION_STAGES:
|
||||
education_stage = 'preschool' # 默认使用学前
|
||||
|
||||
# 获取在校生相关数据
|
||||
enrollment_data, in_school_data = RuYuanZaiYuanModel.load_student_data()
|
||||
|
||||
# 提取云南省级数据
|
||||
@@ -90,15 +102,15 @@ class RuYuanZaiYuanModel:
|
||||
# 提取年份数据(2015-2024)
|
||||
years = [str(year) for year in range(2015, 2025)]
|
||||
|
||||
# 构建学前教育数据
|
||||
# 构建数据
|
||||
urban_data = [] # 城区数据
|
||||
town_data = [] # 镇区数据
|
||||
rural_data = [] # 乡村数据
|
||||
total_in_school = [] # 总在园数
|
||||
total_in_school = [] # 总人数
|
||||
|
||||
for year in years:
|
||||
# 将education_data改为student_data
|
||||
in_school_year_data = yunnan_in_school["student_data"]["preschool"].get(year, {})
|
||||
# 使用传入的教育阶段参数
|
||||
in_school_year_data = yunnan_in_school["student_data"].get(education_stage, {}).get(year, {})
|
||||
|
||||
# 先获取原始数据
|
||||
urban_val = in_school_year_data.get("urban", 0)
|
||||
@@ -118,7 +130,7 @@ class RuYuanZaiYuanModel:
|
||||
base_year = "2022"
|
||||
# 找到2022年在years中的索引位置
|
||||
base_index = years.index(base_year) if base_year in years else 0
|
||||
# 获取2022年的总在园数作为基数
|
||||
# 获取2022年的总人数作为基数
|
||||
base_value = total_in_school[base_index] if base_index < len(total_in_school) else 0
|
||||
# 创建2022年基数折线数据(2022-2024年)
|
||||
base_2022_line = []
|
||||
@@ -135,7 +147,8 @@ class RuYuanZaiYuanModel:
|
||||
"series_data_1": town_data,
|
||||
"series_data_2": rural_data,
|
||||
"series_data_3": total_in_school,
|
||||
"series_data_4": base_2022_line
|
||||
"series_data_4": base_2022_line,
|
||||
"education_stage": RuYuanZaiYuanModel.EDUCATION_STAGES.get(education_stage, '学前') # 添加教育阶段名称
|
||||
}
|
||||
|
||||
return data
|
||||
|
Binary file not shown.
@@ -166,7 +166,7 @@
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<script type="text/javascript" src="js/jquery.js"></script>
|
||||
<script type="text/javascript" src="js/jquery-3.7.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/echarts.min.js"></script>
|
||||
<script language="JavaScript" src="js/index.js"></script>
|
||||
<script language="JavaScript" src="js/data/index.js"></script>
|
||||
|
5
static/js/jquery.js
vendored
5
static/js/jquery.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user