Skip to content

Commit

Permalink
Merge pull request #60 from Syriiin/use-new-membershipscore-pp
Browse files Browse the repository at this point in the history
Use MembershipScore.performance_total for sorting
  • Loading branch information
Syriiin authored Jun 2, 2024
2 parents 5916bed + 09f5851 commit 0f6cb79
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions leaderboards/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from django.db.models import Max, Q

from common.osu.enums import Gamemode
from common.osu.utils import calculate_pp_total
from leaderboards.enums import LeaderboardAccessType
from profiles.enums import ScoreResult, ScoreSet
from profiles.models import OsuUser, Score, ScoreFilter


Expand Down Expand Up @@ -81,21 +79,18 @@ class Leaderboard(models.Model):
)()

def get_pp_record(self) -> typing.Union[Score, None]:
scores = Score.objects.non_restricted().filter(
membership__leaderboard_id=self.id
)

scores = scores.annotate_sorting_pp(self.score_set)
scores = self.get_top_scores()

return scores.aggregate(Max("sorting_pp"))["sorting_pp__max"]
return scores.aggregate(Max("membership_scores__performance_total"))[
"membership_scores__performance_total__max"
]

def get_top_scores(self, limit=5):
scores = (
Score.objects.non_restricted()
.distinct()
.filter(membership__leaderboard_id=self.id)
.order_by("-membership_scores__performance_total", "date")
.select_related("user_stats", "user_stats__user", "beatmap")
.get_score_set(score_set=self.score_set)
)

return scores[:limit]
Expand Down

0 comments on commit 0f6cb79

Please sign in to comment.