From 466760f891b86632e570a16bf75488ccf217274c Mon Sep 17 00:00:00 2001 From: zkldi Date: Thu, 22 Apr 2021 16:20:29 +0100 Subject: [PATCH] Drop BMS 5K support --- server/pnpm-lock.yaml | 6 +- server/src/db/schemas.ts | 39 +++++++++++-- .../__KT_DATABASE_MIGRATION/charts-iidx.ts | 56 +++++++++++++++++++ server/src/scripts/validate-database.ts | 7 +++ 4 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 server/src/scripts/__KT_DATABASE_MIGRATION/charts-iidx.ts diff --git a/server/pnpm-lock.yaml b/server/pnpm-lock.yaml index c88f88730..261317f0a 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/a024af3d674dbb0b707e20d2f02ae8b68af0a162 + kamaitachi-common: github.com/zkldi/Kamaitachi-common/814aebf65f12377e20441bcb420dabfbd628eb78 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/a024af3d674dbb0b707e20d2f02ae8b68af0a162: - resolution: {tarball: https://codeload.github.com/zkldi/Kamaitachi-common/tar.gz/a024af3d674dbb0b707e20d2f02ae8b68af0a162} + github.com/zkldi/Kamaitachi-common/814aebf65f12377e20441bcb420dabfbd628eb78: + resolution: {tarball: https://codeload.github.com/zkldi/Kamaitachi-common/tar.gz/814aebf65f12377e20441bcb420dabfbd628eb78} name: kamaitachi-common version: 0.1.0 dependencies: diff --git a/server/src/db/schemas.ts b/server/src/db/schemas.ts index c44df3de4..0ba5fc540 100644 --- a/server/src/db/schemas.ts +++ b/server/src/db/schemas.ts @@ -6,6 +6,8 @@ import { lamps, validHitData, validHitMeta, + validDifficulties, + validPlaytypes, } from "kamaitachi-common/js/config"; import p, { PrudenceOptions, PrudenceSchema, ValidationFunction, ValidSchemaValue } from "prudence"; import { RevaluedObject } from "../types"; @@ -272,10 +274,6 @@ export const PRUDENCE_SCORE_SCHEMAS: ScoreSchemas = { random: p.optional(DoublePlayTwinRandomTuple), }, }), - "5K": deepmerge(PR_SCORE_BMS_7K, { - playtype: p.equalTo("5K"), - scoreMeta: {}, - }), }, chunithm: { Single: deepmerge(CreatePRScore("chunithm", "Single"), { @@ -325,13 +323,44 @@ export const PRUDENCE_SCORE_SCHEMAS: ScoreSchemas = { }, }; +const PRUDENCE_CHART_BASE: PrudenceSchema = { + chartID: "string", + rgcID: "?string", + songID: p.isPositiveInteger, + level: "string", + levelNum: p.isPositive, + length: "?string", + bpmString: "?string", + isRemoved: "boolean", +}; + +function CreatePrChart(game: Game, flags: string[], data: PrudenceSchema) { + return deepmerge(PRUDENCE_CHART_BASE, { + difficulty: p.isIn(validDifficulties[game]), + playtype: p.isIn(validPlaytypes[game]), + flags: Object.fromEntries(flags.map((e) => [e, "boolean"])), + data, + }); +} + +export const PRUDENCE_CHART_SCHEMAS: Record = { + iidx: CreatePrChart("iidx", ["IN BASE GAME", "OMNIMIX", "N-1"], { + notecount: p.isPositiveInteger, + inGameID: "string", + inGameINTID: p.and(p.isPositiveInteger, (self, parent) => self === Number(parent.inGameID)), + }), + bms: CreatePrChart("bms", [], {}), + chunithm: CreatePrChart("chunithm"), +}; + /** * Schemas that are "static", i.e. the content of the document * does not depend on fields in the document (such as score docs) * being different depending on the score.game field. */ -export const STATIC_SCHEMAS: Partial> = { +export const STATIC_SCHEMAS: Partial, PrudenceSchema>> = { users: PRUDENCE_PRIVATE_USER, "iidx-bpi-data": PRUDENCE_IIDX_BPI_DATA, counters: PRUDENCE_COUNTER, + charts: PRUDENCE_CHART_SCHEMAS, }; diff --git a/server/src/scripts/__KT_DATABASE_MIGRATION/charts-iidx.ts b/server/src/scripts/__KT_DATABASE_MIGRATION/charts-iidx.ts new file mode 100644 index 000000000..46c1b0034 --- /dev/null +++ b/server/src/scripts/__KT_DATABASE_MIGRATION/charts-iidx.ts @@ -0,0 +1,56 @@ +import { ChartDocument } from "kamaitachi-common"; +import db from "../../db/db"; +import { rootLogger } from "../../logger"; +import MigrateRecords from "./migrate"; + +function ConvertFn(c: any): ChartDocument<"iidx:SP" | "iidx:DP"> { + const newChartDoc: ChartDocument<"iidx:SP" | "iidx:DP"> = { + rgcID: null, + chartID: c.chartID, + difficulty: c.difficulty, + songID: c.id, + playtype: c.playtype, + levelNum: c.levelNum, + isRemoved: false, + level: c.level, + length: c.length, + bpmString: "", // sentinel + flags: { + "IN BASE GAME": c.flags["IN BASE GAME"], + OMNIMIX: c.flags.OMNIMIX, + "N-1": c.flags["N-1"], + }, + data: { + inGameID: c.internals.inGameID, + inGameINTID: c.internals.inGameINTID, + notecount: c.notedata.notecount, + }, + }; + + if (typeof c.length === "number") { + let m = c.length % 60_000; + let s = c.length - m * 60_000; + + newChartDoc.length = `${m}:${s}`; + } + + if (c.bpmMin && c.bpmMax) { + if (c.monoBPM) { + newChartDoc.bpmString = c.bpmMin; + } else { + newChartDoc.bpmString = `${c.bpmMin}-${c.bpmMax}`; + } + } + + if (newChartDoc.length === null) { + rootLogger.warn(`Length of chart ${newChartDoc.chartID} is null, continuing anyway?`); + } + + return newChartDoc; +} + +(async () => { + await MigrateRecords(db.charts.iidx, "charts-iidx", ConvertFn); + + process.exit(0); +})(); diff --git a/server/src/scripts/validate-database.ts b/server/src/scripts/validate-database.ts index e033b5f16..7d7c90267 100644 --- a/server/src/scripts/validate-database.ts +++ b/server/src/scripts/validate-database.ts @@ -125,5 +125,12 @@ async function ValidateScores(): Promise { // process.exit(1); } +async function ValidateCharts(): Promise { + for (const game of supportedGames) { + let col = db.charts[game]; + let schema = STATIC_SCHEMAS.charts[game]; + } +} + // ValidateStaticSchemas(); ValidateScores();