Skip to content

Commit

Permalink
Edit displaying rating and points rank for unlisted (#115)
Browse files Browse the repository at this point in the history
* Edit displaying rating and points rank for unlisted

* Edit rating/points rank of unlisted users and cache get_rank functions
  • Loading branch information
anhkha2003 authored Jun 5, 2024
1 parent 570c307 commit 46c950d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
6 changes: 4 additions & 2 deletions judge/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def wrapper(*args, **kwargs):
return result
result = func(*args, **kwargs)
if result is None:
result = NONE_RESULT
_set(cache_key, result, timeout)
cache_result = NONE_RESULT
else:
cache_result = result
_set(cache_key, cache_result, timeout)
return result

def dirty(*args, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions judge/ratings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.db.models.functions import Coalesce
from django.utils import timezone


BETA2 = 328.33**2
RATING_INIT = 1200 # Newcomer's rating when applying the rating floor/ceiling
MEAN_INIT = 1400.0
Expand Down Expand Up @@ -147,7 +146,7 @@ def divconq(i, j):
def rate_contest(contest):
from judge.models import Rating, Profile
from judge.models.profile import _get_basic_info
from judge.utils.users import get_contest_ratings
from judge.utils.users import get_contest_ratings, get_rating_rank

rating_subquery = Rating.objects.filter(user=OuterRef("user"))
rating_sorted = rating_subquery.order_by("-contest__end_time")
Expand Down Expand Up @@ -241,6 +240,7 @@ def rate_contest(contest):

_get_basic_info.dirty_multi([(uid,) for uid in user_ids])
get_contest_ratings.dirty_multi([(uid,) for uid in user_ids])
get_rating_rank.dirty_multi([(uid,) for uid in user_ids])


RATING_LEVELS = [
Expand Down
2 changes: 2 additions & 0 deletions judge/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def problem_update(sender, instance, **kwargs):

@receiver(post_save, sender=Profile)
def profile_update(sender, instance, **kwargs):
judge.utils.users.get_points_rank.dirty(instance.id)
judge.utils.users.get_rating_rank.dirty(instance.id)
if hasattr(instance, "_updating_stats_only"):
return

Expand Down
6 changes: 6 additions & 0 deletions judge/utils/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
from judge.models import Profile, Rating, Submission, Friend, ProfileInfo


@cache_wrapper(prefix="grr")
def get_rating_rank(profile):
if profile.is_unlisted:
return None
rank = None
if profile.rating:
rank = (
Expand All @@ -19,7 +22,10 @@ def get_rating_rank(profile):
return rank


@cache_wrapper(prefix="gpr")
def get_points_rank(profile):
if profile.is_unlisted:
return None
return (
Profile.objects.filter(
is_unlisted=False,
Expand Down
12 changes: 5 additions & 7 deletions templates/profile-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ <h4>{{ link_user(request.profile) }}</h4>
{{ request.profile.performance_points|floatformat(0) }}
</span></div>
</div>
{% if not request.profile.is_unlisted %}
<div class="user-info">
<div title="{{_('Rank by rating')}}"><i class="fa fa-globe peru" ></i> {{_('Rating')}} #</div>
<div class="user-info-body">{{rating_rank if rating_rank else '-'}}</div>
</div>
{% endif %}
<div class="user-info">
<div title="{{_('Rank by rating')}}"><i class="fa fa-globe peru" ></i> {{_('Rating')}} #</div>
<div class="user-info-body">{{rating_rank if rating_rank else '-'}}</div>
</div>
<div class="user-info">
<div title="{{_('Rank by points')}}"><i class="fa fa-globe blue" ></i> {{_('Points')}} #</div>
<div class="user-info-body">{{points_rank}}</div>
<div class="user-info-body">{{points_rank if points_rank else '-'}}</div>
</div>

{% if awards.medals %}
Expand Down
14 changes: 6 additions & 8 deletions templates/user/user-about.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@
</span></div>
</div>
</div>
{% if not user.is_unlisted %}
<div class="user-info-card">
<div class="user-info">
<div class="user-info-header" title="{{_('Rank by rating')}}"><i class="fa fa-globe peru" ></i> {{_('Rating')}} #</div>
<div class="user-info-body">{{rating_rank if rating_rank else '-'}}</div>
</div>
<div class="user-info-card">
<div class="user-info">
<div class="user-info-header" title="{{_('Rank by rating')}}"><i class="fa fa-globe peru" ></i> {{_('Rating')}} #</div>
<div class="user-info-body">{{rating_rank if rating_rank else '-'}}</div>
</div>
{% endif %}
</div>
<div class="user-info-card">
<div class="user-info">
<div class="user-info-header" title="{{_('Rank by points')}}"><i class="fa fa-globe blue" ></i> {{_('Points')}} #</div>
<div class="user-info-body">{{points_rank}}</div>
<div class="user-info-body">{{points_rank if points_rank else '-'}}</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 46c950d

Please sign in to comment.