Files
Momento/memento-note/lib/flashcards/sm2.ts
Antigravity 36336e6b0d
Some checks failed
CI / Lint, Test & Build (push) Failing after 32s
CI / Deploy production (on server) (push) Has been skipped
feat(flashcards): révision SM-2, génération IA et page /revision
Livre US-FLASHCARDS avec decks, session de révision, stats et migration Prisma. Finalise le Web Clipper (i18n 15 langues) et corrige les erreurs ESLint bloquant la CI.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 19:22:20 +00:00

40 lines
902 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export type Sm2Grade = 1 | 2 | 3 | 4
export interface Sm2State {
easinessFactor: number
interval: number
}
export interface Sm2UpdateResult extends Sm2State {
nextReviewAt: Date
}
/** SM-2 update per US-FLASHCARDS spec (grades 14). */
export function computeSm2Update(
grade: number,
previous: Sm2State,
): Sm2UpdateResult {
const g = Math.min(4, Math.max(1, Math.round(grade))) as Sm2Grade
const ef = previous.easinessFactor
const newEF = Math.max(
1.3,
ef + 0.1 - (5 - g) * (0.08 + (5 - g) * 0.02),
)
const nextInterval =
g <= 2 ? 1 : Math.max(1, Math.round(previous.interval * newEF))
const nextReviewAt = new Date()
nextReviewAt.setDate(nextReviewAt.getDate() + nextInterval)
return {
easinessFactor: newEF,
interval: nextInterval,
nextReviewAt,
}
}
export function isCardMastered(interval: number): boolean {
return interval >= 21
}