fix: Perfekt has not been removed

This commit is contained in:
Alexander Polynomdivision 2018-10-19 17:04:27 +02:00
parent 3293a876e3
commit 4ec41120dc
5 changed files with 45 additions and 37 deletions

View File

@ -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 {

View File

@ -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,
},
});
}

1
backend/src/config.ts Normal file
View File

@ -0,0 +1 @@
export const SM2_DEF_EASINESS = 1.5;

View File

@ -28,9 +28,6 @@ function vocabSpecificInformation(vocab: IVocab) {
<Typography variant="subheading" component="p">
<b>1. Person Präsens:</b> {vData.praesens}
</Typography>
<Typography variant="subheading" component="p">
<b>1. Person Perfekt:</b> {vData.perfekt}
</Typography>
</div>;
case VocabType.ADJEKTIV:
const aData = vocab.latin as IAdjektivData;

View File

@ -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;