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

Feat/get retrievability #24

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions fsrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ func (f *FSRS) Repeat(card Card, now time.Time) RecordLog {
func (f *FSRS) Next(card Card, now time.Time, grade Rating) SchedulingInfo {
return f.scheduler(card, now).Review(grade)
}

func (f *FSRS) GetRetrievability(card Card, now time.Time) float64 {
if card.State == New {
return 0
} else {
elapsedDays := now.Sub(card.LastReview).Hours() / 24
retrievability := f.Parameters.forgettingCurve(elapsedDays, card.Stability)
return retrievability
}
}
17 changes: 17 additions & 0 deletions fsrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,20 @@ func TestLongTermScheduler(t *testing.T) {
t.Errorf("excepted:%v, got:%v", wantDHistory, dHistory)
}
}

func TestGetRetrievability(t *testing.T) {
retrievabilityList := []float64{}
fsrs := NewFSRS(DefaultParam())
card := NewCard()
now := time.Date(2022, 11, 29, 12, 30, 0, 0, time.UTC)
retrievabilityList = append(retrievabilityList, roundFloat(fsrs.GetRetrievability(card, now), 4))
for i := 0; i < 3; i++ {
card = fsrs.Next(card, now, Good).Card
now = card.Due
retrievabilityList = append(retrievabilityList, roundFloat(fsrs.GetRetrievability(card, now), 4))
}
wantRetrievabilityList := []float64{0, 0.9997, 0.9036, 0.9017}
if !reflect.DeepEqual(retrievabilityList, wantRetrievabilityList) {
t.Errorf("excepted:%v, got:%v", wantRetrievabilityList, retrievabilityList)
}
}
Loading