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):
|
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')
|
.prefetch_related('user__organizations')
|
||||||
.extra(select={'round_score': 'round(score, 6)'})
|
.extra(select={'round_score': 'round(score, 6)'})
|
||||||
.order_by('is_disqualified', '-round_score', 'cumtime', 'tiebreaker'))
|
.order_by('is_disqualified', '-round_score', 'cumtime', 'tiebreaker'))
|
||||||
|
|
||||||
|
|
||||||
def get_contest_ranking_list(request, contest, participation=None, ranking_list=contest_ranking_list,
|
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'))
|
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'))
|
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,
|
'problems': problems,
|
||||||
'contest': contest,
|
'contest': contest,
|
||||||
'has_rating': contest.ratings.exists(),
|
'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()
|
users, problems = self.get_ranking_list()
|
||||||
context['users'] = users
|
context['users'] = users
|
||||||
context['problems'] = problems
|
context['problems'] = problems
|
||||||
context['last_msg'] = event.last()
|
|
||||||
context['tab'] = self.tab
|
context['tab'] = self.tab
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -759,6 +759,7 @@ class ContestParticipationList(LoginRequiredMixin, ContestRankingBase):
|
||||||
context['has_rating'] = False
|
context['has_rating'] = False
|
||||||
context['now'] = timezone.now()
|
context['now'] = timezone.now()
|
||||||
context['rank_header'] = _('Participation')
|
context['rank_header'] = _('Participation')
|
||||||
|
context['participation_tab'] = True
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block user_data %}
|
{% block user_data %}
|
||||||
|
{% if user.participation.virtual %}
|
||||||
|
<sup style="color:grey">[{{user.participation.virtual}}]</sup>
|
||||||
|
{% endif %}
|
||||||
{% if can_edit %}
|
{% if can_edit %}
|
||||||
<span class="contest-participation-operation">
|
<span class="contest-participation-operation">
|
||||||
<form action="{{ url('contest_participation_disqualify', contest.key) }}" method="post">
|
<form action="{{ url('contest_participation_disqualify', contest.key) }}" method="post">
|
||||||
|
@ -63,7 +66,7 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block row_extra %}
|
{% 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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block before_point %}
|
{% block before_point %}
|
||||||
|
|
|
@ -284,14 +284,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let non_virtual_rank = [];
|
||||||
|
let original_rank = [];
|
||||||
|
|
||||||
function renew_filter() {
|
function renew_filter() {
|
||||||
var checkboxes = [
|
var checkboxes = [
|
||||||
'#show-organizations-checkbox',
|
'#show-organizations-checkbox',
|
||||||
'#show-fullnames-checkbox',
|
'#show-fullnames-checkbox',
|
||||||
'#show-friends-checkbox',
|
'#show-friends-checkbox',
|
||||||
'#show-total-score-checkbox',
|
'#show-total-score-checkbox',
|
||||||
|
'#show-virtual-checkbox'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
get_all_rank();
|
||||||
|
get_non_virtual_rank();
|
||||||
|
|
||||||
for (var i of checkboxes) {
|
for (var i of checkboxes) {
|
||||||
var $box = $(i);
|
var $box = $(i);
|
||||||
if ($box.is(':checked')) {
|
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) {
|
// window.load_dynamic_update = function (last_msg) {
|
||||||
// return new EventReceiver(
|
// return new EventReceiver(
|
||||||
// "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}",
|
// "{{ EVENT_DAEMON_LOCATION }}", "{{ EVENT_DAEMON_POLL_LOCATION }}",
|
||||||
|
@ -330,11 +381,6 @@
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$(function () {
|
$(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 url = '{{ url('contest_participation', contest.key, '__username__') }}';
|
||||||
var placeholder = $('#search-contest').replaceWith($('<select>').attr({
|
var placeholder = $('#search-contest').replaceWith($('<select>').attr({
|
||||||
id: 'search-contest'
|
id: 'search-contest'
|
||||||
|
@ -363,6 +409,7 @@
|
||||||
$('#show-fullnames-checkbox').click(function () {
|
$('#show-fullnames-checkbox').click(function () {
|
||||||
$('.fullname-column').toggle();
|
$('.fullname-column').toggle();
|
||||||
});
|
});
|
||||||
|
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
$('#show-friends-checkbox').click(function() {
|
$('#show-friends-checkbox').click(function() {
|
||||||
let checked = $('#show-friends-checkbox').is(':checked');
|
let checked = $('#show-friends-checkbox').is(':checked');
|
||||||
|
@ -379,13 +426,30 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
{% endif %}
|
{% 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() {
|
$('#show-total-score-checkbox').click(function() {
|
||||||
$('.problem-score-col').toggle();
|
$('.problem-score-col').toggle();
|
||||||
})
|
})
|
||||||
|
|
||||||
highlightFirstSolve();
|
highlightFirstSolve();
|
||||||
renew_filter();
|
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>
|
</script>
|
||||||
|
@ -409,8 +473,10 @@
|
||||||
<input id="show-friends-checkbox" type="checkbox" style="vertical-align: bottom;">
|
<input id="show-friends-checkbox" type="checkbox" style="vertical-align: bottom;">
|
||||||
<label for="show-friends-checkbox" style="vertical-align: bottom; margin-right: 1em;">{{ _('Show friends only') }}</label>
|
<label for="show-friends-checkbox" style="vertical-align: bottom; margin-right: 1em;">{{ _('Show friends only') }}</label>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<input id="show-total-score-checkbox" type="checkbox" style="vertical-align: bottom;">
|
<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>
|
</div>
|
||||||
{% include "contest/ranking-table.html" %}
|
{% include "contest/ranking-table.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue