statcalc就业统计模块更新

This commit is contained in:
2026-09-22 17:02:59 +08:00
parent eb4e4c1cc0
commit 5020eeb640
3 changed files with 37 additions and 3 deletions
+32
View File
@@ -113,4 +113,36 @@ def get_students( stu:StudentsQuery = Depends()
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
@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]
@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)
}