From f3e483937219129cb1cd612754fa6a19248e915e Mon Sep 17 00:00:00 2001 From: Gorbachev Egor <7gorbachevm@gmail.com> Date: Wed, 8 Nov 2023 13:55:15 +0700 Subject: [PATCH] Spaced repetitioin interval should reset to 0 if review session has been interrupted --- functions/services/review-card.test.ts | 19 +++++++++++++++++++ functions/services/review-card.ts | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/functions/services/review-card.test.ts b/functions/services/review-card.test.ts index 468b6518..25bb93b7 100644 --- a/functions/services/review-card.test.ts +++ b/functions/services/review-card.test.ts @@ -37,3 +37,22 @@ test("hit yes all the time", () => { 3600 * 24 * 1000 * 15.625, ]); }); + +test("forgetting resets interval", () => { + let date = DateTime.fromSQL("2021-05-20 10:00:00"); + + const { interval: newInterval1 } = reviewCard(date, 0.4, "correct"); + expect(newInterval1).toBe(1); + + const { interval: newInterval2 } = reviewCard(date, 1, "wrong"); + expect(newInterval2).toBe(0); + + const { interval: newInterval3 } = reviewCard(date, 0, "wrong"); + expect(newInterval3).toBe(0); + + const { interval: newInterval4 } = reviewCard(date, 0, "correct"); + expect(newInterval4).toBe(0.4); + + const { interval: newInterval5 } = reviewCard(date, 0.4, "correct"); + expect(newInterval5).toBe(1); +}); diff --git a/functions/services/review-card.ts b/functions/services/review-card.ts index 1d6be128..a823e388 100644 --- a/functions/services/review-card.ts +++ b/functions/services/review-card.ts @@ -17,9 +17,12 @@ export const reviewCard = ( const easeFactor = 2.5; if (reviewOutcome === "correct") { + if (interval === 0) { + interval = 0.16; + } interval *= easeFactor; } else if (reviewOutcome === "wrong") { - interval = 0.4; + interval = 0; } const nextReviewDate = now.plus({ day: interval });