-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only count the best replay by each user for ranking.
- Loading branch information
Showing
3 changed files
with
213 additions
and
15 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
project/thscoreboard/replays/migrations/0042_unique_rank_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Generated by Django 4.2.4 on 2024-11-29 19:44 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
"""Change rank view to only include the best replay for each player.""" | ||
dependencies = [ | ||
("replays", "0041_replay_rank_view"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL( | ||
sql=""" | ||
CREATE OR REPLACE VIEW replays_rank | ||
AS | ||
SELECT | ||
row_number() over () as id, | ||
replay, | ||
score, | ||
shot_id, | ||
difficulty, | ||
route_id, | ||
category, | ||
place | ||
FROM | ||
( | ||
SELECT | ||
replay, | ||
score, | ||
shot_id, | ||
difficulty, | ||
route_id, | ||
category, | ||
created, | ||
rank() OVER ( | ||
PARTITION BY shot_id, | ||
difficulty, | ||
route_id, | ||
category | ||
ORDER BY | ||
score DESC, | ||
created, | ||
replay | ||
) as place | ||
FROM | ||
( | ||
SELECT | ||
replay, | ||
score, | ||
shot_id, | ||
difficulty, | ||
route_id, | ||
category, | ||
created, | ||
user_id | ||
FROM | ||
( | ||
SELECT | ||
id as replay, | ||
score, | ||
shot_id, | ||
difficulty, | ||
route_id, | ||
category, | ||
created, | ||
user_id, | ||
rank() OVER ( | ||
PARTITION BY shot_id, | ||
difficulty, | ||
route_id, | ||
category, | ||
user_id | ||
ORDER BY | ||
score DESC, | ||
created, | ||
id | ||
) as per_user_place | ||
FROM | ||
replays_replay | ||
WHERE | ||
replay_type = 1 -- FULL_GAME | ||
AND category = 1 -- STANDARD | ||
) AS replays_ranked_per_user | ||
WHERE | ||
per_user_place = 1 | ||
) AS top_replays_per_user | ||
) AS top_replays | ||
WHERE | ||
place <= 3 | ||
ORDER BY | ||
shot_id, | ||
difficulty, | ||
route_id, | ||
category, | ||
place DESC; | ||
""", | ||
# old: | ||
# """ | ||
# CREATE OR REPLACE VIEW replays_rank | ||
# AS | ||
# SELECT row_number() over () as id, replay, score, shot_id, difficulty, route_id, category, place | ||
# FROM ( | ||
# SELECT id as replay, score, shot_id, difficulty, route_id, category, rank() OVER (PARTITION BY shot_id, difficulty, route_id, category ORDER BY score DESC, created, id) as place | ||
# FROM replays_replay | ||
# WHERE replay_type = 1 -- FULL_GAME | ||
# AND category = 1 -- STANDARD | ||
# ) AS ranked | ||
# WHERE place <= 3 | ||
# ORDER BY shot_id, difficulty, route_id, category, place desc | ||
# ; | ||
# """, | ||
reverse_sql=""" | ||
CREATE OR REPLACE VIEW replays_rank | ||
AS | ||
SELECT row_number() over () as id, replay, score, shot_id, difficulty, route_id, category, place | ||
FROM ( | ||
SELECT id as replay, score, shot_id, difficulty, route_id, category, rank() OVER (PARTITION BY shot_id, difficulty, route_id, category ORDER BY score DESC, created, id) as place | ||
FROM replays_replay | ||
WHERE replay_type = 1 -- FULL_GAME | ||
AND category = 1 -- STANDARD | ||
) AS ranked | ||
WHERE place <= 3 | ||
ORDER BY shot_id, difficulty, route_id, category, place desc | ||
; | ||
""", | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters