2026-09-22 16:38:38 +08:00
|
|
|
# statcalc_api所有统计分析模块的api路由、接口
|
|
|
|
|
|
2026-09-23 12:30:55 +08:00
|
|
|
from fastapi import APIRouter , Depends , HTTPException , Query
|
2026-09-22 16:38:38 +08:00
|
|
|
from StatCalc.dao.statcalc_dao import *
|
|
|
|
|
from StatCalc.schema.statcalc_request import *
|
|
|
|
|
from databases import *
|
|
|
|
|
|
|
|
|
|
statcalc_api = APIRouter()
|
|
|
|
|
|
2026-09-22 21:05:09 +08:00
|
|
|
@statcalc_api.get("/statcalc/age"
|
2026-09-22 16:38:38 +08:00
|
|
|
,summary='人员信息查询'
|
2026-09-23 12:30:55 +08:00
|
|
|
,description=f'查询所有大于等于输入年龄的学员的信息。'
|
2026-09-22 16:38:38 +08:00
|
|
|
)
|
2026-09-23 12:30:55 +08:00
|
|
|
def get_students( age:int = 0 ,db=Depends(get_db)):
|
|
|
|
|
result = get_age_30( age=age , db=db )
|
|
|
|
|
if result is None or len(result) == 0:
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
return result
|
2026-09-22 16:38:38 +08:00
|
|
|
|
2026-09-22 21:05:09 +08:00
|
|
|
@statcalc_api.get("/statcalc/students"
|
2026-09-22 16:38:38 +08:00
|
|
|
,summary='人数统计'
|
|
|
|
|
,description=f'统计每个班级的人数以及男生女生的人数。'
|
|
|
|
|
)
|
2026-09-22 21:05:09 +08:00
|
|
|
def get_students(headcount:get_student_dao
|
2026-09-22 19:04:39 +08:00
|
|
|
,db=Depends(get_db)
|
|
|
|
|
):
|
2026-09-22 21:05:09 +08:00
|
|
|
result = get_class_count( g=headcount , db=db )
|
2026-09-22 16:38:38 +08:00
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
2026-09-22 21:05:09 +08:00
|
|
|
@statcalc_api.get("/statcalc/scores"
|
2026-09-23 04:27:31 +08:00
|
|
|
,summary='优秀成绩学生信息查询'
|
|
|
|
|
,description=f'查询所有科目考试成绩都在80分以上的学生。'
|
2026-09-22 16:38:38 +08:00
|
|
|
)
|
2026-09-23 12:30:55 +08:00
|
|
|
def get_excellent(sco:int = Query(80,ge=0, le=100,description="优秀成绩设定")
|
|
|
|
|
, db=Depends(get_db)
|
|
|
|
|
):
|
|
|
|
|
result = get_excellent_students(sco=sco, db=db )
|
2026-09-22 16:38:38 +08:00
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
2026-09-22 21:05:09 +08:00
|
|
|
@statcalc_api.get("/statcalc/fail"
|
2026-09-22 16:38:38 +08:00
|
|
|
,summary='不及格成绩查询'
|
2026-09-23 12:30:55 +08:00
|
|
|
,description=f'查询有两次以上低于输入分数的学生的姓名,班级和不及格成绩。'
|
2026-09-22 16:38:38 +08:00
|
|
|
)
|
2026-09-23 12:30:55 +08:00
|
|
|
def get_students(sco:int = Query(60,ge=0, le=100,description="不及格成绩设定")
|
|
|
|
|
, db=Depends(get_db) ):
|
|
|
|
|
result = get_score_60( sco=sco ,db=db )
|
2026-09-22 16:38:38 +08:00
|
|
|
if result:
|
|
|
|
|
return result
|
|
|
|
|
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
|
|
|
|
|
2026-09-22 21:05:09 +08:00
|
|
|
@statcalc_api.get('/statcalc/average', summary='统计每次考试每个班级的平均分')
|
2026-09-23 12:30:55 +08:00
|
|
|
def get_class_avg( class_id:int = Query(1,ge=1, le=3,description="查询班级")
|
|
|
|
|
, db=Depends(get_db)):
|
|
|
|
|
result = get_class_avg_dao( class_id , db)
|
2026-09-22 21:05:09 +08:00
|
|
|
if not result:
|
|
|
|
|
return []
|
|
|
|
|
return result
|
2026-09-22 16:38:38 +08:00
|
|
|
|
|
|
|
|
|
2026-09-22 20:28:02 +08:00
|
|
|
from stu_jiuye.model import *
|
2026-09-23 04:27:31 +08:00
|
|
|
from students.model.students_model import Students
|
|
|
|
|
from class_management.model.class_management_model import ClassInfo
|
2026-09-22 16:38:38 +08:00
|
|
|
|
2026-09-22 21:05:09 +08:00
|
|
|
@statcalc_api.get('/statcalc/top',summary='就业薪资Top5')
|
2026-09-23 12:09:49 +08:00
|
|
|
def salarytop5(num:int,db=Depends(get_db)):
|
2026-09-23 04:27:31 +08:00
|
|
|
q = db.query(Employments, Company.employment_company, Students.name.label('sname'), ClassInfo.name.label('class_num')) \
|
|
|
|
|
.join(Company, Employments.company_id == Company.id) \
|
|
|
|
|
.join(Students, Employments.stuid == Students.id) \
|
|
|
|
|
.join(ClassInfo, Employments.class_id == ClassInfo.id) \
|
|
|
|
|
.filter(Employments.is_deleted == 0) \
|
|
|
|
|
.order_by(Employments.employment_salary.desc()) \
|
2026-09-23 12:09:49 +08:00
|
|
|
.limit(num).all()
|
2026-09-23 04:27:31 +08:00
|
|
|
# q是4元组 (Employments对象, company_name, sname, class_num)
|
|
|
|
|
return [{'学生姓名': row[2], '学生班级编号': row[3], '就业时间': str(row[0].offer_recived_time) if row[0].offer_recived_time else None, '公司': row[1]} for row in q]
|
2026-09-22 16:38:38 +08:00
|
|
|
|
2026-09-22 21:05:09 +08:00
|
|
|
@statcalc_api.get('/statcalc/job',summary='学生就业时长')
|
2026-09-23 12:14:22 +08:00
|
|
|
def worktime(stuid:int,db=Depends(get_db)):
|
2026-09-23 04:27:31 +08:00
|
|
|
q = db.query(Employments, Students.name.label('sname')) \
|
|
|
|
|
.join(Students, Employments.stuid == Students.id) \
|
2026-09-23 12:14:22 +08:00
|
|
|
.filter(Employments.stuid == stuid,Employments.is_deleted == 0) \
|
2026-09-23 04:27:31 +08:00
|
|
|
.all()
|
2026-09-22 17:02:59 +08:00
|
|
|
|
2026-09-22 20:28:02 +08:00
|
|
|
return [
|
2026-09-23 04:27:31 +08:00
|
|
|
{'学生姓名': row[1],
|
|
|
|
|
'就业时常':f'{row[0].offer_recived_time-row[0].employment_open_time}'
|
|
|
|
|
if row[0].offer_recived_time and row[0].employment_open_time else '暂无数据'} for row in q
|
2026-09-22 20:28:02 +08:00
|
|
|
]
|
2026-09-22 17:02:59 +08:00
|
|
|
|
2026-09-22 21:05:09 +08:00
|
|
|
@statcalc_api.get('/statcalc/avgjob',summary='学生平均就业时长')
|
2026-09-22 17:02:59 +08:00
|
|
|
def avgworktime(db=Depends(get_db)):
|
2026-09-23 04:27:31 +08:00
|
|
|
q = db.query(Employments) \
|
2026-09-22 17:02:59 +08:00
|
|
|
.filter(Employments.employment_open_time.isnot(None)
|
|
|
|
|
,Employments.offer_recived_time.isnot(None)
|
2026-09-23 04:27:31 +08:00
|
|
|
,Employments.is_deleted==0) \
|
2026-09-22 17:02:59 +08:00
|
|
|
.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)
|
|
|
|
|
}
|
2026-09-22 20:28:02 +08:00
|
|
|
|