统计分析所有测试通过。
This commit is contained in:
@@ -30,11 +30,11 @@ def get_students(headcount:get_student_dao
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
|
||||
@statcalc_api.get("/statcalc/scores"
|
||||
,summary='80分以上成绩学生信息查询'
|
||||
,description=f'查询每次考试成绩都在80分以上的学生的编号,姓名和成绩。'
|
||||
,summary='优秀成绩学生信息查询'
|
||||
,description=f'查询所有科目考试成绩都在80分以上的学生。'
|
||||
)
|
||||
def get_students(db=Depends(get_db)):
|
||||
result = get_score_80( db=db )
|
||||
def get_excellent(db=Depends(get_db)):
|
||||
result = get_excellent_students( db=db )
|
||||
if result:
|
||||
return result
|
||||
raise HTTPException(status_code=404, detail="没有找到符合条件的学生")
|
||||
@@ -58,34 +58,40 @@ def get_class_avg(db=Depends(get_db)):
|
||||
|
||||
|
||||
from stu_jiuye.model import *
|
||||
from students.model.students_model import Students
|
||||
from class_management.model.class_management_model import ClassInfo
|
||||
|
||||
@statcalc_api.get('/statcalc/top',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.stuid,'学生班级编号':i.class_id,'就业时间':i.offer_recived_time,'公司':employment_company} for i,employment_company in q]
|
||||
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()) \
|
||||
.limit(5).all()
|
||||
# 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]
|
||||
|
||||
@statcalc_api.get('/statcalc/job',summary='学生就业时长')
|
||||
def worktime(db=Depends(get_db)):
|
||||
q = db.query(Employments)\
|
||||
.filter(Employments.is_deleted==0)\
|
||||
.all()
|
||||
q = db.query(Employments, Students.name.label('sname')) \
|
||||
.join(Students, Employments.stuid == Students.id) \
|
||||
.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
|
||||
{'学生姓名': 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
|
||||
]
|
||||
|
||||
@statcalc_api.get('/statcalc/avgjob',summary='学生平均就业时长')
|
||||
def avgworktime(db=Depends(get_db)):
|
||||
q = db.query(Employments)\
|
||||
q = db.query(Employments) \
|
||||
.filter(Employments.employment_open_time.isnot(None)
|
||||
,Employments.offer_recived_time.isnot(None)
|
||||
,Employments.is_deleted==0)\
|
||||
,Employments.is_deleted==0) \
|
||||
.all()
|
||||
if not q:
|
||||
return {'平均就业时常': '暂无数据'}
|
||||
|
||||
@@ -37,21 +37,47 @@ def get_class_count(g , db):
|
||||
|
||||
from scores.model.score_model import Score
|
||||
|
||||
def get_score_80(db):
|
||||
sq = ( db.query(Students.id)
|
||||
.join(Score, Score.sid == Students.id)
|
||||
.filter(Score.score < 80 )
|
||||
.group_by(Students.id)
|
||||
.having(func.count(Score.id) > 2 )
|
||||
.all()
|
||||
)
|
||||
|
||||
q = ( db.query(Students.name,ClassInfo.name,Score.score )
|
||||
.join(ClassInfo, ClassInfo.id == Students.class_id)
|
||||
.join(Score, Score.sid == Students.id)
|
||||
.filter(Students.id.in_(sq),Score.score < 80)
|
||||
.all()
|
||||
)
|
||||
def get_excellent_students(db):
|
||||
"""查询所有科目都在80分以上的优秀学生"""
|
||||
# 先查总科目数
|
||||
total_subjects = db.execute(text("SELECT COUNT(*) FROM subject")).scalar()
|
||||
|
||||
# 子查询:找出成绩>=80分的科目数等于总科目数的学生
|
||||
sq = db.query(Students.id) \
|
||||
.join(Score, Score.sid == Students.id) \
|
||||
.filter(Score.score >= 80) \
|
||||
.group_by(Students.id) \
|
||||
.having(func.count(Score.id) == total_subjects) \
|
||||
.subquery()
|
||||
|
||||
# 主查询:返回优秀学生信息
|
||||
q = db.query(Students.id, Students.name, ClassInfo.name.label('class_name'), Score.score) \
|
||||
.join(ClassInfo, ClassInfo.id == Students.class_id) \
|
||||
.join(Score, Score.sid == Students.id) \
|
||||
.filter(Students.id.in_(sq.select()), Score.score >= 80) \
|
||||
.all()
|
||||
return [row._asdict() for row in q]
|
||||
|
||||
|
||||
from scores.model.score_model import Score
|
||||
|
||||
def get_score_80(db):
|
||||
"""查询有两次以上不及格(<60分)的学生"""
|
||||
# 子查询:找出不及格超过2门的学生ID
|
||||
sq = db.query(Students.id) \
|
||||
.join(Score, Score.sid == Students.id) \
|
||||
.filter(Score.score < 60) \
|
||||
.group_by(Students.id) \
|
||||
.having(func.count(Score.id) > 2) \
|
||||
.subquery()
|
||||
|
||||
# 主查询:返回不及格学生信息
|
||||
q = db.query(Students.name, ClassInfo.name.label('class_name'), Score.score) \
|
||||
.join(ClassInfo, ClassInfo.id == Students.class_id) \
|
||||
.join(Score, Score.sid == Students.id) \
|
||||
.filter(Students.id.in_(sq.select()), Score.score < 60) \
|
||||
.all()
|
||||
return [row._asdict() for row in q]
|
||||
|
||||
def get_class_avg_dao(db):
|
||||
|
||||
+4
-4
@@ -2000,8 +2000,8 @@
|
||||
if (data.detail) {
|
||||
resultDiv.innerHTML = `<div>${data.detail}</div>`;
|
||||
} else {
|
||||
resultDiv.innerHTML = data.length > 0
|
||||
? data.map(row => `<div>${row['students.name']} - ${row.scores.score}分</div>`).join('')
|
||||
resultDiv.innerHTML = data.length > 0
|
||||
? data.map(row => `<div>${row.name} - ${row.score}分</div>`).join('')
|
||||
: '<div>暂无数据</div>';
|
||||
}
|
||||
}
|
||||
@@ -2019,8 +2019,8 @@
|
||||
if (data.detail) {
|
||||
resultDiv.innerHTML = `<div>${data.detail}</div>`;
|
||||
} else {
|
||||
resultDiv.innerHTML = data.length > 0
|
||||
? data.map(row => `<div>${row['students.name']} | ${row['class_management.name']} | 不及格${row.scores.score}分</div>`).join('')
|
||||
resultDiv.innerHTML = data.length > 0
|
||||
? data.map(row => `<div>${row.name} | ${row.class_name} | 不及格${row.score}分</div>`).join('')
|
||||
: '<div>无不及格学生</div>';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user