Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compute retrievability for all states #122

Merged
merged 7 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions __tests__/FSRSV5.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ describe('FSRS V5 ', () => {

describe('get retrievability', () => {
const fsrs = new FSRS({})
test('return undefined for non-review cards', () => {
test('return 0.00% for new cards', () => {
const card = createEmptyCard()
const now = new Date()
const expected = undefined
const expected = "0.00%"
expect(fsrs.get_retrievability(card, now)).toBe(expected)
})

test('return retrievability percentage for review cards', () => {
const card = createEmptyCard('2023-12-01 04:00:00')
const sc = fsrs.repeat(card, '2023-12-01 04:05:00')
const r = [undefined, undefined, undefined, '90.26%']
const r_number = [undefined, undefined, undefined, 0.90260891]
const r = ['100.00%', '100.00%', '100.00%', '90.26%']
const r_number = [1, 1, 1, 0.90260891]
Grades.forEach((grade, index) => {
expect(fsrs.get_retrievability(sc[grade].card, sc[grade].card.due)).toBe(
r[index]
Expand Down
13 changes: 5 additions & 8 deletions src/fsrs/fsrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,13 @@ export class FSRS extends FSRSAlgorithm {
*/
get_retrievability<T extends boolean>(
card: CardInput | Card,
now: DateInput,
now?: DateInput,
format: T = true as T
): undefined | (T extends true ? string : number) {
): (T extends true ? string : number) {
const processedCard = TypeConvert.card(card)
now = TypeConvert.time(now)
if (processedCard.state !== State.Review) {
return undefined
}
const t = Math.max(now.diff(processedCard.last_review as Date, 'days'), 0)
const r = this.forgetting_curve(t, +processedCard.stability.toFixed(2))
now = now ? TypeConvert.time(now) : new Date()
const t = processedCard.state !== State.New ? Math.max(now.diff(processedCard.last_review as Date, 'days'), 0) : 0
const r = processedCard.state !== State.New ? this.forgetting_curve(t, +processedCard.stability.toFixed(2)) : 0
ishiko732 marked this conversation as resolved.
Show resolved Hide resolved
return (format ? `${(r * 100).toFixed(2)}%` : r) as T extends true
? string
: number
Expand Down