fix(clock): colliding points annotation with CustomUser.points field
This commit is contained in:
@@ -54,8 +54,8 @@ def current_state(request: HttpRequest, event_path: str):
|
|||||||
def my_stats(request: HttpRequest, event_path: str):
|
def my_stats(request: HttpRequest, event_path: str):
|
||||||
ranked = list(
|
ranked = list(
|
||||||
ranked_players(request.event)
|
ranked_players(request.event)
|
||||||
.values("id", "points", "rank")
|
.values("id", "clock_points", "rank")
|
||||||
.order_by("-points", "id")
|
.order_by("-clock_points", "id")
|
||||||
)
|
)
|
||||||
total_players = len(ranked)
|
total_players = len(ranked)
|
||||||
my_index = next(
|
my_index = next(
|
||||||
@@ -71,9 +71,9 @@ def my_stats(request: HttpRequest, event_path: str):
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"points": mine["points"] if mine else 0.0,
|
"points": mine["clock_points"] if mine else 0.0,
|
||||||
"rank": mine["rank"] if mine else total_players,
|
"rank": mine["rank"] if mine else total_players,
|
||||||
"total_players": total_players,
|
"total_players": total_players,
|
||||||
"points_above": above["points"] if above else None,
|
"points_above": above["clock_points"] if above else None,
|
||||||
"points_below": below["points"] if below else None,
|
"points_below": below["clock_points"] if below else None,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ def _press_points_expression():
|
|||||||
|
|
||||||
|
|
||||||
def ranked_players(event: Event):
|
def ranked_players(event: Event):
|
||||||
"""All users annotated with their live total points for this event and
|
"""All users annotated with their live total `clock_points` (not `points`,
|
||||||
|
that one is the market balance field on CustomUser) for this event and
|
||||||
DB-computed RANK(). Points only ever come from presses made in `event` -
|
DB-computed RANK(). Points only ever come from presses made in `event` -
|
||||||
a player's history in another event never leaks into this leaderboard."""
|
a player's history in another event never leaks into this leaderboard."""
|
||||||
from accounts.models import CustomUser
|
from accounts.models import CustomUser
|
||||||
@@ -32,6 +33,6 @@ def ranked_players(event: Event):
|
|||||||
Value(0.0),
|
Value(0.0),
|
||||||
output_field=FloatField(),
|
output_field=FloatField(),
|
||||||
)
|
)
|
||||||
return CustomUser.objects.annotate(points=points).annotate(
|
return CustomUser.objects.annotate(clock_points=points).annotate(
|
||||||
rank=Window(expression=Rank(), order_by=F("points").desc())
|
rank=Window(expression=Rank(), order_by=F("clock_points").desc())
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user