which means we no longer need autocoerce

This commit is contained in:
zkldi
2021-04-28 22:40:15 +01:00
parent 938274dc7f
commit 28bdbbb279
-53
View File
@@ -1,53 +0,0 @@
import { ScoreDocument } from "..";
import { ICollection } from "monk";
export async function AutoCoerce(
collection: ICollection<ScoreDocument>,
scores: ScoreDocument[]
): Promise<ScoreDocument[]> {
let notPBsArr = [];
for (const s of scores) {
if (!s.isLampPB) {
notPBsArr.push({
userID: s.userID,
chartID: s.chartID,
isLampPB: true,
});
}
}
if (notPBsArr.length === 0) {
return scores;
}
let lampPBsArr = await collection.find({
$or: notPBsArr,
});
let lampPBs: Map<string, ScoreDocument> = new Map();
for (const score of lampPBsArr) {
lampPBs.set(`${score.userID}-${score.chartID}`, score);
}
for (const score of scores) {
if (!score.isLampPB) {
let lampPB = lampPBs.get(`${score.userID}-${score.chartID}`);
if (lampPB) {
score.scoreData.lamp = lampPB.scoreData.lamp;
score.scoreData.lampIndex = lampPB.scoreData.lampIndex;
score.calculatedData.lampRating = lampPB.calculatedData.lampRating;
// not too happy about this, this is a sign
// of something not properly being generalised.
if (score.game === "bms") {
score.calculatedData.rating = lampPB.calculatedData.rating;
}
score.isLampPB = true;
}
}
}
return scores;
}