Skip to content

Commit

Permalink
feat: show both group ranking and global ranking in hub
Browse files Browse the repository at this point in the history
  • Loading branch information
taoky committed Sep 5, 2023
1 parent d0840c4 commit 6c3617f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
11 changes: 3 additions & 8 deletions frontend/templates/hub.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,11 @@
<button onclick="token_copy()">{{ token_copy_text }}</button>
Token 是一些题目的登录凭证,禁止分享,否则视为作弊
<template v-if="progress.scores.find(i=>i.category===null)">
<a v-if="user.group==='other'" href="/board/">
<a href="/board/">
<br>
当前分数:{{ (progress.scores.find(i=>i.category===null)||{score:0}).score }},
总排名:{{ ranking.ranking }} / {{ ranking.total }}
<br>
</a>
<a v-else :href="`/board/?group=${encodeURIComponent(user.group)}`">
<br>
当前分数:{{ (progress.scores.find(i=>i.category===null)||{score:0}).score }},
{{ groups[user.group] }}组内排名:{{ ranking.ranking }} / {{ ranking.total }}
总排名:{{ ranking["all"].ranking }} / {{ ranking["all"].total }}
<a :href="`/board/?group=${encodeURIComponent(user.group)}`" v-if="user.group!=='other'">,{{ groups[user.group] }}组内排名:{{ ranking["group"].ranking }} / {{ ranking["group"].total }}</a>
<br>
</a>
<template v-for="(category, category_index) in categories">
Expand Down
14 changes: 7 additions & 7 deletions frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def get(self, request):
announcement = Announcement.get_latest(context).json
except NotFound:
announcement = None
ranking = {}
if request.user.is_authenticated:
user = User.get(context, request.user.pk)
if user.group == 'other':
ranking = Submission.get_user_ranking(context, request.user.pk)
else:
ranking = Submission.get_user_ranking(context, request.user.pk,
group=user.group)
else:
ranking = {}
# 获取总排名(所有用户均显示)
ranking["all"] = Submission.get_user_ranking(context, request.user.pk)
# 获取分组排名(对非 other 用户组)
if user.group != 'other':
ranking["group"] = Submission.get_user_ranking(context, request.user.pk,
group=user.group)
return TemplateResponse(request, 'hub.html', {
'announcement': announcement,
'challenges': challenges,
Expand Down
6 changes: 6 additions & 0 deletions server/submission/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ def f(d):

@classmethod
def get_user_ranking(cls, context, user, *, category=None, group=None):
"""
返回用户排名信息。
返回值格式:
{"ranking": int, "total": int}
"""
if category is None:
category = ALL
try:
Expand Down

0 comments on commit 6c3617f

Please sign in to comment.