mirror of
https://github.com/zkldi/Tachi.git
synced 2026-09-22 23:18:05 +03:00
Set a default of 0 when a rating value is null when calculating rank (#1675)
* Set a default of 0 when a rating value is null when calculating rank * make null values be last place * adjust test for new null rating case
This commit is contained in:
@@ -131,15 +131,17 @@ describe("GetUsersRankingAndOutOf", () => {
|
||||
expect(result).toEqual({ ranking: 1, outOf: 2 });
|
||||
});
|
||||
|
||||
it("returns ranking 1 when user rating is null (no one can be strictly greater than null)", async () => {
|
||||
it("returns worst ranking when user rating is null", async () => {
|
||||
const user1 = await seedUser({ username: "null_rater" });
|
||||
const user2 = await seedUser({ username: "other_player" });
|
||||
const user3 = await seedUser({ username: "other_better_player" });
|
||||
await seedGameStats(user1.id, null);
|
||||
await seedGameStats(user2.id, 10);
|
||||
await seedGameStats(user2.id, 0);
|
||||
await seedGameStats(user3.id, 10);
|
||||
|
||||
const result = await GetUsersRankingAndOutOf(makeStats(user1.id, null));
|
||||
|
||||
expect(result).toEqual({ ranking: 1, outOf: 2 });
|
||||
expect(result).toEqual({ ranking: 3, outOf: 3 });
|
||||
});
|
||||
|
||||
it("does not include rows from different games in the count", async () => {
|
||||
|
||||
@@ -199,9 +199,13 @@ export async function GetUsersRankingAndOutOf(
|
||||
const result = await DB.selectFrom("game_profile")
|
||||
.select([
|
||||
(eb) => eb.fn.countAll().as("out_of"),
|
||||
sql<number>`COUNT(*) FILTER (WHERE (ratings->>${ratingAlg})::numeric > ${userRating})`.as(
|
||||
"ranking_count",
|
||||
),
|
||||
sql<number>`COUNT(*) FILTER (
|
||||
WHERE user_id != ${stats.userID} -- itll include self when null, doesnt affect normal ranking
|
||||
AND (
|
||||
(ratings->>${ratingAlg})::numeric > ${userRating}::numeric
|
||||
OR ${userRating}::numeric IS NULL
|
||||
)
|
||||
)`.as("ranking_count"),
|
||||
])
|
||||
.where("game", "=", stats.game)
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
Reference in New Issue
Block a user