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 { function dateInNDays(n: number): number {
let today = new Date(); //@ts-ignore
today.setDate(today.getDate() + n); return new Date(Date.now() + 1000 * 60 * 60 * 24 * n);
return Date.parse(today.toString());
} }
export enum AnswerType { export enum AnswerType {

View File

@ -5,6 +5,8 @@ import { Db } from "mongodb";
import { authRoute } from "../security/token"; import { authRoute } from "../security/token";
import { SM2_DEF_EASINESS } from "../config";
import { userFromSession } from "../utils/user"; import { userFromSession } from "../utils/user";
import { IUser, IUserDBModel } from "../models/user"; import { IUser, IUserDBModel } from "../models/user";
@ -205,6 +207,18 @@ userRouter.post("/lastReview", async (req: LRequest, res) => {
// user object back into the database. // user object back into the database.
Object.keys(req.body.sm2).forEach((id: string) => { Object.keys(req.body.sm2).forEach((id: string) => {
const vocabId = parseInt(id); 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]; const correct: boolean = req.body.sm2[id];
let vocab_sm2: ISchedulingData = Object.assign({}, let vocab_sm2: ISchedulingData = Object.assign({},
user.vocabMetadata[vocabId]); user.vocabMetadata[vocabId]);
@ -297,36 +311,39 @@ userRouter.post("/level/:id", async (req: LRequest, res) => {
} else { } else {
// The level is new to the user // The level is new to the user
// Is the new level higher than the "highest" already completed level? // Is the new level higher than the "highest" already completed level?
let update = { // let update = {
levels: user.levels.concat(id), // levels: user.levels.concat(id),
}; // };
if (id > Math.max(...user.levels)) { // if (id > Math.max(...user.levels)) {
// TODO: if (!level) // // TODO: if (!level)
const level = await db.collection("levels").findOne({ // const level = await db.collection("levels").findOne({
level: id, // level: id,
}); // });
// Convert the level's vocabulary to SM2 metadata // // Convert the level's vocabulary to SM2 metadata
let sm2: { [id: number]: ISchedulingData } = {}; // let sm2: { [id: number]: ISchedulingData } = {};
level.vocab.forEach((id: number) => { // level.vocab.forEach((id: number) => {
sm2[id] = { // sm2[id] = {
easiness: 1.3, // easiness: 1.3,
consecutiveCorrectAnswers: 0, // consecutiveCorrectAnswers: 0,
nextDueDate: Date.parse((new Date()).toString()), // nextDueDate: Date.parse((new Date()).toString()),
}; // };
}); // });
const newVocabMetadata = Object.assign({}, user.vocabMetadata, sm2); // const newVocabMetadata = Object.assign({}, user.vocabMetadata, sm2);
// Also update the lastLevel attribute // // Also update the lastLevel attribute
Object.assign(update, { // Object.assign(update, {
lastLevel: id, // lastLevel: id,
vocabMetadata: newVocabMetadata, // vocabMetadata: newVocabMetadata,
}); // });
} // }
await db.collection("users").updateOne({ await db.collection("users").updateOne({
username: user.username, 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"> <Typography variant="subheading" component="p">
<b>1. Person Präsens:</b> {vData.praesens} <b>1. Person Präsens:</b> {vData.praesens}
</Typography> </Typography>
<Typography variant="subheading" component="p">
<b>1. Person Perfekt:</b> {vData.perfekt}
</Typography>
</div>; </div>;
case VocabType.ADJEKTIV: case VocabType.ADJEKTIV:
const aData = vocab.latin as IAdjektivData; const aData = vocab.latin as IAdjektivData;

View File

@ -128,12 +128,6 @@ export function vocabToReviewCard(vocab: IVocab): IReviewCard[] {
answers: [vData.praesens], answers: [vData.praesens],
qtype: ReviewQType.VERB_PRAESENS, qtype: ReviewQType.VERB_PRAESENS,
id: vocab.id, id: vocab.id,
}, {
// Latin -> Perfekt
question: vData.grundform,
answers: [vData.perfekt],
qtype: ReviewQType.VERB_PERFEKT,
id: vocab.id,
}]; }];
case VocabType.ADJEKTIV: case VocabType.ADJEKTIV:
const aData = vocab.latin as IAdjektivData; const aData = vocab.latin as IAdjektivData;