Merge pull request #570 from TNG-dev/zkldi/issue-568

This commit is contained in:
zkldi
2021-12-08 23:58:39 +00:00
committed by GitHub
2 changed files with 51 additions and 2 deletions
@@ -0,0 +1,51 @@
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) {
(async () => {
let i = 0;
db.scores
.find({ game: "iidx" })
// @ts-expect-error dumb
.each(async (oldScore, { pause, resume }) => {
pause();
const chart = (await db.charts.iidx.findOne({
chartID: oldScore.chartID,
})) as ChartDocument<"iidx:SP">;
if (!chart) {
logger.severe(`Chart ${oldScore.chartID} has no chart?`);
return resume();
}
const percent = (100 * oldScore.scoreData.score) / (chart.data.notecount * 2);
if (Math.abs(percent - oldScore.scoreData.percent) > 0.00001) {
const newScore = JSON.parse(JSON.stringify(oldScore));
newScore.scoreData.percent = percent;
newScore.scoreData.grade = GetGradeFromPercent(
"iidx",
oldScore.playtype,
percent
);
newScore.scoreData.gradeIndex = GetGamePTConfig(
"iidx",
oldScore.playtype
).grades.indexOf(newScore.scoreData.grade);
await UpdateScore(oldScore, newScore);
i++;
}
resume();
})
.then(() => logger.info(`Fixed ${i} bad scores.`));
})();
}
@@ -54,8 +54,6 @@ export default async function UpdateScore(oldScore: ScoreDocument, newScore: Sco
const logger = rootLogger.child({
context: ["Update Score", oldScore.scoreID, newScore.scoreID, FormatUserDoc(user)],
oldScore,
newScore,
}) as KtLogger;
logger.info("Received Update Score request.");