refactor: MONOREPO
This commit is contained in:
35
frontend/src/algorithms/sm2/index.ts
Normal file
35
frontend/src/algorithms/sm2/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user