From c53d2a82df984f091138e394995d63f4b63afcbc Mon Sep 17 00:00:00 2001 From: zkldi <20380519+zkldi@users.noreply.github.com> Date: Fri, 10 Dec 2021 13:33:31 +0000 Subject: [PATCH] Add a chunithm recalc script. --- .../single-use/recalc-chunithm-scores.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 server/scripts/single-use/recalc-chunithm-scores.ts diff --git a/server/scripts/single-use/recalc-chunithm-scores.ts b/server/scripts/single-use/recalc-chunithm-scores.ts new file mode 100644 index 000000000..84592f80d --- /dev/null +++ b/server/scripts/single-use/recalc-chunithm-scores.ts @@ -0,0 +1,49 @@ +import db from "external/mongo/db"; +import CreateLogCtx from "lib/logger/logger"; +import { GetGradeFromPercent } from "lib/score-import/framework/common/score-utils"; +import UpdateScore from "lib/score-mutation/update-score"; +import { ChartDocument, GetGamePTConfig } from "tachi-common"; + +const logger = CreateLogCtx(__filename); + +if (require.main === module) { + let i = 0; + db.scores + .find({ game: "chunithm", "scoreData.grade": "SS" }) + // @ts-expect-error dumb + .each(async (oldScore, { pause, resume }) => { + pause(); + + const chart = (await db.charts.chunithm.findOne({ + chartID: oldScore.chartID, + })) as ChartDocument<"chunithm:Single">; + + if (!chart) { + logger.severe(`Chart ${oldScore.chartID} has no chart?`); + return resume(); + } + + const newScore = JSON.parse(JSON.stringify(oldScore)); + + newScore.scoreData.grade = GetGradeFromPercent( + "chunithm", + oldScore.playtype, + oldScore.scoreData.percent + ); + + newScore.scoreData.gradeIndex = GetGamePTConfig( + "chunithm", + oldScore.playtype + ).grades.indexOf(newScore.scoreData.grade); + + await UpdateScore(oldScore, newScore); + + i++; + + resume(); + }) + .then(() => { + logger.info(`Fixed ${i} bad scores.`); + process.exit(0); + }); +}