mrz
This commit is contained in:
@@ -6,7 +6,7 @@ from util.database import get_db
|
|||||||
|
|
||||||
StatisticsAPI = APIRouter(tags=['统计分析模块'])
|
StatisticsAPI = APIRouter(tags=['统计分析模块'])
|
||||||
|
|
||||||
@StatisticsAPI.get("/age",response_model=list[StudentResponse],summary='根据年龄查询学生信息')
|
@StatisticsAPI.get("/age",response_model=list[StugetResponse],summary='根据年龄查询学生信息')
|
||||||
def get_students(min_age:int|None=Query(None,ge=0,le=150),max_age:int|None=Query(None,ge=0,le=150),db=Depends(get_db)):
|
def get_students(min_age:int|None=Query(None,ge=0,le=150),max_age:int|None=Query(None,ge=0,le=150),db=Depends(get_db)):
|
||||||
l = select_age(min_age,max_age,db)
|
l = select_age(min_age,max_age,db)
|
||||||
return l
|
return l
|
||||||
|
|||||||
@@ -38,8 +38,11 @@ def select_all(db):
|
|||||||
"gender": i.gender,
|
"gender": i.gender,
|
||||||
"cnt": i.cnt
|
"cnt": i.cnt
|
||||||
})
|
})
|
||||||
|
if not l2:
|
||||||
|
raise HTTPException(status_code=404, detail="没有数据")
|
||||||
return l2
|
return l2
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
raise HTTPException(status_code=500,detail="查询异常")
|
raise HTTPException(status_code=500,detail="查询异常")
|
||||||
|
|
||||||
@@ -66,7 +69,10 @@ def select_score(min_score,max_score,db):
|
|||||||
db = db.filter(WlScore.score >= min_score)
|
db = db.filter(WlScore.score >= min_score)
|
||||||
if max_score is not None:
|
if max_score is not None:
|
||||||
db = db.filter(WlScore.score <= max_score)
|
db = db.filter(WlScore.score <= max_score)
|
||||||
return db.all()
|
l1 = db.all()
|
||||||
|
if not l1:
|
||||||
|
raise HTTPException(status_code=404, detail="没有数据")
|
||||||
|
return l1
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -80,7 +86,11 @@ def select_avg_score(db):
|
|||||||
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\
|
.filter(WlScore.delete_status==0,Student_Model.delete_status == 0)\
|
||||||
.group_by(Student_Model.class_id)\
|
.group_by(Student_Model.class_id)\
|
||||||
.order_by(func.round(func.avg(WlScore.score),1)).all()
|
.order_by(func.round(func.avg(WlScore.score),1)).all()
|
||||||
|
if not l1:
|
||||||
|
raise HTTPException(status_code=404, detail="没有数据")
|
||||||
return l1
|
return l1
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
raise HTTPException(status_code=500,detail="查询异常")
|
raise HTTPException(status_code=500,detail="查询异常")
|
||||||
|
|
||||||
@@ -102,7 +112,11 @@ def select_salary(db):
|
|||||||
.filter(Employment_info.delete_status==0,Student_Model.delete_status == 0)\
|
.filter(Employment_info.delete_status==0,Student_Model.delete_status == 0)\
|
||||||
.order_by(Employment_info.salary.desc())\
|
.order_by(Employment_info.salary.desc())\
|
||||||
.limit(5).all()
|
.limit(5).all()
|
||||||
|
if not l1:
|
||||||
|
raise HTTPException(status_code=404, detail="没有数据")
|
||||||
return l1
|
return l1
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
raise HTTPException(status_code=500,detail="查询异常")
|
raise HTTPException(status_code=500,detail="查询异常")
|
||||||
|
|
||||||
@@ -123,19 +137,27 @@ def select_avg_days(db):
|
|||||||
Employment_info.offer_issuance_date.isnot(None),)\
|
Employment_info.offer_issuance_date.isnot(None),)\
|
||||||
.group_by(Student_Model.class_id)\
|
.group_by(Student_Model.class_id)\
|
||||||
.order_by(func.avg(func.datediff(Employment_info.offer_issuance_date,Student_Model.admission_date)).desc()).all()
|
.order_by(func.avg(func.datediff(Employment_info.offer_issuance_date,Student_Model.admission_date)).desc()).all()
|
||||||
|
if not l1:
|
||||||
|
raise HTTPException(status_code=404, detail="没有数据")
|
||||||
return l1
|
return l1
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
raise HTTPException(status_code=500, detail="查询异常")
|
raise HTTPException(status_code=500, detail="查询异常")
|
||||||
|
|
||||||
#统计每个学⽣的就业时⻓
|
#统计每个学⽣的就业时⻓
|
||||||
def select_days(db):
|
def select_days(db):
|
||||||
try:
|
try:
|
||||||
l2 =db.query(Employment_info.stu_id
|
l1 =db.query(Employment_info.stu_id
|
||||||
,func.coalesce(func.datediff(Employment_info.offer_issuance_date
|
,func.coalesce(func.datediff(Employment_info.offer_issuance_date
|
||||||
,Employment_info.employment_opening_date),0)\
|
,Employment_info.employment_opening_date),0)\
|
||||||
.label("diff_days")
|
.label("diff_days")
|
||||||
).filter(Employment_info.delete_status == 0).all()
|
).filter(Employment_info.delete_status == 0).all()
|
||||||
return l2
|
if not l1:
|
||||||
|
raise HTTPException(status_code=404, detail="没有数据")
|
||||||
|
return l1
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
raise HTTPException(status_code=500, detail="查询异常")
|
raise HTTPException(status_code=500, detail="查询异常")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user