Skip to content

Commit

Permalink
Make normalize sentence scores script user and sentence list specific
Browse files Browse the repository at this point in the history
Earlier, it used to take a lot of time.

Signed-off-by: Abhishek Kumar <abhi.kr.2100@gmail.com>
  • Loading branch information
abhi-kr-2100 committed Jun 16, 2024
1 parent 0d2fa28 commit 14f376c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion express-backend/src/scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,26 @@ switch (process.argv[2]) {
break;
}
case 'normalizeSentenceScores': {
const sentenceScores = await SentenceScore.find({});
if (process.argv.length !== 5) {
console.error(`Missing parameters: userId sentenceListId`);
process.exit(1);
}

const userId = new Types.ObjectId(process.argv[3]);
const sentenceListId = new Types.ObjectId(process.argv[4]);

const sentenceScores = await SentenceScore.find({
'sentence.sentenceList._id': sentenceListId,
'owner._id': userId,
});
await Promise.all(
sentenceScores.map(async (sentenceScore) => {
const lm = getLanguageModel(sentenceScore.sentence.textLanguageCode);
const words = lm.getWords(sentenceScore.sentence.text);
const wordScores = await WordScore.find({
'word.languageCode': sentenceScore.sentence.textLanguageCode,
'word.wordText': { $in: words },
'owner._id': userId,
});
const lowestScoredWord = wordScores.reduce((prev, curr) => {
return prev.score.easinessFactor < curr.score.easinessFactor
Expand Down

0 comments on commit 14f376c

Please sign in to comment.