Skip to content

Commit f7175d8

Browse files
authored
Merge pull request #163 from Spaghetti-OJ/problem_API_Permission
Problem api permission
2 parents fa7bb7d + 64857b7 commit f7175d8

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

‎problems/views/api.py‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,11 +1148,33 @@ def get(self, request, pk):
11481148
for row in submissions.values('status').annotate(cnt=Count('id')):
11491149
status_count[row['status']] = row['cnt']
11501150

1151-
# 9. top10執行時間
1152-
top10_runtime = list(submissions.filter(execution_time__gt=0).order_by('execution_time')[:10].values('id', 'user', 'execution_time', 'score', 'status'))
1153-
1154-
# 10. top10記憶體
1155-
top10_memory = list(submissions.filter(memory_usage__gt=0).order_by('memory_usage')[:10].values('id', 'user', 'memory_usage', 'score', 'status'))
1151+
# 9. top10執行時間(含使用者 username,方便前端顯示)
1152+
runtime_qs = submissions.filter(execution_time__gt=0).select_related('user').order_by('execution_time')[:10]
1153+
top10_runtime = [
1154+
{
1155+
'id': s.id,
1156+
'user': s.user_id,
1157+
'username': getattr(s.user, 'username', ''),
1158+
'execution_time': s.execution_time,
1159+
'score': s.score,
1160+
'status': s.status,
1161+
}
1162+
for s in runtime_qs
1163+
]
1164+
1165+
# 10. top10記憶體(含使用者 username)
1166+
memory_qs = submissions.filter(memory_usage__gt=0).select_related('user').order_by('memory_usage')[:10]
1167+
top10_memory = [
1168+
{
1169+
'id': s.id,
1170+
'user': s.user_id,
1171+
'username': getattr(s.user, 'username', ''),
1172+
'memory_usage': s.memory_usage,
1173+
'score': s.score,
1174+
'status': s.status,
1175+
}
1176+
for s in memory_qs
1177+
]
11561178

11571179
return api_response({
11581180
"acUserRatio": [ac_user_count, total_students],

0 commit comments

Comments
 (0)