From 11700219b13cba42d14899b4254a1840de57e74a Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sun, 24 Oct 2021 17:57:06 -0500 Subject: [PATCH] Add show virtual option --- judge/views/contests.py | 7 ++- templates/contest/ranking-table.html | 5 +- templates/contest/ranking.html | 82 +++++++++++++++++++++++++--- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/judge/views/contests.py b/judge/views/contests.py index eb6f901..c46c06a 100644 --- a/judge/views/contests.py +++ b/judge/views/contests.py @@ -644,14 +644,14 @@ def base_contest_ranking_list(contest, problems, queryset): def contest_ranking_list(contest, problems): - return base_contest_ranking_list(contest, problems, contest.users.filter(virtual=0) + return base_contest_ranking_list(contest, problems, contest.users.filter(virtual__gte=0) .prefetch_related('user__organizations') .extra(select={'round_score': 'round(score, 6)'}) .order_by('is_disqualified', '-round_score', 'cumtime', 'tiebreaker')) def get_contest_ranking_list(request, contest, participation=None, ranking_list=contest_ranking_list, - show_current_virtual=True, ranker=ranker): + show_current_virtual=False, ranker=ranker): problems = list(contest.contest_problems.select_related('problem').defer('problem__description').order_by('order')) users = ranker(ranking_list(contest, problems), key=attrgetter('points', 'cumtime', 'tiebreaker')) @@ -680,6 +680,7 @@ def contest_ranking_ajax(request, contest, participation=None): 'problems': problems, 'contest': contest, 'has_rating': contest.ratings.exists(), + 'can_edit': contest.is_editable_by(request.user) }) @@ -705,7 +706,6 @@ class ContestRankingBase(ContestMixin, TitleMixin, DetailView): users, problems = self.get_ranking_list() context['users'] = users context['problems'] = problems - context['last_msg'] = event.last() context['tab'] = self.tab return context @@ -759,6 +759,7 @@ class ContestParticipationList(LoginRequiredMixin, ContestRankingBase): context['has_rating'] = False context['now'] = timezone.now() context['rank_header'] = _('Participation') + context['participation_tab'] = True return context def get(self, request, *args, **kwargs): diff --git a/templates/contest/ranking-table.html b/templates/contest/ranking-table.html index d90c281..210795b 100644 --- a/templates/contest/ranking-table.html +++ b/templates/contest/ranking-table.html @@ -32,6 +32,9 @@ {% endblock %} {% block user_data %} + {% if user.participation.virtual %} + [{{user.participation.virtual}}] + {% endif %} {% if can_edit %}
@@ -63,7 +66,7 @@ {% endblock %} {% block row_extra %} - class="{{ 'disqualified' if user.participation.is_disqualified }} {{ 'friend' if user.username in friends }} {{'highlight' if user.username == request.user.username}}" + class="{{ 'disqualified' if user.participation.is_disqualified }} {{ 'friend' if user.username in friends }} {{'highlight' if user.username == request.user.username}} {{'virtual' if user.participation.virtual}}" {% endblock %} {% block before_point %} diff --git a/templates/contest/ranking.html b/templates/contest/ranking.html index 26f24bd..871a9d6 100644 --- a/templates/contest/ranking.html +++ b/templates/contest/ranking.html @@ -284,14 +284,21 @@ } } + let non_virtual_rank = []; + let original_rank = []; + function renew_filter() { var checkboxes = [ '#show-organizations-checkbox', '#show-fullnames-checkbox', '#show-friends-checkbox', '#show-total-score-checkbox', + '#show-virtual-checkbox' ]; + get_all_rank(); + get_non_virtual_rank(); + for (var i of checkboxes) { var $box = $(i); if ($box.is(':checked')) { @@ -316,6 +323,50 @@ }); } + function get_all_rank() { + original_rank = []; + $('tbody tr').each(function() { + original_rank.push($(this).children('td:first').html()); + }); + } + + function get_non_virtual_rank() { + non_virtual_rank = []; + $non_virtual_rows = $('tbody tr').not('.virtual'); + $non_virtual_rows.each(function() { + non_virtual_rank.push($(this).children('td:first').html()); + }); + var res = []; + for (var i in non_virtual_rank) { + if (i > 0 && non_virtual_rank[i] === non_virtual_rank[i - 1]) { + res.push(res[res.length - 1]); + } + else { + res.push(parseInt(i) + 1); + } + } + non_virtual_rank = res; + } + + function hide_virtual() { + $('.virtual').hide(); + var $non_virtual_rows = $('tbody tr').not('.virtual'); + $non_virtual_rows.each(function(index) { + $(this).children('td:first').html(non_virtual_rank[index]); + }); + $non_virtual_rows.last().find('td').css({'border-bottom-width': + '1px', 'border-color': '#ccc'}); + } + + function show_virtual() { + $('.virtual').show(); + $('tbody tr').each(function(index) { + $(this).children('td:first').html(original_rank[index]); + }); + $('tbody tr').not('.virtual').last().find('td').css({'border-bottom-width': + '', 'border-color': ''}); + } + // window.load_dynamic_update = function (last_msg) { // return new EventReceiver( // "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}", @@ -330,11 +381,6 @@ // } $(function () { - // load_dynamic_update({{last_msg}}); - {% if request.in_contest %} - setInterval(update_ranking, 60 * 1000); - {% endif %} - var url = '{{ url('contest_participation', contest.key, '__username__') }}'; var placeholder = $('#search-contest').replaceWith($(' {% endif %} - - + + + + {% include "contest/ranking-table.html" %} {% endblock %}