diff --git a/server/scripts/__KT_DATABASE_MIGRATION/state-sync/recalc-all-scores.ts b/server/scripts/__KT_DATABASE_MIGRATION/state-sync/recalc-all-scores.ts index 458eb3fa9..c08edefa6 100644 --- a/server/scripts/__KT_DATABASE_MIGRATION/state-sync/recalc-all-scores.ts +++ b/server/scripts/__KT_DATABASE_MIGRATION/state-sync/recalc-all-scores.ts @@ -1,7 +1,10 @@ import db from "external/mongo/db"; import CreateLogCtx from "lib/logger/logger"; import { CreateCalculatedData } from "lib/score-import/framework/calculated-data/calculated-data"; +import { ProcessPBs } from "lib/score-import/framework/pb/process-pbs"; +import { updateLanguageServiceSourceFile } from "typescript"; import { EfficientDBIterate } from "../../util/efficient-db-iterate"; +import { UpdateAllPBs } from "./update-all-pbs"; const logger = CreateLogCtx(__filename); @@ -43,6 +46,9 @@ export async function RecalcAllScores(filter = {}) { filter ); + logger.info("Reprocessing PBs..."); + await UpdateAllPBs(filter); + logger.info(`Done!`); } diff --git a/server/scripts/bpi-poyashi-data/update-bpi-poyashi.ts b/server/scripts/bpi-poyashi-data/update-bpi-poyashi.ts index e32026dbf..637349a16 100644 --- a/server/scripts/bpi-poyashi-data/update-bpi-poyashi.ts +++ b/server/scripts/bpi-poyashi-data/update-bpi-poyashi.ts @@ -9,6 +9,7 @@ import CreateLogCtx from "lib/logger/logger"; import { config } from "process"; import { FindChartWithPTDFVersion } from "utils/queries/charts"; import { FindSongOnTitle } from "utils/queries/songs"; +import { RecalcAllScores } from "../__KT_DATABASE_MIGRATION/state-sync/recalc-all-scores"; const program = new Command(); @@ -35,9 +36,7 @@ async function UpdatePoyashiData() { if (options.fetch) { // lol! logger.info("Fetching data from github..."); - const rj = await fetch( - "https://raw.githubusercontent.com/potakusan/bpim-score-repo/master/output/release.json" - ).then((r) => r.json()); + const rj = await fetch("https://proxy.poyashi.me/?type=bpi").then((r) => r.json()); logger.info("Fetched data."); fs.writeFileSync(dataLoc, JSON.stringify(rj)); @@ -71,7 +70,7 @@ async function UpdatePoyashiData() { tachiSong.id, playtype as "SP" | "DP", diff as Difficulties["iidx:DP" | "iidx:SP"], - "28" + "27" )) as ChartDocument<"iidx:SP" | "iidx:DP">; if (!tachiChart) { @@ -90,6 +89,11 @@ async function UpdatePoyashiData() { continue; } + if (d.removed) { + logger.info(`Skipping removed chart ${tachiSong.title}.`); + continue; + } + realData.push({ coef: d.coef === -1 ? null : d.coef, kavg: Number(d.avg), @@ -102,6 +106,14 @@ async function UpdatePoyashiData() { await db["iidx-bpi-data"].insert(realData); logger.info(`Removed all, and inserted ${realData.length} documents.`); + + logger.info(`Triggering IIDX Recalc.`); + + await RecalcAllScores({ game: "iidx" }); + + logger.info(`Done.`); } -UpdatePoyashiData(); +if (require.main === module) { + UpdatePoyashiData(); +} diff --git a/server/src/lib/score-import/framework/calculated-data/stats.test.ts b/server/src/lib/score-import/framework/calculated-data/stats.test.ts index dc0e91a7d..f9ea8fa7b 100644 --- a/server/src/lib/score-import/framework/calculated-data/stats.test.ts +++ b/server/src/lib/score-import/framework/calculated-data/stats.test.ts @@ -53,6 +53,21 @@ t.test("#CalculateBPI", (t) => { t.end(); }); + t.test("COLOSSEUM BPI Tests", (t) => { + const WR_AFT = 2312; + const KAVG_CL = 2131; + const MAX_CL = 2318; + const COEF_CL = -1; + + function CL_BPI(yourEx: number) { + return CalculateBPI(KAVG_CL, WR_AFT, yourEx, MAX_CL, COEF_CL); + } + + isApproximately(CL_BPI(2307), 79.63); + + t.end(); + }); + // This song has both no co-efficient and is an sp11, so it serves // as another interesting test. t.test("Afterimage d'automne BPI tests", (t) => { diff --git a/server/src/lib/score-import/framework/calculated-data/stats.ts b/server/src/lib/score-import/framework/calculated-data/stats.ts index d4ff4b224..19a24527a 100644 --- a/server/src/lib/score-import/framework/calculated-data/stats.ts +++ b/server/src/lib/score-import/framework/calculated-data/stats.ts @@ -6,7 +6,6 @@ import { Game, Playtypes, GetGamePTConfig, - IDStrings, } from "tachi-common"; import { KtLogger } from "lib/logger/logger"; import { DryScore } from "../common/types"; @@ -78,7 +77,11 @@ export function CalculateBPI( max: integer, pc: number | null ) { - const powCoef = pc ?? 1.175; + let powCoef = pc ?? 1.175; + if (powCoef === -1) { + powCoef = 1.175; + } + const yourPGF = BPIPikaGreatFn(yourEx, max); const kaidenPGF = BPIPikaGreatFn(kaidenEx, max); const wrPGF = BPIPikaGreatFn(wrEx, max); @@ -90,8 +93,7 @@ export function CalculateBPI( const isBetterThanKavg = yourEx >= kaidenEx; // this line of code isn't mine, and that's why it's *really* bad here. - return Math.max( - -15, + const bpi = Math.round( (isBetterThanKavg ? 100 : -100) * Math.pow( @@ -99,8 +101,13 @@ export function CalculateBPI( powCoef ) * 100 - ) / 100 - ); + ) / 100; + + if (bpi < -15) { + return -15; + } + + return bpi; } /** diff --git a/server/src/server/router/api/v1/users/_userID/banner/router.test.ts b/server/src/server/router/api/v1/users/_userID/banner/router.test.ts index 3044b8e1e..3c81eb69b 100644 --- a/server/src/server/router/api/v1/users/_userID/banner/router.test.ts +++ b/server/src/server/router/api/v1/users/_userID/banner/router.test.ts @@ -11,7 +11,7 @@ t.test("GET /api/v1/users/:userID/banner", (t) => { t.beforeEach(ResetDBState); t.test("Should return the default profile banner if user has no custom banner", async (t) => { - await CDNStoreOrOverwrite("/users/default/banner.png", "test"); + await CDNStoreOrOverwrite("/users/default/banner", "test"); const res = await mockApi.get("/api/v1/users/1/banner").redirects(1); t.equal(res.body.toString(), "test"); diff --git a/server/src/server/router/api/v1/users/_userID/banner/router.ts b/server/src/server/router/api/v1/users/_userID/banner/router.ts index 11f5f87d1..1cf0587db 100644 --- a/server/src/server/router/api/v1/users/_userID/banner/router.ts +++ b/server/src/server/router/api/v1/users/_userID/banner/router.ts @@ -86,7 +86,7 @@ router.get("/", (req, res) => { if (!user.customBanner) { res.setHeader("Content-Type", "image/png"); - return CDNRedirect(res, "/users/default/banner.png"); + return CDNRedirect(res, "/users/default/banner"); } // express sniffs whether this is a png or jpg **and** browsers dont care either. diff --git a/server/src/server/router/api/v1/users/_userID/pfp/router.test.ts b/server/src/server/router/api/v1/users/_userID/pfp/router.test.ts index 2217791b0..4eb04319e 100644 --- a/server/src/server/router/api/v1/users/_userID/pfp/router.test.ts +++ b/server/src/server/router/api/v1/users/_userID/pfp/router.test.ts @@ -11,7 +11,7 @@ t.test("GET /api/v1/users/:userID/pfp", (t) => { t.beforeEach(ResetDBState); t.test("Should return the default profile picture if user has no custom pfp", async (t) => { - await CDNStoreOrOverwrite("/users/default/pfp.png", "test"); + await CDNStoreOrOverwrite("/users/default/pfp", "test"); // we have to follow redirs here lol const res = await mockApi.get("/api/v1/users/1/pfp").redirects(1); diff --git a/server/src/server/router/api/v1/users/_userID/pfp/router.ts b/server/src/server/router/api/v1/users/_userID/pfp/router.ts index 97e557cc7..76348fab4 100644 --- a/server/src/server/router/api/v1/users/_userID/pfp/router.ts +++ b/server/src/server/router/api/v1/users/_userID/pfp/router.ts @@ -84,7 +84,7 @@ router.get("/", (req, res) => { if (!user.customPfp) { res.setHeader("Content-Type", "image/png"); - return CDNRedirect(res, "/users/default/pfp.png"); + return CDNRedirect(res, "/users/default/pfp"); } return CDNRedirect(res, GetProfilePictureURL(user.id)); diff --git a/server/src/test-utils/asserts.ts b/server/src/test-utils/asserts.ts index f18f23c2c..3fe680801 100644 --- a/server/src/test-utils/asserts.ts +++ b/server/src/test-utils/asserts.ts @@ -1,14 +1,15 @@ +import { rootLogger } from "lib/logger/logger"; import Prudence, { PrudenceSchema } from "prudence"; import t from "tap"; -export function isApproximately(number: number, target: number, message: string, lenience = 0.01) { +export function isApproximately(number: number, target: number, message?: string, lenience = 0.01) { const result = t.ok(Math.abs(number - target) < lenience, message); if (!result) { - throw new Error(`${number} was not close enough to ${target}`); + rootLogger.error(`${number} was not close enough to ${target}`); } - return true; + // return true; } export function prAssert(