Exemple #1
0
 def get_context_data(self, **kwargs):
     context = super(ProblemSubmissions, self).get_context_data(**kwargs)
     if self.dynamic_update:
         context['dynamic_update'] = context['page_obj'].number == 1
         context['dynamic_problem_id'] = self.problem.id
         context['last_msg'] = event.last()
     return context
Exemple #2
0
def base_participation_list(request, contest, profile):
    contest, exists = _find_contest(request, contest)
    if not exists:
        return contest
    contest_access_check(request, contest)

    req_username = request.user.username if request.user.is_authenticated() else None
    prof_username = profile.user.username

    queryset = contest.users.filter(user=profile, virtual__gte=0).order_by('-virtual')
    live_link = format_html('<a href="{2}#!{1}">{0}</a>', _('Live'), prof_username,
                            reverse('contest_ranking', args=[contest.key]))
    users, problems = get_contest_ranking_list(
        request, contest, show_current_virtual=False,
        ranking_list=partial(base_contest_ranking_list, for_user=profile.id, queryset=queryset),
        ranker=lambda users, key: ((user.participation.virtual or live_link, user) for user in users))
    return render(request, 'contest/ranking.jade', {
        'users': users,
        'title': _('Your participation in %s') % contest.name if req_username == prof_username else
        _("%s's participation in %s") % (prof_username, contest.name),
        'content_title': contest.name,
        'subtitle': _('Your participation') if req_username == prof_username else _(
            "%s's participation") % prof_username,
        'problems': problems,
        'contest': contest,
        'show_organization': False,
        'last_msg': event.last(),
        'has_rating': False,
        'rank_header': _('Participation')
    })
Exemple #3
0
 def get_context_data(self, **kwargs):
     context = super(ProblemSubmissionsBase, self).get_context_data(**kwargs)
     if self.dynamic_update:
         context['dynamic_update'] = context['page_obj'].number == 1
         context['dynamic_problem_id'] = self.problem.id
         context['last_msg'] = event.last()
     context['best_submissions_link'] = reverse('ranked_submissions', kwargs={'problem': self.problem.code})
     return context
Exemple #4
0
 def get_context_data(self, **kwargs):
     context = super(ProblemSubmissionsBase,
                     self).get_context_data(**kwargs)
     if self.dynamic_update:
         context['dynamic_update'] = context['page_obj'].number == 1
         context['dynamic_problem_id'] = self.problem.id
         context['last_msg'] = event.last()
     context['best_submissions_link'] = reverse(
         'ranked_submissions', kwargs={'problem': self.problem.code})
     return context
Exemple #5
0
    def get_context_data(self, **kwargs):
        context = super(AllSubmissions, self).get_context_data(**kwargs)
        context['dynamic_update'] = context['page_obj'].number == 1
        context['last_msg'] = event.last()

        context['all_languages'] = Language.objects.all().values_list('key', 'name')
        context['selected_languages'] = self.selected_languages

        context['all_statuses'] = self.get_searchable_status_codes()
        context['selected_statuses'] = self.selected_statuses
        return context
Exemple #6
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        if not self.object.can_see_own_scoreboard(self.request.user):
            raise Http404()

        users, problems = self.get_ranking_list()
        context['users'] = users
        context['problems'] = problems
        context['last_msg'] = event.last()
        context['tab'] = self.tab
        return context
Exemple #7
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        if not self.object.can_see_scoreboard(self.request):
            raise Http404()

        users, problems = self.get_ranking_list()
        context['users'] = users
        context['problems'] = problems
        context['last_msg'] = event.last()
        context['tab'] = self.tab
        return context
Exemple #8
0
def base_participation_list(request, contest, profile):
    contest, exists = _find_contest(request, contest)
    if not exists:
        return contest
    if not contest.can_see_scoreboard(request):
        raise Http404()

    req_username = request.user.username if request.user.is_authenticated else None
    prof_username = profile.user.username

    queryset = contest.users.filter(user=profile,
                                    virtual__gte=0).order_by('-virtual')
    live_link = format_html(u'<a href="{2}#!{1}">{0}</a>', _('Live'),
                            prof_username,
                            reverse('contest_ranking', args=[contest.key]))
    users, problems = get_contest_ranking_list(
        request,
        contest,
        show_current_virtual=False,
        ranking_list=partial(base_contest_ranking_list,
                             for_user=profile.id,
                             queryset=queryset),
        ranker=lambda users, key: (
            (user.participation.virtual or live_link, user) for user in users))
    return render(
        request,
        'contest/ranking.html',
        {
            'users':
            users,
            'title':
            _('Your participation in %s') % contest.name if req_username
            == prof_username else _("%s's participation in %s") %
            (prof_username, contest.name),
            'content_title':
            contest.name,
            # 'subtitle': _('Your participation') if req_username == prof_username else _(
            #    "%s's participation") % prof_username,
            'problems':
            problems,
            'contest':
            contest,
            'last_msg':
            event.last(),
            'has_rating':
            False,
            'now':
            timezone.now(),
            'rank_header':
            _('Participation'),
            'tab':
            'participation',
        })
Exemple #9
0
    def get_context_data(self, **kwargs):
        context = super(AllSubmissions, self).get_context_data(**kwargs)
        context['dynamic_update'] = context['page_obj'].number == 1
        context['last_msg'] = event.last()

        context['all_languages'] = Language.objects.all().values_list(
            'key', 'name')
        context['selected_languages'] = self.selected_languages

        context['all_statuses'] = self.get_searchable_status_codes()
        context['selected_statuses'] = self.selected_statuses
        return context
Exemple #10
0
 def get_context_data(self, **kwargs):
     context = super(SubmissionStatus, self).get_context_data(**kwargs)
     submission = self.object
     context['last_msg'] = event.last()
     context['test_cases'] = submission.test_cases.all()
     context['time_limit'] = submission.problem.time_limit
     try:
         lang_limit = submission.problem.language_limits.get(language=submission.language)
     except ObjectDoesNotExist:
         pass
     else:
         context['time_limit'] = lang_limit.time_limit
     return context
Exemple #11
0
 def get_context_data(self, **kwargs):
     context = super(SubmissionStatus, self).get_context_data(**kwargs)
     submission = self.object
     context['last_msg'] = event.last()
     context['batches'] = group_test_cases(submission.test_cases.all())
     context['time_limit'] = submission.problem.time_limit
     try:
         lang_limit = submission.problem.language_limits.get(language=submission.language)
     except ObjectDoesNotExist:
         pass
     else:
         context['time_limit'] = lang_limit.time_limit
     return context
Exemple #12
0
def contest_ranking_view(request, contest, participation=None):
    contest_access_check(request, contest)
    users, problems = get_contest_ranking_list(request, contest, participation)
    return render(request, 'contest/ranking.jade', {
        'users': users,
        'title': _('%s Rankings') % contest.name,
        'content_title': contest.name,
        'subtitle': _('Rankings'),
        'problems': problems,
        'contest': contest,
        'show_organization': True,
        'last_msg': event.last(),
        'has_rating': contest.ratings.exists(),
    })
Exemple #13
0
 def get_context_data(self, **kwargs):
     context = super(SubmissionStatus, self).get_context_data(**kwargs)
     submission = self.object
     context['last_msg'] = event.last()
     context['batches'] = group_test_cases(submission.test_cases.all())
     context['time_limit'] = submission.problem.time_limit
     context['raw_source'] = submission.source.rstrip('\n')
     context['highlighted_source'] = highlight_code(submission.source, submission.language.pygments)
     try:
         lang_limit = submission.problem.language_limits.get(language=submission.language)
     except ObjectDoesNotExist:
         pass
     else:
         context['time_limit'] = lang_limit.time_limit
     return context
Exemple #14
0
    def get_context_data(self, **kwargs):
        context = super(AllSubmissions, self).get_context_data(**kwargs)
        context['dynamic_update'] = context['page_obj'].number == 1
        context['last_msg'] = event.last()

        context['all_languages'] = Language.objects.all().values_list(
            'key', 'name')
        context['selected_languages'] = self.selected_languages

        context['all_statuses'] = self.get_searchable_status_codes()
        context['selected_statuses'] = self.selected_statuses
        context['page_suffix'] = suffix = (
            '?' + self.request.GET.urlencode()) if self.request.GET else ''
        context['first_page_href'] += suffix
        return context
Exemple #15
0
def contest_ranking_view(request, contest, participation=None):
    contest_access_check(request, contest)
    users, problems = get_contest_ranking_list(request, contest, participation)
    return render(
        request, 'contest/ranking.jade', {
            'users': users,
            'title': _('%s Rankings') % contest.name,
            'content_title': contest.name,
            'subtitle': _('Rankings'),
            'problems': problems,
            'contest': contest,
            'show_organization': True,
            'last_msg': event.last(),
            'has_rating': contest.ratings.exists(),
        })
Exemple #16
0
def contest_ranking_view(request, contest, participation=None):
    contest_access_check(request, contest)
    users, problems = get_contest_ranking_list(request, contest, participation)

    # TODO: When this is changed to be a view, use LoadSelect2Mixin instead of this
    select2_css = getattr(settings, 'SELECT2_CSS_URL', None)
    select2_js = getattr(settings, 'SELECT2_JS_URL', None)
    has_select2 = select2_css is not None and select2_js is not None

    context = {
        'users': users,
        'title': _('%s Rankings') % contest.name,
        'content_title': contest.name,
        'problems': problems,
        'contest': contest,
        'last_msg': event.last(),
        'has_rating': contest.ratings.exists(),
        'has_select2': has_select2,
        'SELECT2_CSS_URL': select2_css,
        'SELECT2_JS_URL': select2_js,
    }

    # TODO: use ContestMixin when this becomes a class-based view
    if request.user.is_authenticated:
        profile = request.user.profile
        in_contest = context['in_contest'] = (
            profile.current_contest is not None
            and profile.current_contest.contest == contest)
        if in_contest:
            context['participation'] = profile.current_contest
            context['participating'] = True
        else:
            try:
                context['participation'] = profile.contest_history.get(
                    contest=contest, virtual=0)
            except ContestParticipation.DoesNotExist:
                context['participating'] = False
                context['participation'] = None
            else:
                context['participating'] = True
    else:
        context['participating'] = False
        context['participation'] = None
        context['in_contest'] = False
    context['now'] = timezone.now()

    return render(request, 'contest/ranking.jade', context)
Exemple #17
0
def contest_ranking_view(request, contest):
    if not request.user.has_perm('judge.see_private_contest'):
        if not contest.is_public:
            raise Http404()
        if contest.start_time is not None and contest.start_time > timezone.now():
            raise Http404()

    problems = list(contest.contest_problems.select_related('problem').defer('problem__description').order_by('order'))
    return render(request, 'contest/ranking.jade', {
        'users': ranker(contest_ranking_list(contest, problems), key=attrgetter('points', 'cumtime')),
        'title': '%s Rankings' % contest.name,
        'content_title': contest.name,
        'subtitle': 'Rankings',
        'problems': problems,
        'contest': contest,
        'show_organization': True,
        'last_msg': event.last(),
        'has_rating': contest.ratings.exists(),
    })
Exemple #18
0
def contest_ranking_view(request, contest):
    if not request.user.has_perm('judge.see_private_contest'):
        if not contest.is_public:
            raise Http404()
        if contest.start_time is not None and contest.start_time > timezone.now():
            raise Http404()

    problems = list(contest.contest_problems.select_related('problem').defer('problem__description').order_by('order'))
    return render(request, 'contest/ranking.jade', {
        'users': ranker(contest_ranking_list(contest, problems), key=attrgetter('points', 'cumtime')),
        'title': '%s Rankings' % contest.name,
        'content_title': contest.name,
        'subtitle': 'Rankings',
        'problems': problems,
        'contest': contest,
        'show_organization': True,
        'last_msg': event.last(),
        'has_rating': contest.ratings.exists(),
    })
Exemple #19
0
def contest_ranking_view(request, contest, participation=None):
    if not contest.can_see_scoreboard(request):
        raise Http404()

    users, problems = get_contest_ranking_list(request, contest, participation)

    context = {
        'users': users,
        'title': _('%s Rankings') % contest.name,
        'content_title': contest.name,
        'problems': problems,
        'contest': contest,
        'last_msg': event.last(),
        'has_rating': contest.ratings.exists(),
        'tab': 'ranking',
    }

    # TODO: use ContestMixin when this becomes a class-based view
    if request.user.is_authenticated:
        profile = request.user.profile
        in_contest = context['in_contest'] = (
            profile.current_contest is not None
            and profile.current_contest.contest == contest)
        if in_contest:
            context['participation'] = profile.current_contest
            context['participating'] = True
        else:
            try:
                context['participation'] = profile.contest_history.get(
                    contest=contest, virtual=0)
            except ContestParticipation.DoesNotExist:
                context['participating'] = False
                context['participation'] = None
            else:
                context['participating'] = True
    else:
        context['participating'] = False
        context['participation'] = None
        context['in_contest'] = False
    context['now'] = timezone.now()

    return render(request, 'contest/ranking.html', context)
Exemple #20
0
    def get_context_data(self, **kwargs):
        context = super(TicketList, self).get_context_data(**kwargs)

        page = context['page_obj']
        context['title'] = _('Tickets - Page %(number)d of %(total)d') % {
            'number': page.number,
            'total': page.paginator.num_pages,
        }
        context['can_edit_all'] = self.can_edit_all
        context['filter_status'] = {
            'own': self.GET_with_session('own'), 'user': self.filter_users, 'assignee': self.filter_assignees,
            'user_id': json.dumps(list(Profile.objects.filter(user__username__in=self.filter_users)
                                       .values_list('id', flat=True))),
            'assignee_id': json.dumps(list(Profile.objects.filter(user__username__in=self.filter_assignees)
                                           .values_list('id', flat=True))),
            'own_id': self.profile.id if self.GET_with_session('own') else 'null',
        }
        context['last_msg'] = event.last()
        context.update(paginate_query_context(self.request))
        return context
Exemple #21
0
    def get_context_data(self, **kwargs):
        context = super(TicketList, self).get_context_data(**kwargs)

        page = context['page_obj']
        context['title'] = _('Tickets - Page %(number)d of %(total)d') % {
            'number': page.number,
            'total': page.paginator.num_pages,
        }
        context['can_edit_all'] = self.can_edit_all
        context['filter_status'] = {
            'own': self.GET_with_session('own'), 'user': self.filter_users, 'assignee': self.filter_assignees,
            'user_id': json.dumps(list(Profile.objects.filter(user__username__in=self.filter_users)
                                       .values_list('id', flat=True))),
            'assignee_id': json.dumps(list(Profile.objects.filter(user__username__in=self.filter_assignees)
                                           .values_list('id', flat=True))),
            'own_id': self.profile.id if self.GET_with_session('own') else 'null',
        }
        context['last_msg'] = event.last()
        context.update(paginate_query_context(self.request))
        return context
Exemple #22
0
    def get_context_data(self, **kwargs):
        context = super(SubmissionStatus, self).get_context_data(**kwargs)
        submission = self.object
        context['last_msg'] = event.last()
        context['batches'] = group_test_cases(submission.test_cases.all())
        context['time_limit'] = submission.problem.time_limit

        contest = submission.contest_or_none
        prefix_length = 0
        if (contest is not None):
            prefix_length = contest.problem.output_prefix_override
        if ((contest is None or prefix_length > 0) or self.request.user.is_superuser):
            context['cases_data'] = get_problem_data(submission)

        try:
            lang_limit = submission.problem.language_limits.get(
                language=submission.language)
        except ObjectDoesNotExist:
            pass
        else:
            context['time_limit'] = lang_limit.time_limit
        return context
Exemple #23
0
 def get_context_data(self, **kwargs):
     context = super(AllSubmissions, self).get_context_data(**kwargs)
     context['dynamic_update'] = context['page_obj'].number == 1
     context['last_msg'] = event.last()
     context['stats_update_interval'] = self.stats_update_interval
     return context
Exemple #24
0
def contest_ranking_view(request, contest, participation=None):
    contest_access_check(request, contest)
    users, problems = get_contest_ranking_list(request, contest, participation)

    context = {
        'users': users,
        'title': _('%s Rankings') % contest.name,
        'content_title': contest.name,
        'problems': problems,
        'contest': contest,
        'last_msg': event.last(),
        'has_rating': contest.ratings.exists(),
        'tab': 'ranking',
    }

    # TODO: use ContestMixin when this becomes a class-based view
    if request.user.is_authenticated:
        profile = request.user.profile
        in_contest = context['in_contest'] = (
            profile.current_contest is not None
            and profile.current_contest.contest == contest)
        if in_contest:
            context['participation'] = profile.current_contest
            context['participating'] = True
        else:
            try:
                context['participation'] = profile.contest_history.get(
                    contest=contest, virtual=0)
            except ContestParticipation.DoesNotExist:
                context['participating'] = False
                context['participation'] = None
            else:
                context['participating'] = True
    else:
        context['participating'] = False
        context['participation'] = None
        context['in_contest'] = False
    context['now'] = timezone.now()

    if contest.use_balloons:
        import random
        seed = sum([p.id for p in problems])
        balloon_colors = [x for x in range(len(problems))]
        random.Random(seed).shuffle(balloon_colors)

        balloons = {}
        for idx, p in enumerate(problems):
            bid = balloon_colors[idx]
            balloons[p.problem.code] = {
                'url': static_files('balloons/balloon{}.png'.format(bid)),
                'problem': p.problem
            }
        context['balloons'] = balloons

        problems_by_users = {}
        for cp in contest.contest_problems.all():
            state = {}
            pid = cp.problem.code
            is_first_user = True
            for sub in cp.submissions.order_by('submission__date').all():
                s = sub.submission
                u = s.user.user.username
                cur = state[u] if u in state is not None else {
                    'try': 0,
                    'first': False,
                    'last_status': None,
                    'solved_at': None
                }

                if s.is_graded and cur['solved_at'] is None:
                    if s.result == 'AC':
                        cur['first'] = is_first_user
                        cur['solved_at'] = s.date
                        is_first_user = False
                    cur['try'] += s.result != 'AC'
                    cur['last_status'] = s.status
                    cur['state'] = best_solution_state(s.points,
                                                       s.problem.points)

                state[u] = cur
            problems_by_users[pid] = state

        def rank_suffix(r):
            return ["st", "nd", "rd", "th"][r - 1 if r <= 3 else 3]

        teams = []
        start_time = contest.start_time
        for u in users:
            rank = u[0]
            crp = u[1]  # contest ranking profile

            problems = []
            penalty = 0
            solved = 0
            u = crp.user.username
            for p in crp.problems:
                if p is not None:
                    solved += 1 if p.state == 'full-score' else 0
                    us = problems_by_users[p.code]
                    if us is not None:
                        info = us[u]
                        if info['solved_at']:
                            spend_time = (info['solved_at'] -
                                          start_time).total_seconds() / 60
                            penalty += 20 * info['try'] + spend_time
                        info['problem_code'] = p.code
                        problems.append(info)
                else:
                    problems.append(None)

            team = {
                'id': crp.id,
                'rank': rank,
                'rank_suffix': rank_suffix(rank),
                'penalty': penalty,
                'solved': solved,
                'solved_group': '',
                'user': crp.user,
                'problems': problems,
                'detail': crp
            }

            teams.append(team)

        def acm_scoring(item1, item2):
            if item1['solved'] > item2['solved']:
                return -1
            elif item1['solved'] == item2['solved']:
                if item1['penalty'] < item2['penalty']:
                    return -1
                else:
                    return 1
            else:
                return 0

        teams.sort(acm_scoring)
        for i in range(len(teams)):
            teams[i]['rank'] = i + 1
            teams[i]['rank_suffix'] = rank_suffix(i + 1)

        before_solved = -1
        for i, t in enumerate(teams):
            if before_solved != t['solved']:
                t['solved_group'] = 'first'
                if i > 0:
                    teams[i - 1]['solved_group'] += ' last'
            before_solved = t['solved']

        context['teams'] = teams

        return render(request, 'contest/spotboard.html', context)

    else:
        return render(request, 'contest/ranking.html', context)
Exemple #25
0
 def get_context_data(self, **kwargs):
     context = super(AllSubmissions, self).get_context_data(**kwargs)
     context['dynamic_update'] = context['page_obj'].number == 1 and self.request.user.is_staff
     context['last_msg'] = event.last()
     return context
Exemple #26
0
 def get_context_data(self, **kwargs):
     context = super(AllUserSubmissions, self).get_context_data(**kwargs)
     context['dynamic_update'] = context['page_obj'].number == 1
     context['dynamic_user_id'] = self.profile.id
     context['last_msg'] = event.last()
     return context
Exemple #27
0
 def get_context_data(self, **kwargs):
     context = super(TicketView, self).get_context_data(**kwargs)
     context['ticket_messages'] = self.object.messages.select_related('user__user')
     context['assignees'] = self.object.assignees.select_related('user')
     context['last_msg'] = event.last()
     return context
Exemple #28
0
 def get_context_data(self, **kwargs):
     context = super(SubmissionStatus, self).get_context_data(**kwargs)
     submission = self.object
     context['last_msg'] = event.last()
     context['test_cases'] = submission.test_cases.all()
     return context
Exemple #29
0
 def get_context_data(self, **kwargs):
     context = super(TicketView, self).get_context_data(**kwargs)
     context['messages'] = self.object.messages.select_related('user__user')
     context['assignees'] = self.object.assignees.select_related('user')
     context['last_msg'] = event.last()
     return context
Exemple #30
0
 def get_context_data(self, **kwargs):
     context = super(AllSubmissions, self).get_context_data(**kwargs)
     context['dynamic_update'] = context['page_obj'].number == 1
     context['last_msg'] = event.last()
     return context
Exemple #31
0
def event_config(request):
    return {'last_msg': event.last()}