Class FSRS

Hierarchy (view full)

Constructors

Properties

_seed?: string
intervalModifier: number

Accessors

  • get interval_modifier(): number
  • Returns number

  • set seed(seed): void
  • Parameters

    • seed: string

    Returns void

Methods

  • If fuzzing is disabled or ivl is less than 2.5, it returns the original interval.

    Parameters

    • ivl: number

      The interval to be fuzzed.

    • elapsed_days: number

      t days since the last review

    Returns int

    • The fuzzed interval.
  • The formula used is : $$\min \lbrace \max \lbrace D_0,1 \rbrace,10\rbrace$$

    Parameters

    • difficulty: number

      $$D \in [1,10]$$

    Returns number

  • Type Parameters

    Parameters

    • card: Card | CardInput

      Card to be processed

    • now: DateInput

      Current time or scheduled time

    • reset_count: boolean = false

      Should the review count information(reps,lapses) be reset. (Optional)

    • OptionalafterHandler: ((recordLogItem: RecordLogItem) => R)

      Convert the result to another type. (Optional)

    Returns R

    const now = new Date();
    const f = fsrs();
    const emptyCard = createEmptyCard(now);
    const scheduling_cards = f.repeat(emptyCard, now);
    const { card, log } = scheduling_cards[Rating.Hard];
    const forgetCard = f.forget(card, new Date(), true);
    interface RepeatRecordLog {
    card: CardUnChecked; //see method: createEmptyCard
    log: RevLogUnchecked; //see method: fsrs.repeat()
    }

    function forgetAfterHandler(recordLogItem: RecordLogItem): RepeatRecordLog {
    return {
    card: {
    ...(recordLogItem.card as Card & { cid: string }),
    due: recordLogItem.card.due.getTime(),
    state: State[recordLogItem.card.state] as StateType,
    last_review: recordLogItem.card.last_review
    ? recordLogItem.card.last_review!.getTime()
    : null,
    },
    log: {
    ...recordLogItem.log,
    cid: (recordLogItem.card as Card & { cid: string }).cid,
    due: recordLogItem.log.due.getTime(),
    review: recordLogItem.log.review.getTime(),
    state: State[recordLogItem.log.state] as StateType,
    rating: Rating[recordLogItem.log.rating] as RatingType,
    },
    };
    }
    const now = new Date();
    const f = fsrs();
    const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard
    const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()
    const { card } = repeatFormAfterHandler[Rating.Hard];
    const forgetFromAfterHandler = f.forget(card, date_scheduler(now, 1, true), false, forgetAfterHandler);
  • The formula used is : $$R(t,S) = (1 + \text{FACTOR} \times \frac{t}{9 \cdot S})^{\text{DECAY}}$$

    Parameters

    • elapsed_days: number

      t days since the last review

    • stability: number

      Stability (interval when R=90%)

    Returns number

    r Retrievability (probability of recall)

  • Get the retrievability of the card

    Type Parameters

    • T extends boolean

    Parameters

    • card: Card | CardInput

      Card to be processed

    • Optionalnow: DateInput

      Current time or scheduled time

    • format: T = ...

      default:true , Convert the result to another type. (Optional)

    Returns T extends true
        ? string
        : number

    The retrievability of the card,if format is true, the result is a string, otherwise it is a number

  • The formula used is : $$D_0(G) = w_4 - e^{(G-1) \cdot w_5} + 1 $$ $$D_0 = \min \lbrace \max \lbrace D_0(G),1 \rbrace,10 \rbrace$$ where the $$D_0(1)=w_4$$ when the first rating is good.

    Parameters

    • g: Grade

      Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]

    Returns number

    Difficulty $$D \in [1,10]$$

  • The formula used is : $$ S_0(G) = w_{G-1}$$ $$S_0 = \max \lbrace S_0,0.1\rbrace $$

    Parameters

    • g: Grade

      Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]

    Returns number

    Stability (interval when R=90%)

  • The formula used is : $$w_7 \cdot \text{init} +(1 - w_7) \cdot \text{current}$$

    Parameters

    • init: number

      $$w_2 : D_0(3) = w_2 + (R-2) \cdot w_3= w_2$$

    • current: number

      $$D - w_6 \cdot (R - 2)$$

    Returns number

    difficulty

  • Display the collection of cards and logs for the card scheduled at the current time, after applying a specific grade rating.

    Type Parameters

    Parameters

    • card: Card | CardInput

      Card to be processed

    • now: DateInput

      Current time or scheduled time

    • grade: Grade

      Rating of the review (Again, Hard, Good, Easy)

    • OptionalafterHandler: ((recordLog: RecordLogItem) => R)

      Convert the result to another type. (Optional)

    Returns R

    const card: Card = createEmptyCard(new Date());
    const f = fsrs();
    const recordLogItem = f.next(card, new Date(), Rating.Again);
    interface RevLogUnchecked
    extends Omit<ReviewLog, "due" | "review" | "state" | "rating"> {
    cid: string;
    due: Date | number;
    state: StateType;
    review: Date | number;
    rating: RatingType;
    }

    interface NextRecordLog {
    card: CardUnChecked; //see method: createEmptyCard
    log: RevLogUnchecked;
    }

    function nextAfterHandler(recordLogItem: RecordLogItem) {
    const recordItem = {
    card: {
    ...(recordLogItem.card as Card & { cid: string }),
    due: recordLogItem.card.due.getTime(),
    state: State[recordLogItem.card.state] as StateType,
    last_review: recordLogItem.card.last_review
    ? recordLogItem.card.last_review!.getTime()
    : null,
    },
    log: {
    ...recordLogItem.log,
    cid: (recordLogItem.card as Card & { cid: string }).cid,
    due: recordLogItem.log.due.getTime(),
    review: recordLogItem.log.review.getTime(),
    state: State[recordLogItem.log.state] as StateType,
    rating: Rating[recordLogItem.log.rating] as RatingType,
    },
    };
    return recordItem
    }
    const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard
    const f = fsrs();
    const recordLogItem = f.repeat(card, new Date(), Rating.Again, nextAfterHandler);
  • The formula used is : $$\text{next}_d = D - w_6 \cdot (g - 3)$$ $$D^\prime(D,R) = w_7 \cdot D_0(4) +(1 - w_7) \cdot \text{next}_d$$

    Parameters

    • d: number

      Difficulty $$D \in [1,10]$$

    • g: Grade

      Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]

    Returns number

    $$\text{next}_D$$

  • The formula used is : $$S^\prime_f(D,S,R) = w_{11}\cdot D^{-w_{12}}\cdot ((S+1)^{w_{13}}-1) \cdot e^{w_{14}\cdot(1-R)}$$

    Parameters

    • d: number

      Difficulty D \in [1,10]

    • s: number

      Stability (interval when R=90%)

    • r: number

      Retrievability (probability of recall)

    Returns number

    S^\prime_f new stability after forgetting

  • The formula used is : $$S^\prime_r(D,S,R,G) = S\cdot(e^{w_8}\cdot (11-D)\cdot S^{-w_9}\cdot(e^{w_{10}\cdot(1-R)}-1)\cdot w_{15}(\text{if} G=2) \cdot w_{16}(\text{if} G=4)+1)$$

    Parameters

    • d: number

      Difficulty D \in [1,10]

    • s: number

      Stability (interval when R=90%)

    • r: number

      Retrievability (probability of recall)

    • g: Grade

      Grade (Rating[0.again,1.hard,2.good,3.easy])

    Returns number

    S^\prime_r new stability after recall

  • The formula used is : $$S^\prime_s(S,G) = S \cdot e^{w_{17} \cdot (G-3+w_{18})}$$

    Parameters

    • s: number

      Stability (interval when R=90%)

    • g: Grade

      Grade (Rating[0.again,1.hard,2.good,3.easy])

    Returns number

  • Display the collection of cards and logs for the four scenarios after scheduling the card at the current time.

    Type Parameters

    Parameters

    • card: Card | CardInput

      Card to be processed

    • now: DateInput

      Current time or scheduled time

    • OptionalafterHandler: ((recordLog: IPreview) => R)

      Convert the result to another type. (Optional)

        • (recordLog): R
        • Parameters

          Returns R

    Returns R

    const card: Card = createEmptyCard(new Date());
    const f = fsrs();
    const recordLog = f.repeat(card, new Date());
    interface RevLogUnchecked
    extends Omit<ReviewLog, "due" | "review" | "state" | "rating"> {
    cid: string;
    due: Date | number;
    state: StateType;
    review: Date | number;
    rating: RatingType;
    }

    interface RepeatRecordLog {
    card: CardUnChecked; //see method: createEmptyCard
    log: RevLogUnchecked;
    }

    function repeatAfterHandler(recordLog: RecordLog) {
    const record: { [key in Grade]: RepeatRecordLog } = {} as {
    [key in Grade]: RepeatRecordLog;
    };
    for (const grade of Grades) {
    record[grade] = {
    card: {
    ...(recordLog[grade].card as Card & { cid: string }),
    due: recordLog[grade].card.due.getTime(),
    state: State[recordLog[grade].card.state] as StateType,
    last_review: recordLog[grade].card.last_review
    ? recordLog[grade].card.last_review!.getTime()
    : null,
    },
    log: {
    ...recordLog[grade].log,
    cid: (recordLog[grade].card as Card & { cid: string }).cid,
    due: recordLog[grade].log.due.getTime(),
    review: recordLog[grade].log.review.getTime(),
    state: State[recordLog[grade].log.state] as StateType,
    rating: Rating[recordLog[grade].log.rating] as RatingType,
    },
    };
    }
    return record;
    }
    const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard
    const f = fsrs();
    const recordLog = f.repeat(card, new Date(), repeatAfterHandler);
  • Reschedules the current card and returns the rescheduled collections and reschedule item.

    Type Parameters

    Parameters

    • current_card: Card | CardInput

      The current card to be rescheduled.

    • reviews: FSRSHistory[] = []

      The array of FSRSHistory objects representing the reviews.

    • options: Partial<RescheduleOptions<T>> = {}

      The optional reschedule options.

    Returns IReschedule<T>

    • The rescheduled collections and reschedule item.
     const f = fsrs()
    const grades: Grade[] = [Rating.Good, Rating.Good, Rating.Good, Rating.Good]
    const reviews_at = [
    new Date(2024, 8, 13),
    new Date(2024, 8, 13),
    new Date(2024, 8, 17),
    new Date(2024, 8, 28),
    ]

    const reviews: FSRSHistory[] = []
    for (let i = 0; i < grades.length; i++) {
    reviews.push({
    rating: grades[i],
    review: reviews_at[i],
    })
    }

    const results_short = scheduler.reschedule(
    createEmptyCard(),
    reviews,
    {
    skipManual: false,
    }
    )
    console.log(results_short)
  • Type Parameters

    Parameters

    • card: Card | CardInput

      Card to be processed

    • log: ReviewLogInput

      last review log

    • OptionalafterHandler: ((prevCard: Card) => R)

      Convert the result to another type. (Optional)

        • (prevCard): R
        • Parameters

          Returns R

    Returns R

    const now = new Date();
    const f = fsrs();
    const emptyCardFormAfterHandler = createEmptyCard(now);
    const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now);
    const { card, log } = repeatFormAfterHandler[Rating.Hard];
    const rollbackFromAfterHandler = f.rollback(card, log);
    const now = new Date();
    const f = fsrs();
    const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard
    const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()
    const { card, log } = repeatFormAfterHandler[Rating.Hard];
    const rollbackFromAfterHandler = f.rollback(card, log, cardAfterHandler);