From 8babacbeeef0648eded65bbfcc02cbc0d3d17d59 Mon Sep 17 00:00:00 2001 From: Jarrett Ye Date: Thu, 12 Sep 2024 14:08:31 +0800 Subject: [PATCH 1/2] Feat/get retrievability --- fsrs.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fsrs.go b/fsrs.go index 8ae0e37..bad4760 100644 --- a/fsrs.go +++ b/fsrs.go @@ -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 + } +} From 67be89085f89b656de3670dcac5a2864688647e0 Mon Sep 17 00:00:00 2001 From: Jarrett Ye Date: Thu, 12 Sep 2024 14:14:44 +0800 Subject: [PATCH 2/2] add unit test --- fsrs_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fsrs_test.go b/fsrs_test.go index f4459f9..8ebbd61 100644 --- a/fsrs_test.go +++ b/fsrs_test.go @@ -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) + } +}