Add virtual participation to ranking list when virtual joining

This commit is contained in:
cuom1999 2024-05-31 00:35:20 -05:00
parent dc86e3a095
commit 308006f7bd
2 changed files with 20 additions and 15 deletions

View file

@ -1107,7 +1107,6 @@ def get_contest_ranking_list(
contest, contest,
participation=None, participation=None,
ranking_list=contest_ranking_list, ranking_list=contest_ranking_list,
show_current_virtual=False,
ranker=ranker, ranker=ranker,
show_final=False, show_final=False,
): ):
@ -1117,20 +1116,25 @@ def get_contest_ranking_list(
.order_by("order") .order_by("order")
) )
users = ranker( # Set participation to current virtual join if it's None
ranking_list(contest, problems, show_final=show_final), ranking_participation = None
key=attrgetter("points", "cumtime", "tiebreaker"),
)
if show_current_virtual:
if participation is None and request.user.is_authenticated: if participation is None and request.user.is_authenticated:
participation = request.profile.current_contest participation = request.profile.current_contest
if participation is None or participation.contest_id != contest.id: if participation is None or participation.contest_id != contest.id:
participation = None participation = None
if participation is not None and participation.virtual: if participation is not None and participation.virtual:
users = chain( ranking_participation = make_contest_ranking_profile(
[("-", make_contest_ranking_profile(contest, participation, problems))], contest, participation, problems
users, )
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(
ranking_list_result,
key=attrgetter("points", "cumtime", "tiebreaker"),
) )
return users, problems return users, problems
@ -1272,7 +1276,6 @@ class ContestParticipationList(LoginRequiredMixin, ContestRankingBase):
return get_contest_ranking_list( return get_contest_ranking_list(
self.request, self.request,
self.object, self.object,
show_current_virtual=False,
ranking_list=partial(base_contest_ranking_list, queryset=queryset), ranking_list=partial(base_contest_ranking_list, queryset=queryset),
ranker=lambda users, key: ( ranker=lambda users, key: (
(user.participation.virtual or live_link, user) for user in users (user.participation.virtual or live_link, user) for user in users

View file

@ -203,7 +203,9 @@ class UserAboutPage(UserPage):
"label": rating.contest.name, "label": rating.contest.name,
"rating": rating.rating, "rating": rating.rating,
"ranking": rating.rank, "ranking": rating.rank,
"link": reverse("contest_ranking", args=(rating.contest.key,)), "link": reverse("contest_ranking", args=(rating.contest.key,))
+ "#!"
+ self.object.username,
"timestamp": (rating.contest.end_time - EPOCH).total_seconds() "timestamp": (rating.contest.end_time - EPOCH).total_seconds()
* 1000, * 1000,
"date": date_format( "date": date_format(