Skip to content

Commit

Permalink
Feat/get retrievability (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Sep 12, 2024
1 parent 3c34707 commit c4552d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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)
}
}

0 comments on commit c4552d2

Please sign in to comment.