diff --git a/backend/src/algorithms/sm2/index.ts b/backend/src/algorithms/sm2/index.ts index 5aa8050..d9dcec1 100644 --- a/backend/src/algorithms/sm2/index.ts +++ b/backend/src/algorithms/sm2/index.ts @@ -5,9 +5,8 @@ export interface ISchedulingData { }; function dateInNDays(n: number): number { - let today = new Date(); - today.setDate(today.getDate() + n); - return Date.parse(today.toString()); + //@ts-ignore + return new Date(Date.now() + 1000 * 60 * 60 * 24 * n); } export enum AnswerType { diff --git a/backend/src/api/user.ts b/backend/src/api/user.ts index 7ebec19..43959c4 100644 --- a/backend/src/api/user.ts +++ b/backend/src/api/user.ts @@ -5,6 +5,8 @@ import { Db } from "mongodb"; import { authRoute } from "../security/token"; +import { SM2_DEF_EASINESS } from "../config"; + import { userFromSession } from "../utils/user"; import { IUser, IUserDBModel } from "../models/user"; @@ -205,6 +207,18 @@ userRouter.post("/lastReview", async (req: LRequest, res) => { // user object back into the database. Object.keys(req.body.sm2).forEach((id: string) => { const vocabId = parseInt(id); + + // Check if that vocabulary is already in the list of known vocabulary + if (Object.keys(user.vocabMetadata).indexOf(id) === -1) { + // Initialize the vocabulary item + user.vocabMetadata[vocabId] = { + easiness: SM2_DEF_EASINESS, + consecutiveCorrectAnswers: 0, + //@ts-ignore + nextDueDate: new Date(Date.now()), + }; + } + const correct: boolean = req.body.sm2[id]; let vocab_sm2: ISchedulingData = Object.assign({}, user.vocabMetadata[vocabId]); @@ -297,36 +311,39 @@ userRouter.post("/level/:id", async (req: LRequest, res) => { } else { // The level is new to the user // Is the new level higher than the "highest" already completed level? - let update = { - levels: user.levels.concat(id), - }; - if (id > Math.max(...user.levels)) { - // TODO: if (!level) - const level = await db.collection("levels").findOne({ - level: id, - }); + // let update = { + // levels: user.levels.concat(id), + // }; + // if (id > Math.max(...user.levels)) { + // // TODO: if (!level) + // const level = await db.collection("levels").findOne({ + // level: id, + // }); - // Convert the level's vocabulary to SM2 metadata - let sm2: { [id: number]: ISchedulingData } = {}; - level.vocab.forEach((id: number) => { - sm2[id] = { - easiness: 1.3, - consecutiveCorrectAnswers: 0, - nextDueDate: Date.parse((new Date()).toString()), - }; - }); - const newVocabMetadata = Object.assign({}, user.vocabMetadata, sm2); + // // Convert the level's vocabulary to SM2 metadata + // let sm2: { [id: number]: ISchedulingData } = {}; + // level.vocab.forEach((id: number) => { + // sm2[id] = { + // easiness: 1.3, + // consecutiveCorrectAnswers: 0, + // nextDueDate: Date.parse((new Date()).toString()), + // }; + // }); + // const newVocabMetadata = Object.assign({}, user.vocabMetadata, sm2); - // Also update the lastLevel attribute - Object.assign(update, { - lastLevel: id, - vocabMetadata: newVocabMetadata, - }); - } + // // Also update the lastLevel attribute + // Object.assign(update, { + // lastLevel: id, + // vocabMetadata: newVocabMetadata, + // }); + // } await db.collection("users").updateOne({ username: user.username, }, { - $set: update, + $set: { + levels: user.levels.concat(id), + lastLevel: id, + }, }); } diff --git a/backend/src/config.ts b/backend/src/config.ts new file mode 100644 index 0000000..606c4b2 --- /dev/null +++ b/backend/src/config.ts @@ -0,0 +1 @@ +export const SM2_DEF_EASINESS = 1.5; diff --git a/frontend/src/components/VocabularyData.tsx b/frontend/src/components/VocabularyData.tsx index 359fb4a..6d09b31 100644 --- a/frontend/src/components/VocabularyData.tsx +++ b/frontend/src/components/VocabularyData.tsx @@ -28,9 +28,6 @@ function vocabSpecificInformation(vocab: IVocab) { 1. Person Präsens: {vData.praesens} - - 1. Person Perfekt: {vData.perfekt} - ; case VocabType.ADJEKTIV: const aData = vocab.latin as IAdjektivData; diff --git a/frontend/src/models/vocab.ts b/frontend/src/models/vocab.ts index c28fc88..28f64a9 100644 --- a/frontend/src/models/vocab.ts +++ b/frontend/src/models/vocab.ts @@ -128,12 +128,6 @@ export function vocabToReviewCard(vocab: IVocab): IReviewCard[] { answers: [vData.praesens], qtype: ReviewQType.VERB_PRAESENS, id: vocab.id, - }, { - // Latin -> Perfekt - question: vData.grundform, - answers: [vData.perfekt], - qtype: ReviewQType.VERB_PERFEKT, - id: vocab.id, }]; case VocabType.ADJEKTIV: const aData = vocab.latin as IAdjektivData;