diff --git a/server/scripts/validate-database.ts b/server/scripts/validate-database.ts index 778b41149..be15c2ec3 100644 --- a/server/scripts/validate-database.ts +++ b/server/scripts/validate-database.ts @@ -16,180 +16,180 @@ const BASE_DIR = path.join(__dirname, "./validate-database-errs"); const logger = CreateLogCtx(__filename); async function ValidateStaticSchemas(): Promise { - for (const x in STATIC_SCHEMAS) { - const c = x as keyof typeof STATIC_SCHEMAS; + for (const x in STATIC_SCHEMAS) { + const c = x as keyof typeof STATIC_SCHEMAS; - const schema = STATIC_SCHEMAS[c] as PrudenceSchema; + const schema = STATIC_SCHEMAS[c] as PrudenceSchema; - logger.info(`=== Validating Collection ${c}... ===`); + logger.info(`=== Validating Collection ${c}... ===`); - let successCount = 0; - let total = 0; - const fails: { err: PrudenceError; doc: unknown }[] = []; + let successCount = 0; + let total = 0; + const fails: { err: PrudenceError; doc: unknown }[] = []; - const start = process.hrtime.bigint(); + const start = process.hrtime.bigint(); - // @ts-expect-error shut UP - // eslint-disable-next-line no-await-in-loop - await db[c].find({}, { projection: { _id: 0 } }).each((c: unknown) => { - total++; - const res = Prudence(c, schema); + // @ts-expect-error shut UP + // eslint-disable-next-line no-await-in-loop + await db[c].find({}, { projection: { _id: 0 } }).each((c: unknown) => { + total++; + const res = Prudence(c, schema); - if (res === null) { - successCount++; - } else { - logger.error(res); - fails.push({ err: res, doc: c }); - } - }); + if (res === null) { + successCount++; + } else { + logger.error(res); + fails.push({ err: res, doc: c }); + } + }); - const end = process.hrtime.bigint(); - logger.info(`Validated ${total} objects. Took ${Number(end - start) / 1e9} seconds.`); - logger.info(`Success: ${successCount} (${((successCount * 100) / total).toFixed(2)}%)`); - logger.info(`Fail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)`); + const end = process.hrtime.bigint(); + logger.info(`Validated ${total} objects. Took ${Number(end - start) / 1e9} seconds.`); + logger.info(`Success: ${successCount} (${((successCount * 100) / total).toFixed(2)}%)`); + logger.info(`Fail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)`); - if (fails.length !== 0) { - logger.severe(`Invalid documents found! Please resolve them.`); - fs.writeFileSync(path.join(BASE_DIR, `${c}.json`), JSON.stringify(fails)); - } - } + if (fails.length !== 0) { + logger.severe(`Invalid documents found! Please resolve them.`); + fs.writeFileSync(path.join(BASE_DIR, `${c}.json`), JSON.stringify(fails)); + } + } - logger.info("Done!"); - process.exit(0); + logger.info("Done!"); + process.exit(0); } async function ValidateScores(): Promise { - const globalStart = process.hrtime.bigint(); - let globalTotal = 0; - let globalSuccess = 0; - let globalFail = 0; - for (const game of CONF_INFO.SUPPORTED_GAMES) { - for (const playtype of validPlaytypes[game]) { - // @ts-expect-error shut up - const schema = PRUDENCE_SCORE_SCHEMAS[game][playtype]; + const globalStart = process.hrtime.bigint(); + let globalTotal = 0; + let globalSuccess = 0; + let globalFail = 0; + for (const game of CONF_INFO.supportedGames) { + for (const playtype of validPlaytypes[game]) { + // @ts-expect-error shut up + const schema = PRUDENCE_SCORE_SCHEMAS[game][playtype]; - let successCount = 0; - let total = 0; - const fails: { err: PrudenceError; doc: unknown }[] = []; + let successCount = 0; + let total = 0; + const fails: { err: PrudenceError; doc: unknown }[] = []; - logger.info(`=== Validating Collection scores (${game} ${playtype}) ... ===`); - const start = process.hrtime.bigint(); + logger.info(`=== Validating Collection scores (${game} ${playtype}) ... ===`); + const start = process.hrtime.bigint(); - // eslint-disable-next-line no-await-in-loop - await db.scores - .find({ playtype, game }, { projection: { _id: 0 } }) - // @ts-expect-error shut UP - .each((c: unknown) => { - total++; - const res = Prudence(c, schema); + // eslint-disable-next-line no-await-in-loop + await db.scores + .find({ playtype, game }, { projection: { _id: 0 } }) + // @ts-expect-error shut UP + .each((c: unknown) => { + total++; + const res = Prudence(c, schema); - if (res === null) { - successCount++; - } else { - logger.error( - `[${game} ${playtype}] [${res.keychain}] ${res.message}: ${res.userVal}` - ); - fails.push({ err: res, doc: c }); - } - }); + if (res === null) { + successCount++; + } else { + logger.error( + `[${game} ${playtype}] [${res.keychain}] ${res.message}: ${res.userVal}` + ); + fails.push({ err: res, doc: c }); + } + }); - const end = process.hrtime.bigint(); - logger.info(`Validated ${total} objects. Took ${Number(end - start) / 1e9} seconds.`); - logger.info(`Success: ${successCount} (${((successCount * 100) / total).toFixed(2)}%)`); - logger.info(`Fail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)`); + const end = process.hrtime.bigint(); + logger.info(`Validated ${total} objects. Took ${Number(end - start) / 1e9} seconds.`); + logger.info(`Success: ${successCount} (${((successCount * 100) / total).toFixed(2)}%)`); + logger.info(`Fail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)`); - if (fails.length !== 0) { - logger.severe(`Invalid documents found! Please resolve them.`); - fs.writeFileSync( - path.join(BASE_DIR, `scores-${game}-${playtype}.json`), - JSON.stringify(fails) - ); - fs.writeFileSync( - path.join(BASE_DIR, `scores-${game}-${playtype}.log`), - `Validated ${total} objects. Took ${ - Number(end - start) / 1e9 - } seconds.\nSuccess: ${successCount} (${((successCount * 100) / total).toFixed( - 2 - )}%)\nFail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)` - ); - } + if (fails.length !== 0) { + logger.severe(`Invalid documents found! Please resolve them.`); + fs.writeFileSync( + path.join(BASE_DIR, `scores-${game}-${playtype}.json`), + JSON.stringify(fails) + ); + fs.writeFileSync( + path.join(BASE_DIR, `scores-${game}-${playtype}.log`), + `Validated ${total} objects. Took ${ + Number(end - start) / 1e9 + } seconds.\nSuccess: ${successCount} (${((successCount * 100) / total).toFixed( + 2 + )}%)\nFail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)` + ); + } - globalTotal += total; - globalFail += fails.length; - globalSuccess += successCount; - } - } + globalTotal += total; + globalFail += fails.length; + globalSuccess += successCount; + } + } - const globalEnd = process.hrtime.bigint(); - logger.info( - `Validated ${globalTotal} objects. Took ${Number(globalEnd - globalStart) / 1e9} seconds.` - ); - logger.info(`Success: ${globalSuccess} (${((globalSuccess * 100) / globalTotal).toFixed(2)}%)`); - logger.info(`Fail: ${globalFail} (${((globalFail * 100) / globalTotal).toFixed(2)}%)`); + const globalEnd = process.hrtime.bigint(); + logger.info( + `Validated ${globalTotal} objects. Took ${Number(globalEnd - globalStart) / 1e9} seconds.` + ); + logger.info(`Success: ${globalSuccess} (${((globalSuccess * 100) / globalTotal).toFixed(2)}%)`); + logger.info(`Fail: ${globalFail} (${((globalFail * 100) / globalTotal).toFixed(2)}%)`); - // process.exit(1); + // process.exit(1); } async function ValidateChartsOrSongs(type: "songs" | "charts"): Promise { - const globalStart = process.hrtime.bigint(); - let globalTotal = 0; - let globalSuccess = 0; - let globalFail = 0; - for (const game of CONF_INFO.SUPPORTED_GAMES) { - const schema = STATIC_SCHEMAS[type]![game]; + const globalStart = process.hrtime.bigint(); + let globalTotal = 0; + let globalSuccess = 0; + let globalFail = 0; + for (const game of CONF_INFO.supportedGames) { + const schema = STATIC_SCHEMAS[type]![game]; - let successCount = 0; - let total = 0; - const fails: { err: PrudenceError; doc: unknown }[] = []; + let successCount = 0; + let total = 0; + const fails: { err: PrudenceError; doc: unknown }[] = []; - logger.info(`=== Validating Collection ${type} (${game}) ... ===`); - const start = process.hrtime.bigint(); + logger.info(`=== Validating Collection ${type} (${game}) ... ===`); + const start = process.hrtime.bigint(); - // eslint-disable-next-line no-await-in-loop - await db[type][game] - // @ts-expect-error whatever bro - .find({}, { projection: { _id: 0 } }) - .each((c: unknown) => { - total++; - const res = Prudence(c, schema); + // eslint-disable-next-line no-await-in-loop + await db[type][game] + // @ts-expect-error whatever bro + .find({}, { projection: { _id: 0 } }) + .each((c: unknown) => { + total++; + const res = Prudence(c, schema); - if (res === null) { - successCount++; - } else { - logger.error(`[${game}] [${res.keychain}] ${res.message}: ${res.userVal}`); - fails.push({ err: res, doc: c }); - } - }); + if (res === null) { + successCount++; + } else { + logger.error(`[${game}] [${res.keychain}] ${res.message}: ${res.userVal}`); + fails.push({ err: res, doc: c }); + } + }); - const end = process.hrtime.bigint(); - logger.info(`Validated ${total} objects. Took ${Number(end - start) / 1e9} seconds.`); - logger.info(`Success: ${successCount} (${((successCount * 100) / total).toFixed(2)}%)`); - logger.info(`Fail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)`); + const end = process.hrtime.bigint(); + logger.info(`Validated ${total} objects. Took ${Number(end - start) / 1e9} seconds.`); + logger.info(`Success: ${successCount} (${((successCount * 100) / total).toFixed(2)}%)`); + logger.info(`Fail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)`); - if (fails.length !== 0) { - logger.severe(`Invalid documents found! Please resolve them.`); - fs.writeFileSync(path.join(BASE_DIR, `${type}-${game}.json`), JSON.stringify(fails)); - fs.writeFileSync( - path.join(BASE_DIR, `${type}-${game}.log`), - `Validated ${total} objects. Took ${ - Number(end - start) / 1e9 - } seconds.\nSuccess: ${successCount} (${((successCount * 100) / total).toFixed( - 2 - )}%)\nFail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)` - ); - } + if (fails.length !== 0) { + logger.severe(`Invalid documents found! Please resolve them.`); + fs.writeFileSync(path.join(BASE_DIR, `${type}-${game}.json`), JSON.stringify(fails)); + fs.writeFileSync( + path.join(BASE_DIR, `${type}-${game}.log`), + `Validated ${total} objects. Took ${ + Number(end - start) / 1e9 + } seconds.\nSuccess: ${successCount} (${((successCount * 100) / total).toFixed( + 2 + )}%)\nFail: ${fails.length} (${((fails.length * 100) / total).toFixed(2)}%)` + ); + } - globalTotal += total; - globalFail += fails.length; - globalSuccess += successCount; - } + globalTotal += total; + globalFail += fails.length; + globalSuccess += successCount; + } - const globalEnd = process.hrtime.bigint(); - logger.info( - `Validated ${globalTotal} objects. Took ${Number(globalEnd - globalStart) / 1e9} seconds.` - ); - logger.info(`Success: ${globalSuccess} (${((globalSuccess * 100) / globalTotal).toFixed(2)}%)`); - logger.info(`Fail: ${globalFail} (${((globalFail * 100) / globalTotal).toFixed(2)}%)`); + const globalEnd = process.hrtime.bigint(); + logger.info( + `Validated ${globalTotal} objects. Took ${Number(globalEnd - globalStart) / 1e9} seconds.` + ); + logger.info(`Success: ${globalSuccess} (${((globalSuccess * 100) / globalTotal).toFixed(2)}%)`); + logger.info(`Fail: ${globalFail} (${((globalFail * 100) / globalTotal).toFixed(2)}%)`); } // ValidateStaticSchemas(); diff --git a/server/src/external/mongo/indexes.ts b/server/src/external/mongo/indexes.ts index 23f3de4c9..6e6b19725 100644 --- a/server/src/external/mongo/indexes.ts +++ b/server/src/external/mongo/indexes.ts @@ -75,7 +75,7 @@ const staticIndexes: Partial> = { const indexes: Partial> = staticIndexes; -for (const game of CONF_INFO.SUPPORTED_GAMES) { +for (const game of CONF_INFO.supportedGames) { if (indexes[`charts-${game}` as ValidDatabases]) { indexes[`charts-${game}` as ValidDatabases]!.push( index({ chartID: 1 }, UNIQUE), diff --git a/server/src/external/mongo/schemas.ts b/server/src/external/mongo/schemas.ts index eebace3d6..05499c490 100644 --- a/server/src/external/mongo/schemas.ts +++ b/server/src/external/mongo/schemas.ts @@ -1,5 +1,5 @@ import deepmerge from "deepmerge"; -import { Game, Playtypes } from "tachi-common"; +import { Game, Playtypes, GetGameConfig, GetGamePTConfig } from "tachi-common"; import p, { PrudenceSchema, ValidSchemaValue } from "prudence"; import { CONF_INFO } from "../../lib/setup/config"; @@ -92,7 +92,7 @@ export const PR_SCORE_GENERIC = { comment: p.nullable(p.isBoundedString(1, 240)), timeAdded: p.isPositive, scoreID: "string", // temp - importType: p.nullable(p.isIn(importTypes)), + importType: p.nullable(p.isIn(CONF_INFO.supportedImportTypes)), }; type ScoreSchemas = { @@ -107,28 +107,35 @@ const nullableAndOptional = (fn: ValidSchemaValue) => p.optional(p.nullable(fn)) const nullableAndOptionalPosInt = nullableAndOptional(p.isPositiveInteger); -const CreateGameScoreData = (game: Game, hitMetaMerge: PrudenceSchema) => ({ - lamp: p.isIn(lamps[game]), - lampIndex: p.and( - p.isPositiveInteger, - (self, parent) => lamps[game][self as number] === parent.lamp - ), - grade: p.isIn(grades[game]), - gradeIndex: p.and( - p.isPositiveInteger, - (self, parent) => grades[game][self as number] === parent.grade - ), - judgements: Object.fromEntries(validjudgements[game].map((e) => [e, optionalPositiveInt])), - hitMeta: deepmerge( - { - fast: nullableAndOptionalPosInt, - slow: nullableAndOptionalPosInt, - maxCombo: nullableAndOptionalPosInt, - }, - hitMetaMerge - ), - esd: p.nullable(p.isPositive), -}); +const CreateGameScoreData = ( + game: Game, + playtype: Playtypes[Game], + hitMetaMerge: PrudenceSchema +) => { + const gptConfig = GetGamePTConfig(game, playtype); + return { + lamp: p.isIn(gptConfig.lamps), + lampIndex: p.and( + p.isPositiveInteger, + (self, parent) => gptConfig.lamps[self as number] === parent.lamp + ), + grade: p.isIn(gptConfig.grades), + gradeIndex: p.and( + p.isPositiveInteger, + (self, parent) => gptConfig.grades[self as number] === parent.grade + ), + judgements: Object.fromEntries(gptConfig.judgements.map((e) => [e, optionalPositiveInt])), + hitMeta: deepmerge( + { + fast: nullableAndOptionalPosInt, + slow: nullableAndOptionalPosInt, + maxCombo: nullableAndOptionalPosInt, + }, + hitMetaMerge + ), + esd: p.nullable(p.isPositive), + }; +}; const PR_SCORE_IIDX_SP: PrudenceSchema = CreatePRScore( "iidx", @@ -194,7 +201,7 @@ function CreatePRScore( return deepmerge(PR_SCORE_GENERIC, { game: p.equalTo(game), playtype: p.equalTo(playtype), - scoreData: CreateGameScoreData(game, mergeHitMeta), + scoreData: CreateGameScoreData(game, playtype, mergeHitMeta), scoreMeta: mergeScoreMeta, calculatedData: { gameSpecific: mergeGameSpecific, @@ -292,9 +299,9 @@ export const PRUDENCE_SCORE_SCHEMAS: ScoreSchemas = { Gita: CreatePRScore("gitadora", "Gita"), Dora: CreatePRScore("gitadora", "Dora"), }, - jubeat: { - Single: CreatePRScore("jubeat", "Single"), - }, + // jubeat: { + // Single: CreatePRScore("jubeat", "Single"), + // }, maimai: { Single: deepmerge(CreatePRScore("maimai", "Single"), { scoreData: { percent: p.isBetween(0, 150) }, @@ -303,9 +310,9 @@ export const PRUDENCE_SCORE_SCHEMAS: ScoreSchemas = { museca: { Single: CreatePRScore("museca", "Single"), }, - popn: { - "9B": CreatePRScore("popn", "9B", { gauge: p.optional(p.isBetween(0, 100)) }), - }, + // popn: { + // "9B": CreatePRScore("popn", "9B", { gauge: p.optional(p.isBetween(0, 100)) }), + // }, usc: { Single: CreatePRScore("usc", "Single", { gauge: p.optional(p.isBetween(0, 100)) }), }, @@ -322,9 +329,16 @@ const PRUDENCE_CHART_BASE: PrudenceSchema = { }; function CreatePrChart(game: Game, flags: string[], data: PrudenceSchema) { + const gameConfig = GetGameConfig(game); + + const validDifficulties = []; + for (const playtype of gameConfig.validPlaytypes) { + validDifficulties.push(...GetGamePTConfig(game, playtype).difficulties); + } + return deepmerge(PRUDENCE_CHART_BASE, { - difficulty: p.isIn(validDifficulties[game]), - playtype: p.isIn(validPlaytypes[game]), + difficulty: p.isIn(validDifficulties), + playtype: p.isIn(gameConfig.validPlaytypes), flags: Object.fromEntries(flags.map((e) => [e, "boolean"])), data, }); @@ -347,13 +361,13 @@ export const PRUDENCE_CHART_SCHEMAS: Record = { gitadora: CreatePrChart("gitadora", ["IN BASE GAME", "OMNIMIX", "HOT N-1", "HOT"], { inGameID: p.isPositiveInteger, }), - jubeat: CreatePrChart("jubeat", ["IN BASE GAME"], {}), + // jubeat: CreatePrChart("jubeat", ["IN BASE GAME"], {}), maimai: CreatePrChart("maimai", ["IN BASE GAME"], { maxPercent: p.gte(100), inGameID: "string", }), museca: CreatePrChart("museca", ["IN BASE GAME", "OMNIMIX"], {}), - popn: CreatePrChart("popn", ["IN BASE GAME", "OMNIMIX"], {}), + // popn: CreatePrChart("popn", ["IN BASE GAME", "OMNIMIX"], {}), sdvx: CreatePrChart("sdvx", ["IN BASE GAME", "OMNIMIX", "N-1"], { inGameID: p.isPositiveInteger, }), @@ -385,10 +399,10 @@ export const PRUDENCE_SONG_SCHEMAS: Record = { chunithm: PRUDENCE_SONG_WITH_GENRE, ddr: CreatePrSong({}), gitadora: CreatePrSong({}), - jubeat: CreatePrSong({}), + // jubeat: CreatePrSong({}), maimai: CreatePrSong({ titleJP: "string", artistJP: "string", genre: "string" }), museca: CreatePrSong({ titleJP: "string", artistJP: "string" }), - popn: PRUDENCE_SONG_WITH_GENRE, + // popn: PRUDENCE_SONG_WITH_GENRE, sdvx: CreatePrSong({ uscEquiv: p.nullable(p.isPositiveInteger) }), usc: CreatePrSong({ sdvxEquiv: p.nullable(p.isPositiveInteger) }), }; @@ -400,8 +414,8 @@ const PRUDENCE_FOLDER_CHART_LOOKUP: PrudenceSchema = { const PRUDENCE_FOLDER: PrudenceSchema = { title: "string", - game: p.isIn(CONF_INFO.SUPPORTED_GAMES), - playtype: (self, parent) => p.isIn(validPlaytypes[parent.game as Game])(self), + game: p.isIn(CONF_INFO.supportedGames), + playtype: (self, parent) => p.isIn(GetGameConfig(parent.game as Game).validPlaytypes)(self), folderID: "string", table: "string", tableIndex: "number", diff --git a/server/src/lib/score-import/framework/calculated-data/calculated-data.ts b/server/src/lib/score-import/framework/calculated-data/calculated-data.ts index bd177ba1a..321049770 100644 --- a/server/src/lib/score-import/framework/calculated-data/calculated-data.ts +++ b/server/src/lib/score-import/framework/calculated-data/calculated-data.ts @@ -69,9 +69,9 @@ const CalculatedDataFunctions: CalculatedDataFunctions = { sdvx: { Single: CalculateDataSDVXorUSC, }, - popn: { - "9B": () => ({}), - }, + // popn: { + // "9B": () => ({}), + // }, museca: { Single: CalculateDataMuseca, }, @@ -93,9 +93,9 @@ const CalculatedDataFunctions: CalculatedDataFunctions = { SP: CalculateDataDDR, DP: CalculateDataDDR, }, - jubeat: { - Single: CalculateDataJubeat, - }, + // jubeat: { + // Single: CalculateDataJubeat, + // }, usc: { Single: CalculateDataSDVXorUSC, }, @@ -310,13 +310,13 @@ async function CalculateDataBMS7K( }; } -async function CalculateDataJubeat( - dryScore: DryScore, - chart: AnyChartDocument, - defaultTierlistID: string | undefined, - logger: KtLogger -): Promise> { - return { - jubility: 0, // @todo #163 Jubeat Jubility - }; -} +// async function CalculateDataJubeat( +// dryScore: DryScore, +// chart: AnyChartDocument, +// defaultTierlistID: string | undefined, +// logger: KtLogger +// ): Promise> { +// return { +// jubility: 0, // @todo #163 Jubeat Jubility +// }; +// } diff --git a/server/src/lib/score-import/framework/score-importing/hydrate-score.ts b/server/src/lib/score-import/framework/score-importing/hydrate-score.ts index ebac51a87..372f60fe9 100644 --- a/server/src/lib/score-import/framework/score-importing/hydrate-score.ts +++ b/server/src/lib/score-import/framework/score-importing/hydrate-score.ts @@ -1,4 +1,10 @@ -import { AnyChartDocument, config, integer, ScoreDocument, AnySongDocument } from "tachi-common"; +import { + AnyChartDocument, + integer, + ScoreDocument, + AnySongDocument, + GetGamePTConfig, +} from "tachi-common"; import { KtLogger } from "../../../logger/logger"; import { CreateCalculatedData } from "../calculated-data/calculated-data"; import { CalculateESDForGame } from "../common/score-utils"; @@ -27,12 +33,13 @@ export async function HydrateScore( const { scoreData: dryScoreData, ...rest } = dryScore; + const gptConfig = GetGamePTConfig(dryScore.game, chart.playtype); + // Fill out the rest of the fields we want for scoreData const scoreData = Object.assign( { - // @todo #103 lamps may need to be separate upon game:playtype someday. Maybe. We need to check this out - lampIndex: config.lamps[dryScore.game].indexOf(dryScore.scoreData.lamp as string), - gradeIndex: config.grades[dryScore.game].indexOf(dryScore.scoreData.grade as string), + lampIndex: gptConfig.lamps.indexOf(dryScore.scoreData.lamp), + gradeIndex: gptConfig.grades.indexOf(dryScore.scoreData.grade), esd, }, dryScoreData diff --git a/server/src/lib/score-import/framework/sessions/calculated-data.ts b/server/src/lib/score-import/framework/sessions/calculated-data.ts index bf1547dbd..338c66fec 100644 --- a/server/src/lib/score-import/framework/sessions/calculated-data.ts +++ b/server/src/lib/score-import/framework/sessions/calculated-data.ts @@ -64,9 +64,9 @@ const CalculatedDataFunctions: CalculatedDataFunctions = { }; }, }, - popn: { - "9B": () => ({}), - }, + // popn: { + // "9B": () => ({}), + // }, museca: { Single: (scd) => ({ ktRating: AvgBest10Map(scd, "ktRating"), @@ -108,11 +108,11 @@ const CalculatedDataFunctions: CalculatedDataFunctions = { ktRating: AvgBest10Map(scd, "ktRating"), }), }, - jubeat: { - Single: (scd) => ({ - jubility: AvgBest10Map(scd, "jubility"), - }), - }, + // jubeat: { + // Single: (scd) => ({ + // jubility: AvgBest10Map(scd, "jubility"), + // }), + // }, usc: { Single: (scd) => { const VF6 = AvgBest10Map(scd, "VF6"); diff --git a/server/src/lib/score-import/framework/user-game-stats/builtin-class-handlers.ts b/server/src/lib/score-import/framework/user-game-stats/builtin-class-handlers.ts index d99e469df..08e3d4882 100644 --- a/server/src/lib/score-import/framework/user-game-stats/builtin-class-handlers.ts +++ b/server/src/lib/score-import/framework/user-game-stats/builtin-class-handlers.ts @@ -94,13 +94,13 @@ export function GitadoraSkillToColour(sk: number) { return GitadoraColours.WHITE; } -export function CalculateJubeatColour( - game: Game, - playtype: Playtypes[Game], - userID: integer, - ratings: Record -): GameClasses<"jubeat:Single"> { - throw new Error("Not implemented."); -} +// export function CalculateJubeatColour( +// game: Game, +// playtype: Playtypes[Game], +// userID: integer, +// ratings: Record +// ): GameClasses<"jubeat:Single"> { +// throw new Error("Not implemented."); +// } // function JubilityToColour(jb: number) {} diff --git a/server/src/lib/score-import/framework/user-game-stats/classes.ts b/server/src/lib/score-import/framework/user-game-stats/classes.ts index 720d86b69..4a48518bc 100644 --- a/server/src/lib/score-import/framework/user-game-stats/classes.ts +++ b/server/src/lib/score-import/framework/user-game-stats/classes.ts @@ -2,11 +2,7 @@ import { Game, Playtypes, integer, UserGameStats, ClassDelta, IDStrings } from " import { GameClasses } from "tachi-common/js/game-classes"; import deepmerge from "deepmerge"; import { KtLogger } from "../../../logger/logger"; -import { - CalculateGitadoraColour, - CalculateJubeatColour, - CalculateSDVXClass, -} from "./builtin-class-handlers"; +import { CalculateGitadoraColour, CalculateSDVXClass } from "./builtin-class-handlers"; import { ReturnClassIfGreater } from "../../../../utils/class"; import { RedisPub } from "../../../../external/redis/redis-IPC"; import { ClassHandler, ScoreClasses } from "./types"; @@ -37,12 +33,12 @@ const STATIC_CLASS_HANDLERS: ClassHandlerMap = { Gita: CalculateGitadoraColour, Dora: CalculateGitadoraColour, }, - jubeat: { - Single: CalculateJubeatColour, - }, + // jubeat: { + // Single: CalculateJubeatColour, + // }, maimai: null, museca: null, - popn: null, + // popn: null, sdvx: { Single: CalculateSDVXClass, }, diff --git a/server/src/lib/score-import/framework/user-game-stats/rating.ts b/server/src/lib/score-import/framework/user-game-stats/rating.ts index 8d8cfef05..aa37ed410 100644 --- a/server/src/lib/score-import/framework/user-game-stats/rating.ts +++ b/server/src/lib/score-import/framework/user-game-stats/rating.ts @@ -117,9 +117,9 @@ const RatingFunctions: RatingFunctions = { naiveRating: await LazyMeanN("rating", 20)(g, p, u), }), }, - popn: { - "9B": async () => ({}), - }, + // popn: { + // "9B": async () => ({}), + // }, museca: { Single: async (g, p, u) => ({ ktRating: await LazyMeanN("ktRating", 20)(g, p, u), @@ -130,11 +130,11 @@ const RatingFunctions: RatingFunctions = { ktRating: await LazyMeanN("ktRating", 20)(g, p, u), }), }, - jubeat: { - Single: async (g, p, u, l) => ({ - jubility: await CalculateJubility(g, p, u, l), - }), - }, + // jubeat: { + // Single: async (g, p, u, l) => ({ + // jubility: await CalculateJubility(g, p, u, l), + // }), + // }, }; export function CalculateRatings( @@ -188,43 +188,43 @@ async function CalculateGitadoraSkill( return skill; } -async function CalculateJubility( - game: Game, - playtype: Playtypes[Game], - userID: integer, - logger: KtLogger -): Promise { - const hotCharts = await db.charts.jubeat.find( - { "flags.HOT N-1": true }, - { projection: { chartID: 1 } } - ); +// async function CalculateJubility( +// game: Game, +// playtype: Playtypes[Game], +// userID: integer, +// logger: KtLogger +// ): Promise { +// const hotCharts = await db.charts.jubeat.find( +// { "flags.HOT N-1": true }, +// { projection: { chartID: 1 } } +// ); - const hotChartIDs = hotCharts.map((e) => e.chartID); +// const hotChartIDs = hotCharts.map((e) => e.chartID); - const [bestHotScores, bestScores] = await Promise.all([ - db["personal-bests"].find( - { userID, chartID: { $in: hotChartIDs } }, - { - sort: { "calculatedData.jubility": -1 }, - limit: 25, - projection: { "calculatedData.jubility": 1 }, - } - ), - // @inefficient - // see gitadoraskillcalc - db["personal-bests"].find( - { userID, chartID: { $nin: hotChartIDs } }, - { - sort: { "calculatedData.jubility": -1 }, - limit: 25, - projection: { "calculatedData.jubility": 1 }, - } - ), - ]); +// const [bestHotScores, bestScores] = await Promise.all([ +// db["personal-bests"].find( +// { userID, chartID: { $in: hotChartIDs } }, +// { +// sort: { "calculatedData.jubility": -1 }, +// limit: 25, +// projection: { "calculatedData.jubility": 1 }, +// } +// ), +// // @inefficient +// // see gitadoraskillcalc +// db["personal-bests"].find( +// { userID, chartID: { $nin: hotChartIDs } }, +// { +// sort: { "calculatedData.jubility": -1 }, +// limit: 25, +// projection: { "calculatedData.jubility": 1 }, +// } +// ), +// ]); - let skill = 0; - skill += bestHotScores.reduce((a, r) => a + r.calculatedData.jubility!, 0); - skill += bestScores.reduce((a, r) => a + r.calculatedData.jubility!, 0); +// let skill = 0; +// skill += bestHotScores.reduce((a, r) => a + r.calculatedData.jubility!, 0); +// skill += bestScores.reduce((a, r) => a + r.calculatedData.jubility!, 0); - return skill; -} +// return skill; +// } diff --git a/server/src/lib/score-import/import-types/common/api-kai/traverse-api.ts b/server/src/lib/score-import/import-types/common/api-kai/traverse-api.ts index 68a52bf41..ad5d2d515 100644 --- a/server/src/lib/score-import/import-types/common/api-kai/traverse-api.ts +++ b/server/src/lib/score-import/import-types/common/api-kai/traverse-api.ts @@ -41,7 +41,7 @@ export async function* TraverseKaiAPI( const res = await fetch(url, { headers: { Authorization: `Bearer ${token}`, - "User-Agent": `${CONF_INFO.NAME}/${VERSION_STR}`, + "User-Agent": `${CONF_INFO.name}/${VERSION_STR}`, }, }); diff --git a/server/src/main.ts b/server/src/main.ts index 54ebe4028..5b1c461e2 100644 --- a/server/src/main.ts +++ b/server/src/main.ts @@ -6,7 +6,7 @@ import { FormatVersion } from "./lib/constants/version"; const logger = CreateLogCtx(__filename); -logger.info(`Booting ${CONF_INFO.NAME} - ${FormatVersion()} [ENV: ${process.env.NODE_ENV}]`); +logger.info(`Booting ${CONF_INFO.name} - ${FormatVersion()} [ENV: ${process.env.NODE_ENV}]`); logger.info(`Log level is set to ${LOG_LEVEL}.`); server.listen(PORT); diff --git a/server/src/server/router/api/v1/import/router.ts b/server/src/server/router/api/v1/import/router.ts index 10e68b327..dceb11bd1 100644 --- a/server/src/server/router/api/v1/import/router.ts +++ b/server/src/server/router/api/v1/import/router.ts @@ -15,7 +15,7 @@ import ParseBatchManual from "../../../../../lib/score-import/import-types/file/ import { ParseSolidStateXML } from "../../../../../lib/score-import/import-types/file/solid-state-squad/parser"; import { ParseMerIIDX } from "../../../../../lib/score-import/import-types/file/mer-iidx/parser"; import ParsePLIIIDXCSV from "../../../../../lib/score-import/import-types/file/pli-iidx-csv/parser"; -import { RequireKamaitachi } from "../../../../middleware/type-require"; +import { CONF_INFO } from "../../../../../lib/setup/config"; const logger = CreateLogCtx(__filename); @@ -34,11 +34,10 @@ const ParseMultipartScoredata = CreateMulterSingleUploadMiddleware( router.post( "/file", RequireLoggedInSession, - RequireKamaitachi, // This is only useful for Kamaitachi, so. ParseMultipartScoredata, prValidate( { - importType: Prudence.isIn(fileImportTypes), + importType: Prudence.isIn(CONF_INFO.supportedImportTypes), }, {}, { allowExcessKeys: true } diff --git a/server/src/utils/misc.ts b/server/src/utils/misc.ts index f8db1efcc..783519ff6 100644 --- a/server/src/utils/misc.ts +++ b/server/src/utils/misc.ts @@ -62,7 +62,7 @@ export function HasOwnProperty(obj: T, key: string | number | symbol): key is } export function IsValidGame(str: string): str is Game { - return !!CONF_INFO.SUPPORTED_GAMES.includes(str as Game); + return !!CONF_INFO.supportedGames.includes(str as Game); } export function IsValidPlaytype(game: Game, str: string): str is Playtypes[Game] {