Edit displaying rating and points rank for unlisted (#115)

* Edit displaying rating and points rank for unlisted

* Edit rating/points rank of unlisted users and cache get_rank functions
This commit is contained in:
Phuoc Anh Kha Le 2024-06-04 19:40:20 -05:00 committed by GitHub
parent 570c3071ee
commit 46c950dc37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 25 additions and 19 deletions

View file

@ -79,8 +79,10 @@ def cache_wrapper(prefix, timeout=None, expected_type=None):
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):

View file

@ -7,7 +7,6 @@ from django.db.models import Count, OuterRef, Subquery
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
@ -147,7 +146,7 @@ def recalculate_ratings(ranking, old_mean, times_ranked, historical_p):
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")
@ -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 = [

View file

@ -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

View file

@ -6,7 +6,10 @@ from judge.caching import cache_wrapper
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 = (
@ -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,

View file

@ -33,15 +33,13 @@
{{ 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 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 %}

View file

@ -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>
{% endif %}
<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>