'commit'
This commit is contained in:
154
Test/education_resource_forecast.py
Normal file
154
Test/education_resource_forecast.py
Normal file
@@ -0,0 +1,154 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
# 设置中文字体支持(如果需要可视化)
|
||||
# import matplotlib.pyplot as plt
|
||||
# plt.rcParams["font.family"] = ["SimHei", "WenQuanYi Micro Hei", "Heiti TC"]
|
||||
|
||||
class EducationResourceForecast:
|
||||
def __init__(self):
|
||||
# 数据文件路径
|
||||
self.data_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'Data')
|
||||
# 教育阶段映射
|
||||
self.education_stages = {
|
||||
'preschool': '学前',
|
||||
'primary': '小学',
|
||||
'junior': '初中',
|
||||
'senior': '高中',
|
||||
'vocational': '中职'
|
||||
}
|
||||
# 预测年份范围
|
||||
self.forecast_years = list(range(2023, 2030)) # 2023-2029年
|
||||
# 加载数据
|
||||
self.teacher_data = self._load_data('TeacherCount.json')
|
||||
self.school_area_data = self._load_data('SchoolArea.json')
|
||||
# 存储预测结果
|
||||
self.forecast_results = {stage: [] for stage in self.education_stages.keys()}
|
||||
|
||||
def _load_data(self, filename):
|
||||
"""加载JSON数据文件"""
|
||||
import json
|
||||
file_path = os.path.join(self.data_dir, filename)
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
# 数据文件是数组格式,我们只需要云南省的数据
|
||||
for item in data:
|
||||
if item.get('area_name') == '云南省':
|
||||
return item
|
||||
return {}
|
||||
except Exception as e:
|
||||
print(f"加载文件 {filename} 失败: {e}")
|
||||
return {}
|
||||
|
||||
def _get_teacher_data_by_stage(self, stage):
|
||||
"""获取特定教育阶段的教师数据"""
|
||||
# 教师数据字段映射
|
||||
teacher_field_map = {
|
||||
'preschool': 'preschool_teachers',
|
||||
'primary': 'primary_teachers',
|
||||
'junior': 'junior_teachers',
|
||||
'senior': 'senior_teachers',
|
||||
'vocational': 'vocational_teachers'
|
||||
}
|
||||
|
||||
field = teacher_field_map.get(stage)
|
||||
if not field or field not in self.teacher_data:
|
||||
return []
|
||||
|
||||
teacher_data = []
|
||||
# 提取2015-2024年的专任教师数据
|
||||
for year in range(2015, 2025):
|
||||
year_data = self.teacher_data[field].get(str(year), {})
|
||||
# 优先使用专任教师数量
|
||||
teacher_count = year_data.get('total_teacher', 0)
|
||||
teacher_data.append({
|
||||
'year': year,
|
||||
'teacher_count': teacher_count
|
||||
})
|
||||
|
||||
return teacher_data
|
||||
|
||||
def _get_school_area_data_by_stage(self, stage):
|
||||
"""获取特定教育阶段的学校面积数据"""
|
||||
# 学校面积字段映射
|
||||
area_field_map = {
|
||||
'preschool': 'preschool_area',
|
||||
'primary': 'primary_area',
|
||||
'junior': 'junior_high_area', # 修正字段名
|
||||
'senior': 'senior_high_area', # 修正字段名
|
||||
'vocational': 'vocational_area'
|
||||
}
|
||||
|
||||
field = area_field_map.get(stage)
|
||||
if not field or field not in self.school_area_data:
|
||||
return []
|
||||
|
||||
area_data = []
|
||||
# 提取2015-2024年的学校面积数据
|
||||
for year in range(2015, 2025):
|
||||
year_data = self.school_area_data[field].get(str(year), {})
|
||||
# 优先使用教学面积,如果为0则使用学校总面积
|
||||
teaching_area = year_data.get('teaching_total', 0)
|
||||
if teaching_area == 0:
|
||||
teaching_area = year_data.get('school_total', 0)
|
||||
area_data.append({
|
||||
'year': year,
|
||||
'teaching_area': teaching_area
|
||||
})
|
||||
|
||||
return area_data
|
||||
|
||||
def forecast(self):
|
||||
"""执行预测"""
|
||||
for stage in self.education_stages.keys():
|
||||
# 获取历史数据
|
||||
teacher_history = self._get_teacher_data_by_stage(stage)
|
||||
area_history = self._get_school_area_data_by_stage(stage)
|
||||
|
||||
# 生成最终结果
|
||||
for year in self.forecast_years:
|
||||
if year <= 2024:
|
||||
# 2023-2024年使用实际数据
|
||||
# 查找实际教师数据
|
||||
teacher_item = next((item for item in teacher_history if item['year'] == year), None)
|
||||
teacher_count = teacher_item['teacher_count'] if teacher_item else 0
|
||||
|
||||
# 查找实际面积数据
|
||||
area_item = next((item for item in area_history if item['year'] == year), None)
|
||||
teaching_area = area_item['teaching_area'] if area_item else 0
|
||||
else:
|
||||
# 2025-2029年预测数据设为0
|
||||
teacher_count = 0
|
||||
teaching_area = 0
|
||||
|
||||
# 添加结果,师资缺口/富余字段暂时设为0
|
||||
self.forecast_results[stage].append({
|
||||
'year': year,
|
||||
'teacher_count': round(teacher_count / 10000, 2), # 转换为万人
|
||||
'teacher_gap': 0, # 师资缺口/富余暂时设为0
|
||||
'teaching_area': round(teaching_area / 10000, 2), # 转换为万平方米
|
||||
'is_forecast': year >= 2025 # 标记是否为预测数据
|
||||
})
|
||||
|
||||
def print_results(self):
|
||||
"""打印预测结果"""
|
||||
for stage, chinese_name in self.education_stages.items():
|
||||
print(f"\n{chinese_name}教育阶段资源配置预测(2023-2029年):")
|
||||
print("{:<8} {:<12} {:<16} {:<20} {:<10}".format("年份", "专任教师(万人)", "师资缺口/富余", "教学及辅助用房面积(万㎡)", "数据类型"))
|
||||
for item in self.forecast_results[stage]:
|
||||
data_type = "预测" if item['is_forecast'] else "实际"
|
||||
print("{:<8} {:<12.2f} {:<16.2f} {:<20.2f} {:<10}".format(
|
||||
item['year'],
|
||||
item['teacher_count'],
|
||||
item['teacher_gap'],
|
||||
item['teaching_area'],
|
||||
data_type
|
||||
))
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("开始执行教育资源配置发展预测...")
|
||||
forecast = EducationResourceForecast()
|
||||
forecast.forecast()
|
||||
forecast.print_results()
|
||||
print("\n预测完成!")
|
Reference in New Issue
Block a user