2026-09-22 16:38:38 +08:00
|
|
|
# statcalc_api所有统计分析模块的api路由、接口
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter , Depends , HTTPException
|
|
|
|
|
from StatCalc.dao.statcalc_dao import *
|
|
|
|
|
from StatCalc.model.statcalc_model import *
|
|
|
|
|
from StatCalc.schema.statcalc_request import *
|
|
|
|
|
from databases import *
|
|
|
|
|
|
|
|
|
|
statcalc_api = APIRouter()
|
|
|
|
|
|
|
|
|
|
@statcalc_api.get("/statcalc"
|
|
|
|
|
,summary='人员信息查询'
|
|
|
|
|
,description=f'查询所有超过30岁的学员的信息。'
|
|
|
|
|
)
|
2026-09-22 18:23:13 +08:00
|
|
|
def get_students(db=Depends(get_db)):
|
|
|
|
|
result = get_age_30( db=db )
|
2026-09-22 16:38:38 +08:00
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
|
|
|
|
@statcalc_api.get("/statcalc"
|
|
|
|
|
,summary='人数统计'
|
|
|
|
|
,description=f'统计每个班级的人数以及男生女生的人数。'
|
|
|
|
|
)
|
2026-09-22 18:23:13 +08:00
|
|
|
def get_students(db=Depends(get_db)):
|
2026-09-22 16:38:38 +08:00
|
|
|
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
|
|
|
|
result = get_student_dao( s=s_dict , db=db )
|
|
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
|
|
|
|
@statcalc_api.get("/statcalc"
|
|
|
|
|
,summary='80分以上成绩学生信息查询'
|
|
|
|
|
,description=f'查询每次考试成绩都在80分以上的学生的编号,姓名和成绩。'
|
|
|
|
|
)
|
|
|
|
|
def get_students( stu:StudentsQuery = Depends()
|
|
|
|
|
, db=Depends(get_db)
|
|
|
|
|
):
|
|
|
|
|
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
|
|
|
|
result = get_student_dao( s=s_dict , db=db )
|
|
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
|
|
|
|
@statcalc_api.get("/statcalc"
|
|
|
|
|
,summary='不及格成绩查询'
|
|
|
|
|
,description=f'查询有两次以上不及格的学生的姓名,班级和不及格成绩。'
|
|
|
|
|
)
|
|
|
|
|
def get_students( stu:StudentsQuery = Depends()
|
|
|
|
|
, db=Depends(get_db)
|
|
|
|
|
):
|
|
|
|
|
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
|
|
|
|
result = get_student_dao( s=s_dict , db=db )
|
|
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
|
|
|
|
@statcalc_api.get("/statcalc"
|
|
|
|
|
,summary='班级平均分查询'
|
|
|
|
|
,description=f'统计每次考试每个班级的平均分,按照从高到低排序。'
|
|
|
|
|
)
|
|
|
|
|
def get_students( stu:StudentsQuery = Depends()
|
|
|
|
|
, db=Depends(get_db)
|
|
|
|
|
):
|
|
|
|
|
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
|
|
|
|
result = get_student_dao( s=s_dict , db=db )
|
|
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
|
|
|
|
@statcalc_api.get("/statcalc"
|
|
|
|
|
,summary='排名前五的学生信息'
|
|
|
|
|
,description=f'统计就业薪资最高的前五名学生的姓名,班级和就业时间,就业公司。'
|
|
|
|
|
)
|
|
|
|
|
def get_students( stu:StudentsQuery = Depends()
|
|
|
|
|
, db=Depends(get_db)
|
|
|
|
|
):
|
|
|
|
|
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
|
|
|
|
result = get_student_dao( s=s_dict , db=db )
|
|
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
|
|
|
|
@statcalc_api.get("/statcalc"
|
|
|
|
|
,summary='就业时长统计'
|
|
|
|
|
,description=f'统计每个学生的就业时长(offer下发时间-就业开放时间)。'
|
|
|
|
|
)
|
|
|
|
|
def get_students( stu:StudentsQuery = Depends()
|
|
|
|
|
, db=Depends(get_db)
|
|
|
|
|
):
|
|
|
|
|
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
|
|
|
|
result = get_student_dao( s=s_dict , db=db )
|
|
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
|
|
|
|
@statcalc_api.get("/statcalc"
|
|
|
|
|
,summary='班级的平均就业时长'
|
|
|
|
|
,description=f'统计每个班级的平均就业时长(只统计进入就业阶段的学生,也就是有就业开放时间)'
|
|
|
|
|
)
|
|
|
|
|
def get_students( stu:StudentsQuery = Depends()
|
|
|
|
|
, db=Depends(get_db)
|
|
|
|
|
):
|
|
|
|
|
s_dict = stu.model_dump(exclude_unset=True) # 没值的不要
|
|
|
|
|
result = get_student_dao( s=s_dict , db=db )
|
|
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
|
|
|
|
|
2026-09-22 17:02:59 +08:00
|
|
|
@CURD.get('/Top5',summary='就业薪资Top5')
|
|
|
|
|
def salarytop5(db=Depends(get_db)):
|
|
|
|
|
q = db.query(Employments,Company.employment_company) \
|
|
|
|
|
.join(Company, Employments.company_id == Company.id) \
|
|
|
|
|
.filter(Employments.is_deleted == 0)\
|
|
|
|
|
.order_by(Employments.employment_salary.desc())\
|
|
|
|
|
.limit(5) .all()
|
|
|
|
|
return [{'学生姓名':i.sname,'学生班级编号':i.class_num,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q]
|
2026-09-22 16:38:38 +08:00
|
|
|
|
2026-09-22 17:02:59 +08:00
|
|
|
@CURD.get('/worktime',summary='学生就业时常')
|
|
|
|
|
def worktime(db=Depends(get_db)):
|
|
|
|
|
q = db.query(Employments)\
|
|
|
|
|
.filter(Employments.is_deleted==0)\
|
|
|
|
|
.all()
|
|
|
|
|
|
|
|
|
|
return [{'学生姓名':i.sname,'就业时常':f'{i.offer_recived_time-i.employment_open_time}' if i.offer_recived_time and i.employment_open_time else '暂无数据'} for i in q]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@CURD.get('/avgworktime',summary='学生平均就业时常')
|
|
|
|
|
def avgworktime(db=Depends(get_db)):
|
|
|
|
|
q = db.query(Employments)\
|
|
|
|
|
.filter(Employments.employment_open_time.isnot(None)
|
|
|
|
|
,Employments.offer_recived_time.isnot(None)
|
|
|
|
|
,Employments.is_deleted==0)\
|
|
|
|
|
.all()
|
|
|
|
|
if not q:
|
|
|
|
|
return {'平均就业时常': '暂无数据'}
|
|
|
|
|
total = sum((i.offer_recived_time - i.employment_open_time).total_seconds() for i in q)
|
|
|
|
|
avg_days=total /len(q)/86400 #一天86400秒
|
|
|
|
|
return {
|
|
|
|
|
'人数': len(q),
|
|
|
|
|
'平均就业时常(天)': round(avg_days, 2)
|
|
|
|
|
}
|