This repository has been archived on 2022-03-12. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Lateinicus/frontend/src/algorithms/sm2/index.ts
Alexander Polynomdivision 909149fdc7 refactor: MONOREPO
2018-09-20 17:38:12 +02:00

36 lines
961 B
TypeScript

import { dayInNDays } from "../../utils/date";
export interface ISchedulingData {
easiness: number;
consecutiveCorrectAnswers: number;
nextDueDate: number;
};
export enum AnswerType {
CORRECT,
WRONG,
};
function performanceRating(answer: AnswerType): number {
switch (answer) {
case AnswerType.WRONG:
return 1;
case AnswerType.CORRECT:
return 4;
}
}
export function updateSchedulingData(data: ISchedulingData, answer: AnswerType): ISchedulingData {
const perfRating = performanceRating(answer);
data.easiness += -0.8 + 0.28 * perfRating + 0.02 * Math.pow(perfRating, 2);
data.consecutiveCorrectAnswers = answer === AnswerType.CORRECT ? (
data.consecutiveCorrectAnswers + 1
) : 0;
data.nextDueDate = answer === AnswerType.CORRECT ? (
dayInNDays(6 * Math.pow(data.easiness, data.consecutiveCorrectAnswers - 1))
) : dayInNDays(1);
return data;
}