diff --git a/sm2.go b/sm2.go index fba3e67..7dfad89 100644 --- a/sm2.go +++ b/sm2.go @@ -4,12 +4,12 @@ import ( "time" ) -func Next(ts time.Time, history []int) time.Time { +func SM2Next(ts time.Time, history []int, unit time.Duration) time.Time { n, ef, i := 0, 2.5, 1 for j := range history { n, ef, i = sm2Next(history[j], n, ef, i) } - return ts.Add(time.Duration(i) * time.Hour * 24) + return ts.Add(time.Duration(i) * unit) } // After all scheduled reviews are complete, SuperMemo asks the user to re-review any cards they marked with a grade less than 4 repeatedly until they give a grade ≥ 4. diff --git a/sm2_test.go b/sm2_test.go index b66f645..8121e83 100644 --- a/sm2_test.go +++ b/sm2_test.go @@ -44,7 +44,7 @@ func TestSM2(t *testing.T) { for name, d := range cases { c := d t.Run(name, func(t *testing.T) { - got := Next(ts, c.history) + got := SM2Next(ts, c.history, time.Hour*24) t.Logf("Next(\n\t%s, \n\t%+v) = \n\t%s", ts, c.history, got) if got != ts.Add(time.Duration(c.want)*time.Hour*24) { t.Error(c.want, got) diff --git a/yamldb.go b/yamldb.go index c07e754..be6a510 100644 --- a/yamldb.go +++ b/yamldb.go @@ -20,7 +20,8 @@ type ( Answers map[IDA]Answer } user struct { - Tags tags + Tags tags + Cadence duration } tags struct { Assignments []IDT @@ -94,7 +95,15 @@ func (db yamlDB) Next(user IDU, q IDQ) time.Time { } log = append(log, v) } - return Next(last, log) + return SM2Next(last, log, db.cadence(user)) +} + +func (db yamlDB) cadence(user IDU) time.Duration { + u := db.Users[user] + if u.Cadence == 0 { + return time.Hour * 24 + } + return time.Duration(u.Cadence) } func (db yamlDB) Question(q IDQ) Question {