Skip to content
Open
12 changes: 12 additions & 0 deletions migrations/20250323004031_list_scoreless_players.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE OR REPLACE VIEW ranked_players AS
SELECT
ROW_NUMBER() OVER(ORDER BY players.score DESC, id) AS index,
RANK() OVER(ORDER BY players.score DESC) AS rank,
id, name, players.score, subdivision,
nationalities.iso_country_code,
nationalities.nation,
nationalities.continent
FROM players
LEFT OUTER JOIN nationalities
ON players.nationality = nationalities.iso_country_code
WHERE NOT players.banned AND players.score > 0.0;
25 changes: 25 additions & 0 deletions migrations/20250323004031_list_scoreless_players.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE OR REPLACE VIEW ranked_players AS
SELECT
ROW_NUMBER() OVER(ORDER BY players.score DESC, id) AS index,
(CASE WHEN players.score = 0.0 THEN NULL
ELSE RANK() OVER(ORDER BY players.score DESC)
END) AS rank,
id, name, players.score, subdivision,
nationalities.iso_country_code,
nationalities.nation,
nationalities.continent
FROM players
LEFT OUTER JOIN nationalities
ON players.nationality = nationalities.iso_country_code
WHERE NOT players.banned
AND (
EXISTS ( -- check if player has at least one approved record
SELECT 1 FROM records
WHERE records.player = players.id
AND records.status_ = 'APPROVED'
)
OR EXISTS ( -- check if player has verified at least one demon
SELECT 1 FROM demons
WHERE demons.verifier = players.id
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class StatsViewer extends FilteredPaginator {
super.onReceive(response);

// Using currentlySelected is O.K. here, as selection via clicking li-elements is the only possibility (well, not for the nation based one, but oh well)!
this._rank.innerText = this.currentlySelected.dataset.rank;
this._rank.innerText = this.currentlySelected.dataset.rank ?? "None";
this._score.innerHTML =
this.currentlySelected.getElementsByTagName("i")[0].innerHTML;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class IndividualStatsViewer extends StatsViewer {
rankingEndpoint: "/api/v1/players/ranking/",
entryGenerator: generateStatsViewerPlayer,
});
this.updateQueryData("scoreless", true);
}

onReceive(response) {
Expand Down Expand Up @@ -198,9 +199,12 @@ function generateStatsViewerPlayer(player) {

li.className = "white hover";
li.dataset.id = player.id;
li.dataset.rank = player.rank;

if (player.rank) {
li.dataset.rank = player.rank;
b.appendChild(document.createTextNode("#" + player.rank + " "));
}

b.appendChild(document.createTextNode("#" + player.rank + " "));
i.appendChild(document.createTextNode(player.score.toFixed(2)));

if (player.nationality) {
Expand Down
3 changes: 2 additions & 1 deletion pointercrate-demonlist/sql/paginate_player_ranking.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ WHERE (index < $1 OR $1 IS NULL)
AND (nation = $4 OR iso_country_code = $4 OR (nation IS NULL AND $5) OR ($4 IS NULL AND NOT $5))
AND (continent = CAST($6::TEXT AS continent) OR $6 IS NULL)
AND (subdivision = $7 OR $7 IS NULL)
AND (score > 0.0 OR $8 = TRUE)
ORDER BY rank {}, id
LIMIT $8
LIMIT $9
6 changes: 5 additions & 1 deletion pointercrate-demonlist/src/player/paginate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@

#[serde(default, deserialize_with = "non_nullable")]
name_contains: Option<String>,

#[serde(default, deserialize_with = "non_nullable")]
scoreless: Option<bool>,
}

impl PaginationQuery for RankingPagination {
Expand All @@ -145,7 +148,7 @@

#[derive(Debug, Serialize)]
pub struct RankedPlayer {
rank: i64,
rank: Option<i64>,
#[serde(skip)]
index: i64,
#[serde(flatten)]
Expand Down Expand Up @@ -174,6 +177,7 @@
.bind(query.nation == Some(None))
.bind(query.continent.as_ref().map(|c| c.to_sql()))
.bind(&query.subdivision)
.bind(query.scoreless)

Check warning on line 180 in pointercrate-demonlist/src/player/paginate.rs

View check run for this annotation

Codecov / codecov/patch

pointercrate-demonlist/src/player/paginate.rs#L180

Added line #L180 was not covered by tests
.bind(query.params.limit + 1)
.fetch(connection);

Expand Down
Loading