コード例 #1
0
ファイル: user.py プロジェクト: DMOJ/site
 def get_context_data(self, **kwargs):
     context = super(UserList, self).get_context_data(**kwargs)
     context['users'] = ranker(context['users'], rank=self.paginate_by * (context['page_obj'].number - 1))
     context['first_page_href'] = '.'
     context.update(self.get_sort_context())
     context.update(self.get_sort_paginate_context())
     return context
コード例 #2
0
ファイル: user.py プロジェクト: 067953240/site
def users(request):
    if request.user.is_authenticated() and request.user.profile.contest.current is not None:
        return contest_ranking_view(request, request.user.profile.contest.current.contest)
    return render(request, 'user/list.jade', {
        'users': ranker(Profile.objects.filter(points__gt=0, user__is_active=True, submission__points__gt=0)
                               .annotate(problems=Count('submission__problem', distinct=True)).order_by('-points')
                               .select_related('user__username')
                               .only('display_rank', 'user__username', 'name', 'points', 'rating')),
        'title': 'Users'
    })
コード例 #3
0
ファイル: organization.py プロジェクト: frenzybenzy/site
 def get_context_data(self, **kwargs):
     context = super(OrganizationUsers, self).get_context_data(**kwargs)
     context['title'] = '%s Members' % self.object.name
     context['users'] = ranker(chain(
         self.object.members.filter(submission__points__gt=0).order_by('-points')
             .annotate(problems=Count('submission__problem', distinct=True)),
         self.object.members.annotate(problems=Max('submission__points')).filter(problems=0),
         self.object.members.annotate(problems=Count('submission__problem', distinct=True)).filter(problems=0),
     ))
     context['partial'] = True
     return context
コード例 #4
0
ファイル: contests.py プロジェクト: WallE256/site
def contest_ranking_ajax(request, contest):
    contest, exists = _find_contest(request, contest)
    if not exists:
        return HttpResponseBadRequest('Invalid contest', content_type='text/plain')
    problems = list(contest.contest_problems.select_related('problem').defer('problem__description').order_by('order'))
    return render(request, 'contest/ranking_table.jade', {
        'users': ranker(contest_ranking_list(contest, problems), key=attrgetter('points', 'cumtime')),
        'problems': problems,
        'contest': contest,
        'show_organization': True,
        'has_rating': contest.ratings.exists(),
    })
コード例 #5
0
ファイル: contests.py プロジェクト: aurpine/DMOJ-site
def get_contest_ranking_list(request, contest, participation=None, ranking_list=contest_ranking_list,
                             show_current_virtual=True, 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'))

    if show_current_virtual:
        if participation is None and request.user.is_authenticated():
            participation = request.user.profile.current_contest
            if participation is None or participation.contest_id != contest.id:
                participation = None
        if participation is not None and participation.virtual:
            users = chain([('-', get_participation_ranking_profile(contest, participation, problems))], users)
    return users, problems
コード例 #6
0
ファイル: organization.py プロジェクト: DMOJ/site
 def get_context_data(self, **kwargs):
     context = super(OrganizationUsers, self).get_context_data(**kwargs)
     context['title'] = _('%s Members') % self.object.name
     context['users'] = ranker(chain(*[
         i.select_related('user').defer('about') for i in (
             self.object.members.filter(submission__points__gt=0, is_unlisted=False)
                 .order_by('-performance_points')
                 .annotate(problems=Count('submission__problem', distinct=True)),
             self.object.members.filter(is_unlisted=False)
                                .annotate(problems=Max('submission__points')).filter(problems=0),
             self.object.members.filter(is_unlisted=False)
                                .annotate(problems=Count('submission__problem', distinct=True)).filter(problems=0),
         )
     ]))
     context['partial'] = True
     context['is_admin'] = self.can_edit_organization()
     context['kick_url'] = reverse('organization_user_kick', args=[self.object.id, self.object.slug])
     return context
コード例 #7
0
ファイル: contests.py プロジェクト: WallE256/site
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(),
    })
コード例 #8
0
ファイル: organization.py プロジェクト: luobuccc/DMOJ_site
 def get_context_data(self, **kwargs):
     context = super(OrganizationUsers, self).get_context_data(**kwargs)
     context['title'] = _('%s Members') % self.object.name
     context['users'] = ranker(
         chain(*[
             i.select_related('user').defer('about') for i in (
                 self.object.members.filter(submission__points__gt=0).
                 order_by('-performance_points').annotate(
                     problems=Count('submission__problem', distinct=True)),
                 self.object.members.annotate(
                     problems=Max('submission__points')).filter(problems=0),
                 self.object.members.annotate(problems=Count(
                     'submission__problem', distinct=True)).filter(
                         problems=0),
             )
         ]))
     context['partial'] = True
     context['is_admin'] = self.can_edit_organization()
     context['kick_url'] = reverse('organization_user_kick',
                                   args=[self.object.key])
     return context
コード例 #9
0
 def get_context_data(self, **kwargs):
     context = super(OrganizationUsers, self).get_context_data(**kwargs)
     context['title'] = '%s Members' % self.object.name
     context['users'] = ranker(
         chain(*[
             i.select_related('user__username', 'organization').defer(
                 'about', 'organization__about')
             for i in (
                 self.object.members.filter(
                     submission__points__gt=0).order_by('-points').annotate(
                         problems=Count('submission__problem',
                                        distinct=True)),
                 self.object.members.annotate(
                     problems=Max('submission__points')).filter(problems=0),
                 self.object.members.annotate(problems=Count(
                     'submission__problem', distinct=True)).filter(
                         problems=0),
             )
         ]))
     context['partial'] = True
     return context
コード例 #10
0
ファイル: contests.py プロジェクト: Phoenix1369/site
def get_contest_ranking_list(request,
                             contest,
                             participation=None,
                             ranking_list=contest_ranking_list,
                             show_current_virtual=True,
                             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'))

    if show_current_virtual:
        if participation is None and request.user.is_authenticated:
            participation = request.user.profile.current_contest
            if participation is None or participation.contest_id != contest.id:
                participation = None
        if participation is not None and participation.virtual:
            users = chain([('-',
                            get_participation_ranking_profile(
                                contest, participation, problems))], users)
    return users, problems
コード例 #11
0
ファイル: contests.py プロジェクト: oznakn/cacik
def get_contest_ranking_list(request, contest, participation=None, ranking_list=contest_ranking_list,
                             show_current_virtual=True, ranker=ranker):
    problems = list(contest.contest_problems.select_related('problem').defer('problem__description').order_by('order'))

    is_scoreboard_frozen = not contest.can_see_real_scoreboard(request.user)
    is_show_full_scoreboard = 'all' in request.GET

    if contest.hide_scoreboard and contest.is_in_contest(request.user):
        return ([(_('???'), make_contest_ranking_profile(contest, request.profile.current_contest, problems, is_scoreboard_frozen=is_scoreboard_frozen))],
                problems)

    users = ranker(ranking_list(contest, problems, is_scoreboard_frozen=is_scoreboard_frozen, is_show_full_scoreboard=is_show_full_scoreboard),
                key=attrgetter('points', 'cumtime'))

    if show_current_virtual:
        if participation is None and request.user.is_authenticated:
            participation = request.profile.current_contest
            if participation is None or participation.contest_id != contest.id:
                participation = None
        if participation is not None and participation.virtual:
            users = chain([('-', make_contest_ranking_profile(contest, participation, problems, is_scoreboard_frozen=is_scoreboard_frozen))], users)
    return users, problems
コード例 #12
0
ファイル: contests.py プロジェクト: projectstowork1/site
def contest_ranking_ajax(request, key):
    contest, exists = _find_contest(request, key)
    if not exists:
        return HttpResponseBadRequest('Invalid contest',
                                      content_type='text/plain')
    problems = list(
        contest.contest_problems.select_related('problem').defer(
            'problem__description').order_by('order'))
    return render(
        request, 'contest/ranking_table.jade', {
            'users':
            ranker(contest_ranking_list(contest, problems),
                   key=attrgetter('points', 'cumtime')),
            'problems':
            problems,
            'contest':
            contest,
            'show_organization':
            True,
            'has_rating':
            contest.ratings.exists(),
        })
コード例 #13
0
ファイル: contests.py プロジェクト: marawan31/site
def get_contest_ranking_list(request,
                             contest,
                             participation=None,
                             ranking_list=contest_ranking_list,
                             show_current_virtual=True,
                             ranker=ranker):
    problems = list(
        contest.contest_problems.select_related('problem').defer(
            'problem__description').order_by('order'))

    if contest.hide_scoreboard and contest.is_in_contest(request):
        return [(_('???'),
                 get_participation_ranking_profile(
                     contest, request.user.profile.current_contest,
                     problems))], problems

    users = ranker(ranking_list(contest, problems),
                   key=attrgetter('points', 'cumtime'))

    if show_current_virtual:
        if participation is None and request.user.is_authenticated:
            participation = request.user.profile.current_contest
            if participation is None or participation.contest_id != contest.id:
                participation = None
        if participation is not None and participation.virtual:
            users = chain([('-',
                            get_participation_ranking_profile(
                                contest, participation, problems))], users)
        if not request.user.is_authenticated or not request.user.is_superuser:
            usersCount = [0]

            def users_filter(user_tuple):
                usersCount[0] = usersCount[0] + 1
                if user_tuple[1].user == request.user:
                    return True
                return usersCount[0] <= 5

            users = ifilter(users_filter, users)
    return users, problems
コード例 #14
0
def api_v2_user_info(request):
    """
    {
        "points": 100.0,
        "rating": 2452,
        "rank": "user",
        "organizations": [],
        "solved_problems": ["ccc14s4", ...],
        "attempted_problems": [
            {
                "code": "Hello, World!",
                "points": 1.0,
                "max_points": 2.0
            }
        ],
        "authored_problems": ["dmpg16s4"],
        "contest_history": [
            {
                "contest": {
                    "code": "halloween14",
                    "name": "Kemonomimi Party",
                    "tags": ["seasonal"],
                    "time_limit": null,
                    "start_time": "2014-10-31T04:00:00+00:00",
                    "end_time": "2014-11-10T05:00:00+00:00"
                },
                "rank": 1,
                "rating:": 1800
            },
            // ...
        ]
    }
   """
    username = request.GET['username']
    if not username:
        return error("username argument not provided")
    try:
        profile = Profile.objects.get(user__username=username)
    except Profile.DoesNotExist:
        return error("no such user")

    last_rating = list(profile.ratings.order_by('-contest__end_time'))

    resp = {
        "rank": profile.display_rank,
        "organizations": list(profile.organizations.values_list('key', flat=True))
    }

    contest_history = []
    for participation in (ContestParticipation.objects.filter(user=profile, virtual=0, contest__is_public=True)
                                  .order_by('-contest__end_time')):
        contest = participation.contest

        problems = list(contest.contest_problems.select_related('problem').defer('problem__description').order_by('order'))
        rank, result = filter(lambda data: data[1].user == profile.user, ranker(contest_ranking_list(contest, problems), key=attrgetter('points', 'cumtime')))[0]

        contest_history.append({
            'contest': {
                'code': contest.key,
                'name': contest.name,
                'tags': list(contest.tags.values_list('name', flat=True)),
                'time_limit': contest.time_limit and contest.time_limit.total_seconds(),
                'start_time': contest.start_time.isoformat(),
                'end_time': contest.end_time.isoformat(),
            },
            'rank': rank,
            'rating': result.participation_rating,
        })

    resp['contests'] = {
        "current_rating": last_rating[0].rating if last_rating else None,
        "volatility": last_rating[0].volatility if last_rating else None,
        'history': contest_history,
    }

    solved_problems = []
    attempted_problems = []

    problem_data = (Submission.objects.filter(points__gt=0, user=profile, problem__is_public=True)
                    .annotate(max_pts=Max('points'))
                    .values_list('max_pts', 'problem__points', 'problem__code')
                    .distinct())
    for awarded_pts, max_pts, problem in problem_data:
        if awarded_pts == max_pts:
            solved_problems.append(problem)
        else:
            attempted_problems.append({
                'awarded': awarded_pts,
                'max': max_pts,
                'problem': problem
            })

    resp['problems'] = {
        'points': profile.points,
        'solved': solved_problems,
        'attempted': attempted_problems,
        'authored': list(Problem.objects.filter(authors=profile).values_list('code', flat=True))
    }

    return JsonResponse(resp)
コード例 #15
0
ファイル: api_v2.py プロジェクト: DMOJ/site
def api_v2_user_info(request):
    """
    {
        "points": 100.0,
        "rating": 2452,
        "rank": "user",
        "organizations": [],
        "solved_problems": ["ccc14s4", ...],
        "attempted_problems": [
            {
                "code": "Hello, World!",
                "points": 1.0,
                "max_points": 2.0
            }
        ],
        "authored_problems": ["dmpg16s4"],
        "contest_history": [
            {
                "contest": {
                    "code": "halloween14",
                    "name": "Kemonomimi Party",
                    "tags": ["seasonal"],
                    "time_limit": null,
                    "start_time": "2014-10-31T04:00:00+00:00",
                    "end_time": "2014-11-10T05:00:00+00:00"
                },
                "rank": 1,
                "rating:": 1800
            },
            // ...
        ]
    }
   """
    try:
        username = request.GET['username']
    except KeyError:
        return error("no username passed")
    if not username:
        return error("username argument not provided")
    try:
        profile = Profile.objects.get(user__username=username)
    except Profile.DoesNotExist:
        return error("no such user")

    last_rating = list(profile.ratings.order_by('-contest__end_time'))

    resp = {
        "rank": profile.display_rank,
        "organizations": list(profile.organizations.values_list('key', flat=True))
    }

    contest_history = []
    for participation in (ContestParticipation.objects.filter(user=profile, virtual=0, contest__is_public=True)
                                  .order_by('-contest__end_time')):
        contest = participation.contest

        problems = list(contest.contest_problems.select_related('problem').defer('problem__description')
                               .order_by('order'))
        rank, result = next(filter(lambda data: data[1].user == profile.user,
                                   ranker(contest_ranking_list(contest,problems), key=attrgetter('points', 'cumtime'))))

        contest_history.append({
            'contest': {
                'code': contest.key,
                'name': contest.name,
                'tags': list(contest.tags.values_list('name', flat=True)),
                'time_limit': contest.time_limit and contest.time_limit.total_seconds(),
                'start_time': contest.start_time.isoformat(),
                'end_time': contest.end_time.isoformat(),
            },
            'rank': rank,
            'rating': result.participation_rating,
        })

    resp['contests'] = {
        "current_rating": last_rating[0].rating if last_rating else None,
        "volatility": last_rating[0].volatility if last_rating else None,
        'history': contest_history,
    }

    solved_problems = []
    attempted_problems = []

    problem_data = (Submission.objects.filter(points__gt=0, user=profile, problem__is_public=True,
                                              problem__is_organization_private=False)
                    .annotate(max_pts=Max('points'))
                    .values_list('max_pts', 'problem__points', 'problem__code')
                    .distinct())
    for awarded_pts, max_pts, problem in problem_data:
        if awarded_pts == max_pts:
            solved_problems.append(problem)
        else:
            attempted_problems.append({
                'awarded': awarded_pts,
                'max': max_pts,
                'problem': problem
            })

    resp['problems'] = {
        'points': profile.points,
        'solved': solved_problems,
        'attempted': attempted_problems,
        'authored': list(Problem.objects.filter(is_public=True, is_organization_private=False, authors=profile)
                                .values_list('code', flat=True))
    }

    return JsonResponse(resp)
コード例 #16
0
ファイル: organization.py プロジェクト: Ninjaclasher/site
def users_for_template(users):
    return ranker(
        users.filter(is_unlisted=False).order_by(
            '-performance_points',
            '-problem_count').select_related('user').defer(
                'about', 'user_script', 'notes'))