第四版_完整
This commit is contained in:
+37
-20
@@ -1,25 +1,18 @@
|
||||
# api/stats
|
||||
# 本文件定义统计分析相关的所有 API 路由(Controller 层)
|
||||
from itertools import count
|
||||
from pydoc import describe
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
from sqlalchemy import func
|
||||
from starlette import status
|
||||
|
||||
from database import get_db
|
||||
from dao.statistics_dao import StatisticsDao
|
||||
from model.stu_model import StuInfo
|
||||
from scheme.statistics_scheme import StatsResponse, StuInfoAllExamAboveScore, FailingStudentItem, ClassExamAvgScoreItem, \
|
||||
from scheme.statistics_scheme import ClassGenderDistributionItem, StuInfoAllExamAboveScore, FailingStudentItem, ClassExamAvgScoreItem, \
|
||||
TopSalaryStudentItem, StudentEmpDurationItem, ClassAvgEmpDurationItem, StudentAgeDetailItem
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
#### 2.6.1 基本信息动态统计
|
||||
# - **动态年龄范围查询**:支持用户输入年龄阈值及比较条件(如大于、小于、等于、区间等),动态查询符合条件的学员信息。
|
||||
# - **多维度班级统计**:统计每个班级的总人数,以及按性别(男、女)细分的人数分布。
|
||||
@router.get("/api/stats/students/age_filter",
|
||||
response_model=List[StudentAgeDetailItem],
|
||||
summary="动态年龄范围查询",
|
||||
@@ -47,20 +40,49 @@ def get_students_by_age_condition(db: Session = Depends(get_db),
|
||||
max_age = max_age)
|
||||
return data
|
||||
|
||||
|
||||
# **多维度班级统计**:统计每个班级的总人数,以及按性别(男、女)细分的人数分布。
|
||||
@router.get("/class/stats/gender",
|
||||
response_model=List[StatsResponse],
|
||||
@router.get("/api/stats/class/gender_distribution",
|
||||
response_model=List[ClassGenderDistributionItem],
|
||||
summary="班级性别统计",
|
||||
description="统计每个班级的总人数,以及按性别(男、女)细分的人数分布。")
|
||||
def get_class_stats(db: Session = Depends(get_db)):
|
||||
data = StatisticsDao.get_cls_stats(db)
|
||||
data = StatisticsDao.get_class_gender_distribution(db)
|
||||
return data
|
||||
|
||||
|
||||
#### 2.6.2 成绩综合统计: all
|
||||
@router.get("/class_score",
|
||||
summary="班级成绩综合统计",
|
||||
description= """
|
||||
1、查询每次考试成绩都在输入分数线(如80分)以上的学生的编号、姓名和成绩 -- 参数: 分数<br>
|
||||
2、查询有输入指定次数(如两次)以上不及格的学生的姓名、班级和不及格成绩明细 -- 参数: 不及格次数<br>
|
||||
3、统计每次考试每个班级的平均分,并支持按分数从高到低或从低到高动态排序 -- 参数: 1:低到高, 2:高到低<br>
|
||||
""")
|
||||
def get_students_all_exams_above_score(
|
||||
db: Session = Depends(get_db),
|
||||
choose: int = Query(..., ge=1, le=3, description="功能选择(1-3): 参考提示"),
|
||||
player_num: int | float = Query(..., ge=0, le=100, description="输入的具体参数,参考提示")
|
||||
):
|
||||
|
||||
if choose == 1:
|
||||
# 查询每次考试成绩都在输入分数线(如80分)以上的学生的编号、姓名和成绩 -- 参数: 分数
|
||||
if player_num > 100 or player_num < 0:
|
||||
raise HTTPException(status_code=400, detail="成绩需要在[0-100]区间")
|
||||
|
||||
data = StatisticsDao.get_stu_info_all_exams_above_score(db, player_num)
|
||||
elif choose == 2:
|
||||
# 2、查询有输入指定次数(如两次)以上不及格的学生的姓名、班级和不及格成绩明细 -- 参数: 不及格次数
|
||||
data = StatisticsDao.find_students_fail_count(db, player_num)
|
||||
elif choose == 3:
|
||||
# 统计每次考试每个班级的平均分,并支持按分数从高到低或从低到高动态排序 -- 参数: 1:低到高, 2:高到低
|
||||
data = StatisticsDao.find_class_exam_averages(db, player_num)
|
||||
|
||||
return data
|
||||
|
||||
# 2.6.2 单个接口详细版本
|
||||
"""
|
||||
#### 2.6.2 成绩综合统计
|
||||
# 1- 查询每次考试成绩都在输入分数线(如80分)以上的学生的编号、姓名和成绩。
|
||||
# 2- 查询有输入指定次数(如两次)以上不及格的学生的姓名、班级和不及格成绩明细。
|
||||
# 3- 统计每次考试每个班级的平均分,并支持按分数从高到低或从低到高动态排序。
|
||||
@router.get("/api/stats/students/all_exams_above_score",
|
||||
response_model = List[StuInfoAllExamAboveScore],
|
||||
summary="查询成绩在xx分以上的学生信息",
|
||||
@@ -95,13 +117,10 @@ def get_class_exams_avg_scores(
|
||||
):
|
||||
data = StatisticsDao.find_class_exam_averages(db, order_choose)
|
||||
return data
|
||||
|
||||
"""
|
||||
|
||||
#### 2.6.3 就业数据统计
|
||||
|
||||
# - 统计就业薪资排名 Top N(动态输入 N)的学生的姓名、班级、就业时间和就业公司。
|
||||
# - 统计每个学生的就业时长(计算公式:offer下发时间 - 就业开放时间)。
|
||||
# - 统计每个班级的平均就业时长(仅统计进入就业阶段,即有就业开放时间的学生)
|
||||
@router.get("/api/stats/employment/top_salaries",
|
||||
response_model=List[TopSalaryStudentItem],
|
||||
summary="就业薪资top_N",
|
||||
@@ -112,7 +131,6 @@ def get_top_salary_students(
|
||||
data = StatisticsDao.find_top_salary_students(db, top_n)
|
||||
return data
|
||||
|
||||
|
||||
# - 统计每个学生的就业时长(计算公式:offer下发时间 - 就业开放时间)。
|
||||
@router.get("/api/stats/employment/job_seeking_duration",
|
||||
response_model=List[StudentEmpDurationItem],
|
||||
@@ -122,7 +140,6 @@ def get_students_job_seeking_duration(db: Session = Depends(get_db)):
|
||||
data = StatisticsDao.find_students_employment_duration(db)
|
||||
return data
|
||||
|
||||
|
||||
# - 统计每个班级的平均就业时长(仅统计进入就业阶段,即有就业开放时间的学生)
|
||||
@router.get("/api/stats/class/avg_employment_duration",
|
||||
response_model=List[ClassAvgEmpDurationItem],
|
||||
|
||||
Reference in New Issue
Block a user