Skip to content

Enhance Spaced Repetition Algorithm with SM-2 Implementation #123

Description

@Suraj-kumar00

Enhance Spaced Repetition Algorithm with SM-2 Implementation

Description
The current spaced repetition system in src/components/study/StudyMode.tsx uses a basic implementation that updates nextReview dates based on difficulty ratings. This should be enhanced with a proper SM-2 algorithm for more effective learning scheduling.

Current Implementation
In StudyMode.tsx, the difficulty tracking updates the flashcard's nextReview field, but:

  • The interval calculation is basic (not following SM-2 formula)
  • repetitions count is not properly utilized
  • No ease factor tracking
  • Failed cards are not rescheduled optimally

What Needs to Be Done

1. Implement SM-2 Algorithm

Create a utility at src/lib/utils/spaced-repetition.ts:

  • Calculate intervals based on: quality (0-5), repetitions, ease factor
  • Formula: interval = previousInterval * easeFactor
  • Ease factor adjustment based on response quality
  • Reset to interval 1 on failure

2. Update Database Schema

Add to Prisma Flashcard model:

  • easeFactor (Float, default 2.5)
  • interval (Int, default 0)
  • Update repetitions usage

3. Update Study Mode

  • Apply SM-2 calculations when user rates difficulty
  • Show next review date to user
  • Add "Due for Review" filter to deck view
  • Display mastery level per card (based on ease factor)

4. Study Analytics

  • Track study streaks
  • Show retention rate over time
  • Daily review count vs. due cards
  • Export study statistics

Files to Create/Modify

  • Create: src/lib/utils/spaced-repetition.ts — SM-2 algorithm
  • Modify: prisma/schema.prisma — Add easeFactor, interval fields
  • Modify: src/components/study/StudyMode.tsx — Apply SM-2
  • Modify: src/app/api/study/record/route.ts — Store SM-2 data

Acceptance Criteria

  • SM-2 algorithm implemented and tested
  • Database schema updated with new fields
  • Study mode uses SM-2 for scheduling
  • Next review date shown to user
  • Due cards highlighted in deck view
  • Study analytics/stats page

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeatureNew functionality being added

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions