From d9800a4759115850bcdef43217e8fce47de09976 Mon Sep 17 00:00:00 2001 From: anhkha2003 Date: Tue, 4 Jun 2024 16:23:16 -0500 Subject: [PATCH 1/2] Edit displaying rating and points rank for unlisted --- templates/profile-table.html | 12 +++++------- templates/user/user-about.html | 14 ++++++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/templates/profile-table.html b/templates/profile-table.html index de1ad330..2c733f46 100644 --- a/templates/profile-table.html +++ b/templates/profile-table.html @@ -33,15 +33,13 @@

{{ link_user(request.profile) }}

{{ request.profile.performance_points|floatformat(0) }} - {% if not request.profile.is_unlisted %} -
-
{{_('Rating')}} #
- -
- {% endif %} +
+
{{_('Rating')}} #
+ +
{{_('Points')}} #
- +
{% if awards.medals %} diff --git a/templates/user/user-about.html b/templates/user/user-about.html index 69ff3bbc..0f2aa45b 100644 --- a/templates/user/user-about.html +++ b/templates/user/user-about.html @@ -39,18 +39,16 @@ - {% if not user.is_unlisted %} -
- +
From 080361081120e4cbfa5b72910fe6ebbc7ad01d41 Mon Sep 17 00:00:00 2001 From: anhkha2003 Date: Tue, 4 Jun 2024 19:38:48 -0500 Subject: [PATCH 2/2] Edit rating/points rank of unlisted users and cache get_rank functions --- judge/caching.py | 6 ++++-- judge/ratings.py | 4 ++-- judge/signals.py | 2 ++ judge/utils/users.py | 6 ++++++ templates/profile-table.html | 4 ++-- templates/user/user-about.html | 4 ++-- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/judge/caching.py b/judge/caching.py index d86cc308..f40adb15 100644 --- a/judge/caching.py +++ b/judge/caching.py @@ -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): diff --git a/judge/ratings.py b/judge/ratings.py index bfcb828d..854bdcbd 100644 --- a/judge/ratings.py +++ b/judge/ratings.py @@ -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 @@ -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") @@ -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 = [ diff --git a/judge/signals.py b/judge/signals.py index 614a21bd..c3029bb9 100644 --- a/judge/signals.py +++ b/judge/signals.py @@ -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 diff --git a/judge/utils/users.py b/judge/utils/users.py index b9eb0b61..9ac071ca 100644 --- a/judge/utils/users.py +++ b/judge/utils/users.py @@ -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 = ( @@ -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, diff --git a/templates/profile-table.html b/templates/profile-table.html index 2c733f46..17a05ad0 100644 --- a/templates/profile-table.html +++ b/templates/profile-table.html @@ -35,11 +35,11 @@

{{ link_user(request.profile) }}

{% if awards.medals %} diff --git a/templates/user/user-about.html b/templates/user/user-about.html index 0f2aa45b..811e8c64 100644 --- a/templates/user/user-about.html +++ b/templates/user/user-about.html @@ -42,13 +42,13 @@