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,29 +1078,31 @@ 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:
|
||||||
return base_contest_ranking_list(
|
queryset = queryset.order_by(
|
||||||
contest,
|
"is_disqualified", "-score", "cumtime", "tiebreaker"
|
||||||
problems,
|
|
||||||
queryset.extra(select={"round_score": "round(score_final, 6)"}).order_by(
|
|
||||||
"is_disqualified", "-round_score", "cumtime_final", "tiebreaker"
|
|
||||||
),
|
|
||||||
show_final,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return base_contest_ranking_list(
|
||||||
|
contest,
|
||||||
|
problems,
|
||||||
|
queryset,
|
||||||
|
show_final,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_contest_ranking_list(
|
def get_contest_ranking_list(
|
||||||
request,
|
request,
|
||||||
|
@ -1116,21 +1118,12 @@ 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
|
|
||||||
if participation is None or participation.contest_id != contest.id:
|
|
||||||
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)
|
ranking_list_result = ranking_list(
|
||||||
|
contest, problems, show_final=show_final, extra_participation=participation
|
||||||
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,
|
||||||
|
@ -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