From ffcb40db41feda070a729793223cd72df305006a Mon Sep 17 00:00:00 2001 From: Orangeeee Date: Tue, 22 Sep 2026 20:28:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=88=86=E6=9E=90=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=BE=85=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=E7=BB=9F=E8=AE=A1=E5=88=86=E6=9E=90=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=8C=E5=B0=B1=E4=B8=9A3=E4=B8=AA?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=9B=B4=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StatCalc/api/statcalc_api.py | 60 ++++++++---------------------------- StatCalc/dao/statcalc_dao.py | 17 ++++++++-- 2 files changed, 26 insertions(+), 51 deletions(-) diff --git a/StatCalc/api/statcalc_api.py b/StatCalc/api/statcalc_api.py index e2e4b35..908a76a 100644 --- a/StatCalc/api/statcalc_api.py +++ b/StatCalc/api/statcalc_api.py @@ -44,11 +44,8 @@ def get_students(db=Depends(get_db)): ,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 ) +def get_students( db=Depends(get_db) ): + result = get_score_80( db=db ) if result: return result raise HTTPException(status_code=404, detail="没有找到符合条件的学生") @@ -66,47 +63,10 @@ def get_students( stu:StudentsQuery = Depends() 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="没有找到符合条件的学生") +from stu_jiuye.model import * -@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="没有找到符合条件的学生") - - -@CURD.get('/Top5',summary='就业薪资Top5') +@statcalc_api.get('/Top5',summary='就业薪资Top5') def salarytop5(db=Depends(get_db)): q = db.query(Employments,Company.employment_company) \ .join(Company, Employments.company_id == Company.id) \ @@ -115,16 +75,19 @@ def salarytop5(db=Depends(get_db)): .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='学生就业时常') +@statcalc_api.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] + 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='学生平均就业时常') +@statcalc_api.get('/avgworktime',summary='学生平均就业时长') def avgworktime(db=Depends(get_db)): q = db.query(Employments)\ .filter(Employments.employment_open_time.isnot(None) @@ -139,3 +102,4 @@ def avgworktime(db=Depends(get_db)): '人数': len(q), '平均就业时常(天)': round(avg_days, 2) } + diff --git a/StatCalc/dao/statcalc_dao.py b/StatCalc/dao/statcalc_dao.py index 97bd011..8c58f79 100644 --- a/StatCalc/dao/statcalc_dao.py +++ b/StatCalc/dao/statcalc_dao.py @@ -39,12 +39,23 @@ def get_class_count(g , db): from scores.model.score_model import Score def get_score_80(db): - q = ( db.query(Score) - .group_by(Score.score) - .having( min(Score.score) >= 80) + sq = ( db.query(Students.id) + .join(Score, Score.sid == Students.id) + .filer(Score.score < 80 ) + .group_by(Students.id) + .having(func.count(Score.id) > 2 ) + .sq() + ) + + q = ( db.query(Students.name,ClassInfo.name,Score.score ) + .join(ClassInfo, ClassInfo.id == Students.class_id) + .join(Score, Score.sid == Students.id) + .filer(Students.id.in_(sq),Score.score < 80) .all() ) return q + +