refactor charts to do versioning instead of songs

This commit is contained in:
zkldi
2021-04-27 17:01:38 +01:00
parent 25dbf836c4
commit e319f88da8
4 changed files with 32 additions and 7 deletions
+2 -2
View File
@@ -2,7 +2,7 @@ import monk from "monk";
import fs from "fs";
import path from "path";
import { Command } from "commander";
import CreateLogCtx from "../logger";
import CreateLogCtx from "../src/logger";
const program = new Command();
@@ -24,7 +24,7 @@ const ktBlackDB = monk(`${process.env.MONGO_BASE_URL}/ktblackdb`);
logger.info(`Fetched ${data.length} documents, Writing...`);
fs.writeFileSync(
path.join(__dirname, `../test-utils/test-data/kamaitachi/ktblack-${collection}.json`),
path.join(__dirname, `../src/test-utils/test-data/kamaitachi/ktblack-${collection}.json`),
JSON.stringify(data)
);
@@ -21,6 +21,7 @@ async function LoadKTBlackIIDXData() {
await db.charts.iidx.remove({});
await db.charts.iidx.insert(charts);
}
// reset DB handles the post-stuff
t.test("POST /internal-api/import/file", async (t) => {
@@ -3,6 +3,10 @@
import { Difficulties, Game, integer, Playtypes, IDStrings } from "kamaitachi-common";
import db from "../../db/db";
/**
* Find chart with PlaytypeDifficulty. This only finds charts that have `isPrimary` set to true.
* If you want to find charts that are not primary, you need to use PTDFVersion.
*/
export function FindChartWithPTDF<
G extends Game = Game,
P extends Playtypes[G] = Playtypes[G],
@@ -12,5 +16,23 @@ export function FindChartWithPTDF<
songID: songID,
playtype: playtype,
difficulty: difficulty,
isPrimary: true,
});
}
/**
* Find chart with Playtype, Difficulty and a given version. This does not necessarily return a chart that has
* `isPrimary` set.
*/
export function FindChartWithPTDFVersion<
G extends Game = Game,
P extends Playtypes[G] = Playtypes[G],
I extends IDStrings = IDStrings
>(game: G, songID: integer, playtype: P, difficulty: Difficulties[I], version: string) {
return db.charts[game].findOne({
songID: songID,
playtype: playtype,
difficulty: difficulty,
versions: version,
});
}
@@ -1,7 +1,8 @@
import { config, ESDCore, Lamps, AnySongDocument, ChartDocument } from "kamaitachi-common";
import { Logger } from "winston";
import { DryScore, ConverterFunction, ConverterFnReturn } from "../../../../types";
import { FindChartWithPTDF } from "../../../database-lookup/chart-ptdf";
import { FindChartWithPTDFVersion } from "../../../database-lookup/chart-ptdf";
import { FindSongOnTitle } from "../../../database-lookup/song-title";
import {
KTDataNotFoundFailure,
InternalFailure,
@@ -35,7 +36,7 @@ async function EamScoreConverter(
isLegacyLeggendaria: boolean,
logger: Logger
) {
const HUMANISED_CHART_TITLE = `${ktchiSong.title} (${context.playtype} ${eamScore.difficulty})`;
const HUMANISED_CHART_TITLE = `${ktchiSong.title} (${context.playtype} ${eamScore.difficulty} [v${context.importVersion}])`;
if (!eamScore.level) {
// charts that dont exist in the format have a level of 0
return null;
@@ -51,11 +52,12 @@ async function EamScoreConverter(
return null;
}
let ktchiChart = (await FindChartWithPTDF(
let ktchiChart = (await FindChartWithPTDFVersion(
"iidx",
ktchiSong.id,
context.playtype,
eamScore.difficulty
eamScore.difficulty,
context.importVersion
)) as ChartDocument<"iidx:SP" | "iidx:DP">;
if (!ktchiChart) {
@@ -234,7 +236,7 @@ const ConverterFn: ConverterFunction<IIDXEamusementCSVData, IIDXEamusementCSVCon
}
}
let ktchiSong = await FindSongOnTitleVersion("iidx", data.title, context.importVersion);
let ktchiSong = await FindSongOnTitle("iidx", data.title);
if (!ktchiSong) {
return new KTDataNotFoundFailure(