105 lines
5.1 KiB
Python
105 lines
5.1 KiB
Python
from fastapi import APIRouter, Depends, Query
|
||
from database import get_db
|
||
from dao.statistics_dao import StatisticsDao
|
||
from schema.statistics_schema import ResponseModel,ResponseModel1,ResponseModel2,ResponseModel3,ResponseModel4,ResponseModel5,ResponseModel6
|
||
from math import ceil
|
||
|
||
BasicInformationAPI = APIRouter(tags=['统计分析'])
|
||
|
||
@BasicInformationAPI.get('/basic-information',summary='查询年龄区间内的学员信息')
|
||
def get_students_by_age_range_api(
|
||
n:int=Query(..., description='页码,从1开始', ge=1),
|
||
m:int=Query(..., description='每页条数', ge=1),
|
||
min_age: int = Query(..., description='最小年龄', ge=0),
|
||
max_age: int = Query(..., description='最大年龄', le=100),
|
||
db = Depends(get_db)):
|
||
if min_age > max_age:
|
||
return {f'code=400,message=最小年龄不能大于最大年龄'}
|
||
|
||
req,total = StatisticsDao.get_students_by_age_range_dao(n,m,min_age, max_age,db)
|
||
|
||
return ResponseModel(code=200,
|
||
message='查询成功',
|
||
total=total,
|
||
total_pages=ceil(total/m) if total > 0 else 0,
|
||
data=req)
|
||
|
||
@BasicInformationAPI.get('/basic-information/{class_id}',summary='统计每个班级的⼈数以及男⽣/⼥⽣的⼈数')
|
||
def get_students_by_class_id_api(class_id:str,
|
||
db = Depends(get_db)):
|
||
total_count , male_count , female_count = StatisticsDao.get_students_by_class_id_dao(class_id,db)
|
||
return {f'code:200,message=查询成功, 全班总人数:{total_count}, 班级男生人数:{male_count}, 班级女生人数:{female_count}'}
|
||
|
||
|
||
@BasicInformationAPI.get('/scores',summary='在某个分数段的学生')
|
||
def get_students_by_score_api(
|
||
n:int=Query(..., description='页码,从1开始', ge=1),
|
||
m:int=Query(..., description='每页条数', ge=1),
|
||
score:float=Query(ge=0,le=100),
|
||
db = Depends(get_db)):
|
||
if score < 0 or score > 100:
|
||
return {f'code=400,message=分数需要在0~100!'}
|
||
req,total = StatisticsDao.get_students_by_score_dao(n,m,score,db)
|
||
return ResponseModel1(code=200,
|
||
message='查询成功',
|
||
total=total,
|
||
total_pages=ceil(total/m) if total > 0 else 0,
|
||
data=req)
|
||
|
||
@BasicInformationAPI.get('/scores_no_pass',summary='查询有n门成绩不合格的学生')
|
||
def get_students_by_no_pass_api(
|
||
n:int=Query(..., description='页码,从1开始', ge=1),
|
||
m:int=Query(..., description='每页条数', ge=1),
|
||
fail_count:int=Query(..., description='不及格门数', ge=1),
|
||
db = Depends(get_db)):
|
||
req,total = StatisticsDao.get_student_by_no_pass_dao(n,m,fail_count,db)
|
||
return ResponseModel2(code=200,
|
||
message='查询成功',
|
||
total=total,
|
||
total_pages=ceil(total/m) if total > 0 else 0,
|
||
data=req)
|
||
|
||
@BasicInformationAPI.get('/scores_avg', summary='统计每次考试每个班级的平均分(从高到低排序)')
|
||
def get_class_exam_avg_api(
|
||
n:int=Query(..., description='页码,从1开始', ge=1),
|
||
m:int=Query(..., description='每页条数', ge=1),
|
||
db = Depends(get_db)):
|
||
req,total = StatisticsDao.get_class_exam_avg_score_dao(n,m,db)
|
||
return ResponseModel3(code=200,
|
||
message='查询成功',
|
||
total=total,
|
||
total_pages=ceil(total/m) if total > 0 else 0,
|
||
data=req)
|
||
|
||
@BasicInformationAPI.get('/salary_top', summary='查询就业薪资最高的前五名学生')
|
||
def get_salary_top_api(
|
||
m:int=Query(5, description='查询前m名', ge=1),
|
||
db = Depends(get_db)):
|
||
req = StatisticsDao.get_salary_top_dao(m,db)
|
||
return ResponseModel4(code=200,
|
||
message='查询成功',
|
||
data=req)
|
||
|
||
@BasicInformationAPI.get('/time_size', summary='统计每个学生的就业时长(offer下发时间-就业开放时间)')
|
||
def get_time_size_api(
|
||
n:int=Query(..., description='页码,从1开始', ge=1),
|
||
m:int=Query(..., description='每页条数', ge=1),
|
||
db = Depends(get_db)):
|
||
req,total = StatisticsDao.get_time_size_dao(n,m,db)
|
||
return ResponseModel5(code=200,
|
||
message='查询成功',
|
||
total=total,
|
||
total_pages=ceil(total/m) if total > 0 else 0,
|
||
data=req)
|
||
|
||
@BasicInformationAPI.get('/class_avg_time_size', summary='统计每个班级的平均就业时长(只统计进入就业阶段的学生)')
|
||
def get_class_avg_time_size_api(
|
||
n:int=Query(..., description='页码,从1开始', ge=1),
|
||
m:int=Query(..., description='每页条数', ge=1),
|
||
db = Depends(get_db)):
|
||
req,total = StatisticsDao.get_class_avg_time_size_dao(n,m,db)
|
||
return ResponseModel6(code=200,
|
||
message='查询成功',
|
||
total=total,
|
||
total_pages=ceil(total/m) if total > 0 else 0,
|
||
data=req) |