diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml index bf6affba8..79b7ef934 100644 --- a/server/pnpm-lock.yaml +++ b/server/pnpm-lock.yaml @@ -61,7 +61,7 @@ dependencies: express-async-errors: 3.1.1_express@4.17.1 express-session: 1.17.1 fast-json-stable-hash: 1.0.1 - kamaitachi-common: github.com/zkldi/Kamaitachi-common/37b51aefb55dc1e1370c756069a506ac89ebeacd + kamaitachi-common: github.com/zkldi/Kamaitachi-common/52d9ef28d774c0f8581003bdb1ad2e64c7dae543 mongodb: 3.6.6 monk: 7.3.4 multer: 1.4.2 @@ -4601,8 +4601,8 @@ packages: '@types/yoga-layout': 1.9.2 dev: true - github.com/zkldi/Kamaitachi-common/37b51aefb55dc1e1370c756069a506ac89ebeacd: - resolution: {tarball: https://codeload.github.com/zkldi/Kamaitachi-common/tar.gz/37b51aefb55dc1e1370c756069a506ac89ebeacd} + github.com/zkldi/Kamaitachi-common/52d9ef28d774c0f8581003bdb1ad2e64c7dae543: + resolution: {tarball: https://codeload.github.com/zkldi/Kamaitachi-common/tar.gz/52d9ef28d774c0f8581003bdb1ad2e64c7dae543} name: kamaitachi-common version: 0.1.0 dependencies: diff --git a/server/src/db/schemas.ts b/server/src/db/schemas.ts index 0dfb734fe..f3f659bc8 100644 --- a/server/src/db/schemas.ts +++ b/server/src/db/schemas.ts @@ -145,16 +145,22 @@ const PR_SCORE_IIDX_SP: PrudenceSchema = CreatePRScore( "SP", { bp: nullableAndOptional(p.isPositiveInteger), - gauge: p.optional(p.isBetween(0, 100)), - gaugeHistory: p.optional([p.isBetween(0, 100)]), + gauge: nullableAndOptional(p.isBetween(0, 100)), + gaugeHistory: p.optional([nullableAndOptional(p.isBetween(0, 100))]), comboBreak: optionalPositiveInt, deadMeasure: nullableAndOptional(p.isPositiveInteger), deadNote: nullableAndOptional(p.isPositiveInteger), }, { - random: p.optional(p.isIn(["NONRAN", "RANDOM", "R-RANDOM", "S-RANDOM", "MIRROR"])), - assist: p.optional(p.isIn(["NO ASSIST", "AUTO SCRATCH", "LEGACY NOTE", "ASCR + LEGACY"])), - range: p.optional(p.isIn(["NONE", "SUDDEN+", "HIDDEN+", "SUD+ HID+", "LIFT", "LIFT SUD+"])), + random: nullableAndOptional(p.isIn(["NONRAN", "RANDOM", "R-RANDOM", "S-RANDOM", "MIRROR"])), + gauge: nullableAndOptional(p.isIn(["ASSISTED EASY", "EASY", "NORMAL", "HARD", "EX-HARD"])), + assist: nullableAndOptional( + p.isIn(["NO ASSIST", "AUTO SCRATCH", "LEGACY NOTE", "ASCR + LEGACY"]) + ), + range: nullableAndOptional( + p.isIn(["NONE", "SUDDEN+", "HIDDEN+", "SUD+ HID+", "LIFT", "LIFT SUD+"]) + ), + pacemaker: "*?string", // lazy pacemakerName: "*?string", pacemakerTarget: nullableAndOptional(p.isPositiveInteger), }, @@ -184,7 +190,7 @@ const PR_SCORE_BMS_7K: PrudenceSchema = CreatePRScore( }, { random: nullableAndOptional(p.isIn(["NONRAN", "RANDOM", "R-RANDOM", "S-RANDOM", "MIRROR"])), - inputDevice: nullableAndOptional(p.isIn(["KB", "BM_CONTROLLER", "MIDI"])), + inputDevice: nullableAndOptional(p.isIn(["KEYBOARD", "BM_CONTROLLER", "MIDI"])), } ); @@ -232,7 +238,7 @@ export const PRUDENCE_SCORE_SCHEMAS: ScoreSchemas = { DP: deepmerge(PR_SCORE_IIDX_SP, { playtype: p.equalTo("DP"), scoreMeta: { - random: p.optional(DoublePlayTwinRandomTuple), + random: nullableAndOptional(DoublePlayTwinRandomTuple), }, calculatedData: { gameSpecific: { @@ -245,7 +251,12 @@ export const PRUDENCE_SCORE_SCHEMAS: ScoreSchemas = { Single: CreatePRScore( "sdvx", "Single", - { gauge: p.optional(p.isBetween(0, 100)) }, + { + gauge: p.optional(p.isBetween(0, 100)), + btnRate: p.optional(p.isBetween(0, 100)), + holdRate: p.optional(p.isBetween(0, 100)), + laserRate: p.optional(p.isBetween(0, 100)), + }, {}, { VF4: p.nullable(p.isPositiveInteger), diff --git a/server/src/scripts/__KT_DATABASE_MIGRATION/migrate.ts b/server/src/scripts/__KT_DATABASE_MIGRATION/migrate.ts index bc63ecc34..ec93599cb 100644 --- a/server/src/scripts/__KT_DATABASE_MIGRATION/migrate.ts +++ b/server/src/scripts/__KT_DATABASE_MIGRATION/migrate.ts @@ -32,7 +32,9 @@ export default async function MigrateRecords( } const newDoc = HandlerFN(c); - newDocuments.push(newDoc); + if (newDoc !== null) { + newDocuments.push(newDoc); + } }); logger.info(`Inserting ${newDocuments.length} documents.`); diff --git a/server/src/scripts/__KT_DATABASE_MIGRATION/scores.ts b/server/src/scripts/__KT_DATABASE_MIGRATION/scores.ts index e9fe1c756..2bd2747fd 100644 --- a/server/src/scripts/__KT_DATABASE_MIGRATION/scores.ts +++ b/server/src/scripts/__KT_DATABASE_MIGRATION/scores.ts @@ -1,6 +1,7 @@ import { PrivateUserDocument, ScoreDocument } from "kamaitachi-common"; -import { grades, lamps } from "kamaitachi-common/js/config"; +import { grades, lamps, supportedGames, validPlaytypes } from "kamaitachi-common/js/config"; import db from "../../db/db"; +import { rootLogger } from "../../logger"; import { CreateScoreID } from "../../score-import/framework/core/score-id"; import MigrateRecords from "./migrate"; @@ -12,7 +13,21 @@ function ConditionalAssign(base: any, baseProp: string, other: any, otherProp: s } } -function ConvertFn(c: any): ScoreDocument { +function ConvertFn(c: any): ScoreDocument | null { + if (!supportedGames.includes(c.game)) { + rootLogger.warn(`Ignored game ${c.game}`); + return null; + } + + if (["popn", "jubeat", "gitadora", "usc"].includes(c.game)) { + return null; + } + + // @ts-expect-error yea + if (validPlaytypes[c.game].includes(c.playtype)) { + rootLogger.warn(`Ignored game pt ${c.game}, ${c.playtype}`); + } + let base: Omit = { userID: c.userID, songID: c.songID, @@ -22,8 +37,8 @@ function ConvertFn(c: any): ScoreDocument { game: c.game, timeAdded: c.timeAdded, timeAchieved: Number.isNaN(c.timeAchieved) ? null : c.timeAchieved, - isScorePB: c.isScorePB, - isLampPB: c.isLampPB, + isScorePB: !!c.isScorePB, + isLampPB: !!c.isLampPB, comment: c.comment ?? null, highlight: c.highlight ?? false, service: c.service, @@ -54,27 +69,66 @@ function ConvertFn(c: any): ScoreDocument { ConditionalAssign(base.scoreMeta, "pacemaker", c.scoreMeta, "pacemaker"); ConditionalAssign(base.scoreMeta, "pacemakerName", c.scoreMeta, "pacemakerName"); ConditionalAssign(base.scoreMeta, "pacemakerTarget", c.scoreMeta, "pacemakerTarget"); + + if (base.playtype === "DP" && !Array.isArray(base.scoreMeta.random)) { + base.scoreMeta.random = null; + } + + // @ts-expect-error asdf + if (base.scoreMeta.range === "") { + // @ts-expect-error asdf + base.scoreMeta.range = "NONE"; + } } else if (base.game === "bms") { - // @ts-expect-error shut - if (base.scoreData.hitMeta.gauge === -1) { - // @ts-expect-error shut - base.scoreData.hitMeta.gauge = null; - } - - // @ts-expect-error shut - if (base.scoreData.hitMeta.bp === -1 || Number.isNaN(base.scoreData.hitMeta.bp)) { - // @ts-expect-error shut - base.scoreData.hitMeta.bp = null; - } - ConditionalAssign(base.scoreMeta, "random", c.scoreMeta, "optionsRandom"); ConditionalAssign(base.scoreMeta, "inputDevice", c.scoreData.hitMeta, "inputDevice"); - - // @ts-expect-error shut - delete base.scoreData.hitMeta.inputDevice; } } + // @ts-expect-error shut + if (base.scoreData.hitMeta.bp === -1 || Number.isNaN(base.scoreData.hitMeta.bp)) { + // @ts-expect-error shut + base.scoreData.hitMeta.bp = null; + } + + if (base.game === "iidx") { + // @ts-expect-error fuck you + if (base.scoreData.hitMeta.gauge > 200) { + // @ts-expect-error fuck you + base.scoreData.hitMeta.gauge = null; + } + + // @ts-expect-error fuck you + if (base.scoreData.hitMeta.gaugeHistory) { + // @ts-expect-error fuck you + base.scoreData.hitMeta.gaugeHistory = base.scoreData.hitMeta.gaugeHistory.map((e) => + e > 200 ? null : e + ); + } + } else if (base.game === "bms") { + // @ts-expect-error shut + if (base.scoreData.hitMeta.gauge === -1) { + // @ts-expect-error shut + base.scoreData.hitMeta.gauge = null; + } + + // @ts-expect-error shut + delete base.scoreData.hitMeta.inputDevice; + } else if (base.game === "sdvx" || base.game === "usc") { + ConditionalAssign(base.scoreData.hitData, "miss", base.scoreData.hitData, "error"); + + //@ts-expect-error yea + delete base.scoreData.hitData.error; + } else if (base.game === "chunithm") { + if (base.scoreData.percent === 101) { + base.scoreData.grade === "SSS"; + } + } + + if (base.service === "mm") { + base.service = "maimagic"; + } + let scoreID = CreateScoreID(base.userID, base, base.chartID); let score: ScoreDocument = { diff --git a/server/src/scripts/validate-database.ts b/server/src/scripts/validate-database.ts index d052de9f5..e033b5f16 100644 --- a/server/src/scripts/validate-database.ts +++ b/server/src/scripts/validate-database.ts @@ -105,7 +105,7 @@ async function ValidateScores(): Promise { Number(end - start) / 1e9 } seconds.\nSuccess: ${successCount} (${((successCount * 100) / total).toFixed( 2 - )}%\nFail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%))` + )}%)\nFail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)` ); }