from fastapi import APIRouter, Query, Depends from sqlalchemy.orm import Session from dao.age_analysis import ( analysis_student_age, analysis_class_gender, analysis_score_over, analysis_score_not_qualified, analysis_avg_score_order, analysis_employment_salary_order, analysis_student_employment_time, avg_employment_time, ) from database import get_db from scheme.schema_analysis import ( StudentOut, StudentGenderOut, StudentRecordOut1, StudentRecordOut2, StudentRecordOut3, StudentRecordOut4, StudentRecordOut5, StudentRecordOut6, ) router = APIRouter() # 动态年龄范围查询:支持输入年龄阈值(大于等于/小于等于)动态查询学员信息 @router.get("/analysis_age", response_model=list[StudentOut]) async def analysis_age( db: Session = Depends(get_db), min_age: int | None = Query(None, ge=0, description="请输入查询年龄大于等于"), max_age: int | None = Query(None, ge=0, description="请输入查询年龄小于等于"), ): return analysis_student_age(db, min_age, max_age) # 统计每个班级的总人数,以及按性别(男、女)细分的人数分布 @router.get("/analysis_gender", response_model=list[StudentGenderOut]) async def analysis_gender(db: Session = Depends(get_db)): return analysis_class_gender(db) # 查询每次考试成绩都在输入分数线(如80分)以上的学生的编号、姓名和成绩 @router.get("/analysis_scores", response_model=list[StudentRecordOut1]) async def analysis_scores( db: Session = Depends(get_db), score: float = Query(0, ge=0, le=100, description="请输入查询学生每次考试分数在多少以上"), ): return analysis_score_over(db, score) # 查询有输入指定次数(如两次)以上不及格的学生的姓名、班级和不及格成绩明细 @router.get("/analysis_not_qualified", response_model=list[StudentRecordOut2]) async def analysis_not_qualified( db: Session = Depends(get_db), n: int = Query(1, ge=1, description="请输入不及格次数下限"), ): return analysis_score_not_qualified(db, n) # 统计每次考试每个班级的平均分,支持按分数从高到低或从低到高动态排序 @router.get("/analysis_avg_score", response_model=list[StudentRecordOut3]) async def analysis_avg_score( db: Session = Depends(get_db), sort: str = Query("asc", description="请输入排序类型 asc/desc"), ): return analysis_avg_score_order(db, sort) # 统计就业薪资排名 Top N(动态输入 N)的学生的姓名、班级、就业时间和就业公司 @router.get("/analysis_salary_top", response_model=list[StudentRecordOut4]) async def analysis_salary_top( db: Session = Depends(get_db), n: int = Query(1, ge=1, description="请输入取前几名薪资"), ): return analysis_employment_salary_order(db, n) # 统计每个学生的就业时长(offer下发时间 - 就业开放时间,单位秒) @router.get("/analysis_employment_time", response_model=list[StudentRecordOut5]) async def analysis_employment_time(db: Session = Depends(get_db)): return analysis_student_employment_time(db) # 统计每个班级的平均就业时长(仅统计进入就业阶段,即有就业开放时间的学生) @router.get("/analysis_avg_employment_time", response_model=list[StudentRecordOut6]) async def analysis_avg_employment_time(db: Session = Depends(get_db)): return avg_employment_time(db)