diff --git a/Controller/BigScreenController.py b/Controller/BigScreenController.py index 867b40e..2d941f2 100644 --- a/Controller/BigScreenController.py +++ b/Controller/BigScreenController.py @@ -1,6 +1,7 @@ from fastapi import APIRouter import json from Model.RenkouModel import RenkouModel +from Model.RuYuanZaiYuanCount import RuYuanZaiYuanModel # 创建APIRouter实例 router = APIRouter(prefix="/bigscreen", tags=["大屏展示"]) @@ -18,3 +19,7 @@ async def get_population_chart_config(year: str = "2024"): async def get_urbanization_rate_chart_config(): return RenkouModel.generate_urbanization_rate_chart_config() +@router.get("/school/preschool/chart") +async def get_preschool_education_chart_config(): + return RuYuanZaiYuanModel.generate_preschool_education_config() + diff --git a/Log/option.txt b/Log/option.txt new file mode 100644 index 0000000..6aea73f --- /dev/null +++ b/Log/option.txt @@ -0,0 +1,112 @@ +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" }, + // 1. 背景色 + backgroundColor: "rgba(96,98,102,0.8)", // 半透明黑 + // 2. 边框 + 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: ["2019", "2021", "2022", "2023", "2024", "2025", "2026"], + axisPointer: { type: "shadow" }, + axisLine: { lineStyle: { color: "#fff" } }, + axisLabel: { color: "#fff" }, + nameTextStyle: { color: "#fff" }, + }, + ], + yAxis: [ + { + type: "value", + min: 0, + max: 250, + interval: 50, + 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: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6], + itemStyle: { + borderRadius: [6, 6, 0, 0], + }, + }, + { + name: "镇区", + type: "bar", + tooltip: { valueFormatter: (v) => v + " 万人" }, + data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6], + itemStyle: { + borderRadius: [6, 6, 0, 0], + }, + }, + { + name: "乡村", + type: "bar", + tooltip: { valueFormatter: (v) => v + " 万人" }, + data: [2.4, 5.2, 8.0, 25.4, 27.7, 73.7, 155.6], + itemStyle: { + borderRadius: [6, 6, 0, 0], + }, + }, + { + name: "总入园数", + type: "line", + yAxisIndex: 1, + tooltip: { valueFormatter: (v) => v + " 万人" }, + data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3], + }, + // 2. 新增折线 + { + name: "2022年基数", + type: "line", + yAxisIndex: 1, + tooltip: { valueFormatter: (v) => v + " 万人" }, + // 3. 数据整体 +0.8 + data: [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3].map((v) => + (v + 0.8).toFixed(1) + ), + }, + ], + }; \ No newline at end of file diff --git a/Model/RuYuanZaiYuanCount.py b/Model/RuYuanZaiYuanCount.py new file mode 100644 index 0000000..ce8a04e --- /dev/null +++ b/Model/RuYuanZaiYuanCount.py @@ -0,0 +1,156 @@ +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: + @staticmethod + def load_student_data(): + try: + # 加载招生数据(入园人数) + with open("./Data/ZhaoShengCount.json", "r", encoding="utf-8") as f: + enrollment_data = json.load(f) + + # 加载在校生数据(在园人数) + with open("./Data/ZaiXiaoShengCount.json", "r", encoding="utf-8") as f: + in_school_data = json.load(f) + + return enrollment_data, in_school_data + except Exception as e: + print(f"读取学生数据出错: {e}") + return [], [] + + @staticmethod + def generate_preschool_education_config(): + # 获取学前教育相关数据 + enrollment_data, in_school_data = RuYuanZaiYuanModel.load_student_data() + + # 提取云南省级数据 + yunnan_enroll = next((item for item in enrollment_data if item["area_name"] == "云南省"), None) + yunnan_in_school = next((item for item in in_school_data if item["area_name"] == "云南省"), None) + + if not yunnan_enroll or not yunnan_in_school: + return {} + + # 提取年份数据(2015-2024) + years = [str(year) for year in range(2015, 2025)] + + # 构建学前教育数据 + urban_enroll = [] # 城区入园人数 + town_enroll = [] # 镇区入园人数 + rural_enroll = [] # 乡村入园人数 + urban_in_school = [] # 城区在园人数 + town_in_school = [] # 镇区在园人数 + rural_in_school = [] # 乡村在园人数 + + for year in years: + # 入园人数(招生数据) + pre_enroll = yunnan_enroll.get("education_data", {}).get("preschool", {}).get(year, {}) + urban_enroll.append(pre_enroll.get("urban", 0)) + town_enroll.append(pre_enroll.get("town", 0)) + rural_enroll.append(pre_enroll.get("rural", 0)) + + # 在园人数(在校生数据) + pre_in_school = yunnan_in_school.get("education_data", {}).get("preschool", {}).get(year, {}) + urban_in_school.append(pre_in_school.get("urban", 0)) + town_in_school.append(pre_in_school.get("town", 0)) + rural_in_school.append(pre_in_school.get("rural", 0)) + + # 构建option数据结构 + 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": ["城区入园人数", "镇区入园人数", "乡村入园人数", + "城区在园人数", "镇区在园人数", "乡村在园人数"], + "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" }, + }, + ], + "yAxis": [ + { + "type": "value", + "axisLabel": { "formatter": "{value} 人", "color": "#fff" }, + } + ], + "series": [ + { + "name": "城区入园人数", + "type": "bar", + "data": urban_enroll, + "itemStyle": { "borderRadius": [6, 6, 0, 0] }, + }, + { + "name": "镇区入园人数", + "type": "bar", + "data": town_enroll, + "itemStyle": { "borderRadius": [6, 6, 0, 0] }, + }, + { + "name": "乡村入园人数", + "type": "bar", + "data": rural_enroll, + "itemStyle": { "borderRadius": [6, 6, 0, 0] }, + }, + { + "name": "城区在园人数", + "type": "line", + "data": urban_in_school, + "yAxisIndex": 0, + "lineStyle": { "width": 3 }, + "symbolSize": 8, + }, + { + "name": "镇区在园人数", + "type": "line", + "data": town_in_school, + "yAxisIndex": 0, + "lineStyle": { "width": 3 }, + "symbolSize": 8, + }, + { + "name": "乡村在园人数", + "type": "line", + "data": rural_in_school, + "yAxisIndex": 0, + "lineStyle": { "width": 3 }, + "symbolSize": 8, + } + ], + } + + return option \ No newline at end of file diff --git a/Tools/Full_Line.py b/Tools/Full_Line.py deleted file mode 100644 index e69de29..0000000