Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Backend API & implemention V0.5.0: Modify API interface of
Browse files Browse the repository at this point in the history
/data/by_class/<int:class_id>/exam/<int:exam_id>.
  • Loading branch information
saitewasreset committed Nov 28, 2023
1 parent 544f8a6 commit f3696df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
18 changes: 15 additions & 3 deletions backend/app/daemon/scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,10 +571,22 @@ def get_data_by_person(student_id, exam_id):
temp = {}
for subject_id, value, grade_rank, class_rank in data:
temp[subject_id] = [value, class_rank, grade_rank]
result = []
for i in range(10):
result.append([0.0, 0, 0])
result = {}
for key, value in temp.items():
result[key] = value

total_sql = "SELECT temp.v, temp.rank " \
"FROM(SELECT tvalue.student_id , v, RANK() OVER (ORDER BY tvalue.v DESC) AS rank FROM (SELECT student_id, SUM(value) AS v FROM scores INNER JOIN students ON scores.student_id = students.id WHERE exam_id = ? GROUP BY name) AS tvalue) AS temp " \
"WHERE temp.student_id = ?"
cur.execute(total_sql, (exam_id, student_id))
data = list(cur)
total_score, total_grade_rank = data[0]
class_rank_sql = "SELECT temp2.rank " \
"FROM(SELECT tvalue.student_id , v, RANK() OVER (ORDER BY tvalue.v DESC) AS rank FROM (SELECT student_id, SUM(value) AS v FROM scores INNER JOIN students ON scores.student_id = students.id WHERE exam_id = ? AND class = ? GROUP BY name) AS tvalue) AS temp2 " \
"WHERE temp2.student_id = ?"
cur.execute(class_rank_sql, (exam_id, class_id, student_id))
data = list(cur)
total_class_rank = data[0][0]
result[255] = [total_score, total_class_rank, total_grade_rank]
ret = {"code": 200, "msg": "Ok", "data": {"scores": result}}
return ret
18 changes: 9 additions & 9 deletions backend/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

- Change API to V0.3.0

# API V0.4.0
# API V0.5.0

## V0.4.0改动
- /data/by_class/<int:class_id>/exam/<int:exam_id>的ScoreObject中新增id(学生id)
## V0.5.0改动
- /data/by_class/<int:class_id>/exam/<int:exam_id>,修改API接口

SubjectId与科目名称对照表:
|SubjectId|SubjectName|
Expand Down Expand Up @@ -218,7 +218,7 @@ Input:
Output:
HTTP 状态码始终为200,应根据返回的JSON判断:

ret:
ret:
|Item|Value|Description|
| ---- | ---- | ---- |
|code|int,API状态码|若student_id不存在,或exam_id不存在,则为404;若查询成功,则为200|
Expand All @@ -228,11 +228,11 @@ ret:
data:
|Item|Value|Description|
| ---- | ---- | ---- |
|scores|ScoresList(List),查询的成绩数据|其中每个元素为StudentScoreInfoList(List)详见下|
|scores|ScoresBySubject(Object/dict),查询的成绩数据|其中每个元素为StudentScoreInfoList(List)详见下|

ScoresList:
当学生未选考该科目时,该科目成绩为0
|Index|Value|Description|
ScoresBySubject:
当学生未选考该科目时,该科目将不出现在ScoresBySubject中
|Item|Value|Description|
| ---- | ---- | ---- |
|0|StudentScoreList, [0.0, 0, 0]|预留|
|1|StudentScoreList, 语文成绩信息|-|
Expand All @@ -244,9 +244,9 @@ ScoresList:
|7|StudentScoreList, 政治成绩信息|-|
|8|StudentScoreList, 历史成绩信息|-|
|9|StudentScoreList, 地理成绩信息|-|
|255|StudentScoreList, 总分成绩信息|-|

StudentScoreInfoList:
当学生未选考该科目时,该科目成绩为0
|Index|Value|Description|
| ---- | ---- | ---- |
|0|Double, 该科目成绩|-|
Expand Down

0 comments on commit f3696df

Please sign in to comment.