Fix wrong ranking order in previous commit
This commit is contained in:
parent
308006f7bd
commit
0406dea2a2
1 changed files with 42 additions and 31 deletions
|
@ -1078,26 +1078,28 @@ def base_contest_ranking_list(contest, problems, queryset, show_final=False):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def contest_ranking_list(contest, problems, queryset=None, show_final=False):
|
def contest_ranking_list(
|
||||||
|
contest, problems, queryset=None, show_final=False, extra_participation=None
|
||||||
|
):
|
||||||
if queryset is None:
|
if queryset is None:
|
||||||
queryset = contest.users.filter(virtual=0)
|
queryset = contest.users.filter(virtual=0)
|
||||||
|
|
||||||
if not show_final:
|
if extra_participation and extra_participation.virtual:
|
||||||
return base_contest_ranking_list(
|
queryset = queryset | contest.users.filter(id=extra_participation.id)
|
||||||
contest,
|
|
||||||
problems,
|
if show_final:
|
||||||
queryset.extra(select={"round_score": "round(score, 6)"}).order_by(
|
queryset = queryset.order_by(
|
||||||
"is_disqualified", "-round_score", "cumtime", "tiebreaker"
|
"is_disqualified", "-score_final", "cumtime_final", "tiebreaker"
|
||||||
),
|
|
||||||
show_final,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
queryset = queryset.order_by(
|
||||||
|
"is_disqualified", "-score", "cumtime", "tiebreaker"
|
||||||
|
)
|
||||||
|
|
||||||
return base_contest_ranking_list(
|
return base_contest_ranking_list(
|
||||||
contest,
|
contest,
|
||||||
problems,
|
problems,
|
||||||
queryset.extra(select={"round_score": "round(score_final, 6)"}).order_by(
|
queryset,
|
||||||
"is_disqualified", "-round_score", "cumtime_final", "tiebreaker"
|
|
||||||
),
|
|
||||||
show_final,
|
show_final,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1116,22 +1118,13 @@ def get_contest_ranking_list(
|
||||||
.order_by("order")
|
.order_by("order")
|
||||||
)
|
)
|
||||||
|
|
||||||
# Set participation to current virtual join if it's None
|
if participation is None:
|
||||||
ranking_participation = None
|
participation = _get_current_virtual_participation(request, contest)
|
||||||
if participation is None and request.user.is_authenticated:
|
|
||||||
participation = request.profile.current_contest
|
ranking_list_result = ranking_list(
|
||||||
if participation is None or participation.contest_id != contest.id:
|
contest, problems, show_final=show_final, extra_participation=participation
|
||||||
participation = None
|
|
||||||
if participation is not None and participation.virtual:
|
|
||||||
ranking_participation = make_contest_ranking_profile(
|
|
||||||
contest, participation, problems
|
|
||||||
)
|
)
|
||||||
|
|
||||||
ranking_list_result = ranking_list(contest, problems, show_final=show_final)
|
|
||||||
|
|
||||||
if ranking_participation and ranking_participation not in ranking_list_result:
|
|
||||||
ranking_list_result.append(ranking_participation)
|
|
||||||
|
|
||||||
users = ranker(
|
users = ranker(
|
||||||
ranking_list_result,
|
ranking_list_result,
|
||||||
key=attrgetter("points", "cumtime", "tiebreaker"),
|
key=attrgetter("points", "cumtime", "tiebreaker"),
|
||||||
|
@ -1155,6 +1148,9 @@ def contest_ranking_ajax(request, contest, participation=None):
|
||||||
):
|
):
|
||||||
raise Http404()
|
raise Http404()
|
||||||
|
|
||||||
|
if participation is None:
|
||||||
|
participation = _get_current_virtual_participation(request, contest)
|
||||||
|
|
||||||
queryset = contest.users.filter(virtual__gte=0)
|
queryset = contest.users.filter(virtual__gte=0)
|
||||||
if request.GET.get("friend") == "true" and request.profile:
|
if request.GET.get("friend") == "true" and request.profile:
|
||||||
friends = request.profile.get_friends()
|
friends = request.profile.get_friends()
|
||||||
|
@ -1166,7 +1162,9 @@ def contest_ranking_ajax(request, contest, participation=None):
|
||||||
request,
|
request,
|
||||||
contest,
|
contest,
|
||||||
participation,
|
participation,
|
||||||
ranking_list=partial(contest_ranking_list, queryset=queryset),
|
ranking_list=partial(
|
||||||
|
contest_ranking_list, queryset=queryset, extra_participation=participation
|
||||||
|
),
|
||||||
show_final=show_final,
|
show_final=show_final,
|
||||||
)
|
)
|
||||||
return render(
|
return render(
|
||||||
|
@ -1182,6 +1180,19 @@ def contest_ranking_ajax(request, contest, participation=None):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_current_virtual_participation(request, contest):
|
||||||
|
# Return None if not eligible
|
||||||
|
if not request.user.is_authenticated:
|
||||||
|
return None
|
||||||
|
|
||||||
|
participation = request.profile.current_contest
|
||||||
|
|
||||||
|
if participation is None or participation.contest_id != contest.id:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return participation
|
||||||
|
|
||||||
|
|
||||||
class ContestRankingBase(ContestMixin, TitleMixin, DetailView):
|
class ContestRankingBase(ContestMixin, TitleMixin, DetailView):
|
||||||
template_name = "contest/ranking.html"
|
template_name = "contest/ranking.html"
|
||||||
page_type = None
|
page_type = None
|
||||||
|
|
Loading…
Reference in a new issue