From abf4d0a596adc6ebc18e4190da50fce9416d2ccb Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 19 Nov 2023 12:59:07 +0200 Subject: [PATCH] Add skipping plus tier admission from leaderboard --- app/db/tables.ts | 1 + app/features/admin/routes/admin.test.ts | 39 ++++++++++++++++++ .../leaderboards/core/leaderboards.server.ts | 7 ++++ .../queries/userSPLeaderboard.server.ts | 2 + db-test.sqlite3 | Bin 741376 -> 741376 bytes migrations/042-plus-skipped.js | 5 +++ package.json | 1 + scripts/skip-plus.ts | 23 +++++++++++ 8 files changed, 78 insertions(+) create mode 100644 migrations/042-plus-skipped.js create mode 100644 scripts/skip-plus.ts diff --git a/app/db/tables.ts b/app/db/tables.ts index eeb5d6588..af6396c72 100644 --- a/app/db/tables.ts +++ b/app/db/tables.ts @@ -496,6 +496,7 @@ export interface User { twitter: string | null; vc: Generated; youtubeId: string | null; + plusSkippedForSeasonNth: number | null; } export interface UserResultHighlight { diff --git a/app/features/admin/routes/admin.test.ts b/app/features/admin/routes/admin.test.ts index a14e11f16..a4d148bd1 100644 --- a/app/features/admin/routes/admin.test.ts +++ b/app/features/admin/routes/admin.test.ts @@ -140,6 +140,45 @@ PlusVoting( }, ); +PlusVoting( + "skips users from leaderboard with the skip flag for the season", + async () => { + MockDate.set(new Date("2023-11-29T00:00:00.000Z")); + + await Test.database.insertUsers(11); + await createLeaderboard(Array.from({ length: 11 }).map((_, i) => i + 1)); + + await db + .updateTable("User") + .set({ plusSkippedForSeasonNth: 1 }) + .where("User.id", "=", 1) + .execute(); + + await adminAction({ _action: "REFRESH" }, { user: "admin" }); + + assert.equal(await countPlusTierMembers(1), 10); + assert.equal(await countPlusTierMembers(2), 0); + }, +); + +PlusVoting("plus server skip flag ignored if for past season", async () => { + MockDate.set(new Date("2023-11-29T00:00:00.000Z")); + + await Test.database.insertUsers(11); + await createLeaderboard(Array.from({ length: 11 }).map((_, i) => i + 1)); + + await db + .updateTable("User") + .set({ plusSkippedForSeasonNth: 0 }) + .where("User.id", "=", 1) + .execute(); + + await adminAction({ _action: "REFRESH" }, { user: "admin" }); + + assert.equal(await countPlusTierMembers(1), 10); + assert.equal(await countPlusTierMembers(2), 1); +}); + PlusVoting("ignores leaderboard while season is ongoing", async () => { MockDate.set(new Date("2024-02-15T00:00:00.000Z")); diff --git a/app/features/leaderboards/core/leaderboards.server.ts b/app/features/leaderboards/core/leaderboards.server.ts index fbfc8bd11..f05b491d7 100644 --- a/app/features/leaderboards/core/leaderboards.server.ts +++ b/app/features/leaderboards/core/leaderboards.server.ts @@ -4,6 +4,7 @@ import type { SeasonPopularUsersWeapon } from "../queries/seasonPopularUsersWeap import type { MainWeaponId } from "~/modules/in-game-lists"; import { weaponCategories } from "~/modules/in-game-lists"; import { seasonHasTopTen } from "../leaderboards-utils"; +import { currentOrPreviousSeason } from "~/features/mmr/season"; export function addTiers(entries: UserSPLeaderboardItem[], season: number) { const tiers = freshUserSkills(season); @@ -53,6 +54,12 @@ export function addPendingPlusTiers( if (!highestPlusTierWithSpace) break; if (entry.plusTier && entry.plusTier <= highestPlusTierWithSpace) continue; + if ( + entry.plusSkippedForSeasonNth === currentOrPreviousSeason(new Date())?.nth + ) { + entry.plusSkippedForSeasonNth = null; + continue; + } entry.pendingPlusTier = highestPlusTierWithSpace; const key = `+${highestPlusTierWithSpace}` as const; diff --git a/app/features/leaderboards/queries/userSPLeaderboard.server.ts b/app/features/leaderboards/queries/userSPLeaderboard.server.ts index 828a3c686..d89cdf783 100644 --- a/app/features/leaderboards/queries/userSPLeaderboard.server.ts +++ b/app/features/leaderboards/queries/userSPLeaderboard.server.ts @@ -15,6 +15,7 @@ const stm = sql.prepare(/* sql */ ` "User"."discordAvatar", "User"."discordId", "User"."customUrl", + "User"."plusSkippedForSeasonNth", "PlusTier"."tier" as "plusTier", rank () over ( order by "Skill"."Ordinal" desc @@ -48,6 +49,7 @@ export interface UserSPLeaderboardItem { discordId: User["discordId"]; customUrl: User["customUrl"]; plusTier?: PlusTier["tier"]; + plusSkippedForSeasonNth: number | null; /** Plus tier player is on track to join */ pendingPlusTier?: PlusTier["tier"]; placementRank: number; diff --git a/db-test.sqlite3 b/db-test.sqlite3 index e10026d0e6c9c63024cb6b841cf6df3edbd66c56..9948065cec98abc8f5ab5117889959161911a1af 100644 GIT binary patch delta 209 zcmZozpxdxOcY?H_0s{lXRv?CfcN2At85K4rEa7L?<~TT+T_BW+?976K)D*p}Vj}}1V_ic-T|-L+Ljx;gV=Ggm&2J?nud^Lu;Ll(< zG@0kaHm){3CU$XAQN|wo&F??_WKz~qPy(3}3^BwlzbH60u{b}^uOvfBAv3QeH9fVc m`Nik<7oQn{m