Add show virtual option
This commit is contained in:
parent
4cb2eaeaf1
commit
11700219b1
3 changed files with 82 additions and 12 deletions
|
@ -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):
|
||||
|
|
|
@ -32,6 +32,9 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block user_data %}
|
||||
{% if user.participation.virtual %}
|
||||
<sup style="color:grey">[{{user.participation.virtual}}]</sup>
|
||||
{% endif %}
|
||||
{% if can_edit %}
|
||||
<span class="contest-participation-operation">
|
||||
<form action="{{ url('contest_participation_disqualify', contest.key) }}" method="post">
|
||||
|
@ -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 %}
|
||||
|
|
|
@ -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($('<select>').attr({
|
||||
id: 'search-contest'
|
||||
|
@ -363,6 +409,7 @@
|
|||
$('#show-fullnames-checkbox').click(function () {
|
||||
$('.fullname-column').toggle();
|
||||
});
|
||||
|
||||
{% if request.user.is_authenticated %}
|
||||
$('#show-friends-checkbox').click(function() {
|
||||
let checked = $('#show-friends-checkbox').is(':checked');
|
||||
|
@ -379,13 +426,30 @@
|
|||
}
|
||||
})
|
||||
{% endif %}
|
||||
|
||||
$('#show-virtual-checkbox').click(function() {
|
||||
let checked = $('#show-virtual-checkbox').is(':checked');
|
||||
if (checked) {
|
||||
show_virtual();
|
||||
}
|
||||
else {
|
||||
hide_virtual();
|
||||
}
|
||||
})
|
||||
$('#show-total-score-checkbox').click(function() {
|
||||
$('.problem-score-col').toggle();
|
||||
})
|
||||
|
||||
highlightFirstSolve();
|
||||
renew_filter();
|
||||
{% if participation_tab %}
|
||||
$('#show-virtual-checkbox').hide();
|
||||
$('#show-virtual-label').hide();
|
||||
{% else %}
|
||||
hide_virtual();
|
||||
{% if request.in_contest %}
|
||||
setInterval(update_ranking, 60 * 1000);
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
});
|
||||
</script>
|
||||
|
@ -410,7 +474,9 @@
|
|||
<label for="show-friends-checkbox" style="vertical-align: bottom; margin-right: 1em;">{{ _('Show friends only') }}</label>
|
||||
{% endif %}
|
||||
<input id="show-total-score-checkbox" type="checkbox" style="vertical-align: bottom; ">
|
||||
<label for="show-total-score-checkbox" style="vertical-align: bottom;">{{ _('Total score only') }}</label>
|
||||
<label for="show-total-score-checkbox" style="vertical-align: bottom; margin-right: 1em;">{{ _('Total score only') }}</label>
|
||||
<input id="show-virtual-checkbox" type="checkbox" style="vertical-align: bottom;">
|
||||
<label id="show-virtual-label" for="show-virtual-checkbox" style="vertical-align: bottom;">{{ _('Show virtual participation') }}</label>
|
||||
</div>
|
||||
{% include "contest/ranking-table.html" %}
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue