Exemplo n.º 1
0
    def get_context_data(self, **kwargs):
        context = super(UserAboutPage, self).get_context_data(**kwargs)
        ratings = context['ratings'] = self.object.ratings.order_by('-contest__end_time').select_related('contest') \
            .defer('contest__description')

        context['rating_data'] = mark_safe(json.dumps([{
            'label': rating.contest.name,
            'rating': rating.rating,
            'ranking': rating.rank,
            'link': reverse('contest_ranking', args=(rating.contest.key,)),
            'timestamp': (rating.contest.end_time - EPOCH).total_seconds() * 1000,
            'date': date_format(rating.contest.end_time, _('M j, Y, G:i')),
            'class': rating_class(rating.rating),
            'height': '%.3fem' % rating_progress(rating.rating)
        } for rating in ratings]))

        if ratings:
            user_data = self.object.ratings.aggregate(Min('rating'), Max('rating'))
            global_data = Rating.objects.aggregate(Min('rating'), Max('rating'))
            min_ever, max_ever = global_data['rating__min'], global_data['rating__max']
            min_user, max_user = user_data['rating__min'], user_data['rating__max']
            delta = max_user - min_user
            ratio = (max_ever - max_user) / (max_ever - min_ever) if max_ever != min_ever else 1.0
            context['max_graph'] = max_user + ratio * delta
            context['min_graph'] = min_user + ratio * delta - delta
        return context
Exemplo n.º 2
0
Arquivo: user.py Projeto: DMOJ/site
    def get_context_data(self, **kwargs):
        context = super(UserAboutPage, self).get_context_data(**kwargs)
        ratings = context['ratings'] = self.object.ratings.order_by('-contest__end_time').select_related('contest') \
            .defer('contest__description')

        context['rating_data'] = mark_safe(json.dumps([{
            'label': rating.contest.name,
            'rating': rating.rating,
            'ranking': rating.rank,
            'link': reverse('contest_ranking', args=(rating.contest.key,)),
            'timestamp': (rating.contest.end_time - EPOCH).total_seconds() * 1000,
            'date': date_format(rating.contest.end_time, _('M j, Y, G:i')),
            'class': rating_class(rating.rating),
            'height': '%.3fem' % rating_progress(rating.rating)
        } for rating in ratings]))

        if ratings:
            user_data = self.object.ratings.aggregate(Min('rating'), Max('rating'))
            global_data = Rating.objects.aggregate(Min('rating'), Max('rating'))
            min_ever, max_ever = global_data['rating__min'], global_data['rating__max']
            min_user, max_user = user_data['rating__min'], user_data['rating__max']
            delta = max_user - min_user
            ratio = (max_ever - max_user + 0.0) / (max_ever - min_ever)
            context['max_graph'] = max_user + ratio * delta
            context['min_graph'] = min_user + ratio * delta - delta
        return context
Exemplo n.º 3
0
    def get_context_data(self, **kwargs):
        context = super(UserAboutPage, self).get_context_data(**kwargs)
        ratings = context['ratings'] = self.object.ratings.order_by('-contest__end_time').select_related('contest') \
            .defer('contest__description')

        context['rating_data'] = mark_safe(
            json.dumps([{
                'label':
                rating.contest.name,
                'rating':
                rating.rating,
                'ranking':
                rating.rank,
                'link':
                reverse('contest_ranking', args=(rating.contest.key, )),
                'timestamp':
                (rating.contest.end_time - EPOCH).total_seconds() * 1000,
                'date':
                date_format(rating.contest.end_time, _('M j, Y, G:i')),
                'class':
                rating_class(rating.rating),
                'height':
                '%.3fem' % rating_progress(rating.rating),
            } for rating in ratings]))

        context['awards'] = self.get_awards(ratings)

        if ratings:
            user_data = self.object.ratings.aggregate(Min('rating'),
                                                      Max('rating'))
            global_data = Rating.objects.aggregate(Min('rating'),
                                                   Max('rating'))
            min_ever, max_ever = global_data['rating__min'], global_data[
                'rating__max']
            min_user, max_user = user_data['rating__min'], user_data[
                'rating__max']
            delta = max_user - min_user
            ratio = (max_ever - max_user) / (
                max_ever - min_ever) if max_ever != min_ever else 1.0
            context['max_graph'] = max_user + ratio * delta
            context['min_graph'] = min_user + ratio * delta - delta

        submissions = (self.object.submission_set.annotate(
            date_only=Cast('date', DateField())).values('date_only').annotate(
                cnt=Count('id')))

        context['submission_data'] = mark_safe(
            json.dumps({
                date_counts['date_only'].isoformat(): date_counts['cnt']
                for date_counts in submissions
            }))
        context['submission_metadata'] = mark_safe(
            json.dumps({
                'min_year': (self.object.submission_set.annotate(
                    year_only=ExtractYear('date')).aggregate(
                        min_year=Min('year_only'))['min_year']),
            }))

        return context
Exemplo n.º 4
0
 def get_user_css_class(cls,
                        display_rank,
                        rating,
                        rating_colors=settings.DMOJ_RATING_COLORS):
     if rating_colors:
         return 'rating %s %s' % (rating_class(rating) if rating is not None
                                  else 'rate-none', display_rank)
     return display_rank
Exemplo n.º 5
0
def get_user_rating(username, rating):
    element = Element('a', {
        'class': 'rate-group',
        'href': reverse('user_page', args=[username])
    })
    if rating:
        rating_css = rating_class(rating)
        rate_box = Element('span', {'class': 'rate-box ' + rating_css})
        rate_box.append(
            Element('span',
                    {'style': 'height: %3.fem' % rating_progress(rating)}))
        user = Element('span', {'class': 'rating ' + rating_css})
        user.text = username
        element.append(rate_box)
        element.append(user)
    else:
        element.text = username
    return element
Exemplo n.º 6
0
def get_user_rating(username, data):
    if not data:
        element = Element('span')
        element.text = username
        return element

    rating = data[1]
    element = Element('a', {'class': 'rate-group', 'href': reverse('user_page', args=[username])})
    if rating:
        rating_css = rating_class(rating)
        rate_box = Element('span', {'class': 'rate-box ' + rating_css})
        rate_box.append(Element('span', {'style': 'height: %3.fem' % rating_progress(rating)}))
        user = Element('span', {'class': 'rating ' + rating_css})
        user.text = username
        element.append(rate_box)
        element.append(user)
    else:
        element.text = username
    return element
Exemplo n.º 7
0
Arquivo: profile.py Projeto: DMOJ/site
 def get_user_css_class(cls, display_rank, rating, rating_colors=getattr(settings, 'DMOJ_RATING_COLORS', False)):
     if rating_colors:
         return 'rating %s %s' % (rating_class(rating) if rating is not None else 'rate-none', display_rank)
     return display_rank
Exemplo n.º 8
0
def get_class(rating):
    return 'rate-none' if rating is None else rating_class(int(rating))
Exemplo n.º 9
0
def get_class(rating):
    return rating_class(int(rating)) if rating else 'rate-none'