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:
parent
570c3071ee
commit
46c950dc37
6 changed files with 25 additions and 19 deletions
|
@ -79,8 +79,10 @@ def cache_wrapper(prefix, timeout=None, expected_type=None):
|
||||||
return result
|
return result
|
||||||
result = func(*args, **kwargs)
|
result = func(*args, **kwargs)
|
||||||
if result is None:
|
if result is None:
|
||||||
result = NONE_RESULT
|
cache_result = NONE_RESULT
|
||||||
_set(cache_key, result, timeout)
|
else:
|
||||||
|
cache_result = result
|
||||||
|
_set(cache_key, cache_result, timeout)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def dirty(*args, **kwargs):
|
def dirty(*args, **kwargs):
|
||||||
|
|
|
@ -7,7 +7,6 @@ from django.db.models import Count, OuterRef, Subquery
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
|
||||||
BETA2 = 328.33**2
|
BETA2 = 328.33**2
|
||||||
RATING_INIT = 1200 # Newcomer's rating when applying the rating floor/ceiling
|
RATING_INIT = 1200 # Newcomer's rating when applying the rating floor/ceiling
|
||||||
MEAN_INIT = 1400.0
|
MEAN_INIT = 1400.0
|
||||||
|
@ -147,7 +146,7 @@ def recalculate_ratings(ranking, old_mean, times_ranked, historical_p):
|
||||||
def rate_contest(contest):
|
def rate_contest(contest):
|
||||||
from judge.models import Rating, Profile
|
from judge.models import Rating, Profile
|
||||||
from judge.models.profile import _get_basic_info
|
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_subquery = Rating.objects.filter(user=OuterRef("user"))
|
||||||
rating_sorted = rating_subquery.order_by("-contest__end_time")
|
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_basic_info.dirty_multi([(uid,) for uid in user_ids])
|
||||||
get_contest_ratings.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 = [
|
RATING_LEVELS = [
|
||||||
|
|
|
@ -72,6 +72,8 @@ def problem_update(sender, instance, **kwargs):
|
||||||
|
|
||||||
@receiver(post_save, sender=Profile)
|
@receiver(post_save, sender=Profile)
|
||||||
def profile_update(sender, instance, **kwargs):
|
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"):
|
if hasattr(instance, "_updating_stats_only"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,10 @@ from judge.caching import cache_wrapper
|
||||||
from judge.models import Profile, Rating, Submission, Friend, ProfileInfo
|
from judge.models import Profile, Rating, Submission, Friend, ProfileInfo
|
||||||
|
|
||||||
|
|
||||||
|
@cache_wrapper(prefix="grr")
|
||||||
def get_rating_rank(profile):
|
def get_rating_rank(profile):
|
||||||
|
if profile.is_unlisted:
|
||||||
|
return None
|
||||||
rank = None
|
rank = None
|
||||||
if profile.rating:
|
if profile.rating:
|
||||||
rank = (
|
rank = (
|
||||||
|
@ -19,7 +22,10 @@ def get_rating_rank(profile):
|
||||||
return rank
|
return rank
|
||||||
|
|
||||||
|
|
||||||
|
@cache_wrapper(prefix="gpr")
|
||||||
def get_points_rank(profile):
|
def get_points_rank(profile):
|
||||||
|
if profile.is_unlisted:
|
||||||
|
return None
|
||||||
return (
|
return (
|
||||||
Profile.objects.filter(
|
Profile.objects.filter(
|
||||||
is_unlisted=False,
|
is_unlisted=False,
|
||||||
|
|
|
@ -33,15 +33,13 @@
|
||||||
{{ request.profile.performance_points|floatformat(0) }}
|
{{ request.profile.performance_points|floatformat(0) }}
|
||||||
</span></div>
|
</span></div>
|
||||||
</div>
|
</div>
|
||||||
{% if not request.profile.is_unlisted %}
|
<div class="user-info">
|
||||||
<div class="user-info">
|
<div title="{{_('Rank by rating')}}"><i class="fa fa-globe peru" ></i> {{_('Rating')}} #</div>
|
||||||
<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 class="user-info-body">{{rating_rank if rating_rank else '-'}}</div>
|
</div>
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
<div class="user-info">
|
<div class="user-info">
|
||||||
<div title="{{_('Rank by points')}}"><i class="fa fa-globe blue" ></i> {{_('Points')}} #</div>
|
<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>
|
</div>
|
||||||
|
|
||||||
{% if awards.medals %}
|
{% if awards.medals %}
|
||||||
|
|
|
@ -39,18 +39,16 @@
|
||||||
</span></div>
|
</span></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% if not user.is_unlisted %}
|
<div class="user-info-card">
|
||||||
<div class="user-info-card">
|
<div class="user-info">
|
||||||
<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-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 class="user-info-body">{{rating_rank if rating_rank else '-'}}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
</div>
|
||||||
<div class="user-info-card">
|
<div class="user-info-card">
|
||||||
<div class="user-info">
|
<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-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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue