each user can define their cadence
parent
11af5f4d52
commit
ee8e51f281
4
sm2.go
4
sm2.go
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"time"
|
"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
|
n, ef, i := 0, 2.5, 1
|
||||||
for j := range history {
|
for j := range history {
|
||||||
n, ef, i = sm2Next(history[j], n, ef, i)
|
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.
|
// 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.
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ func TestSM2(t *testing.T) {
|
||||||
for name, d := range cases {
|
for name, d := range cases {
|
||||||
c := d
|
c := d
|
||||||
t.Run(name, func(t *testing.T) {
|
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)
|
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) {
|
if got != ts.Add(time.Duration(c.want)*time.Hour*24) {
|
||||||
t.Error(c.want, got)
|
t.Error(c.want, got)
|
||||||
|
|
|
||||||
13
yamldb.go
13
yamldb.go
|
|
@ -20,7 +20,8 @@ type (
|
||||||
Answers map[IDA]Answer
|
Answers map[IDA]Answer
|
||||||
}
|
}
|
||||||
user struct {
|
user struct {
|
||||||
Tags tags
|
Tags tags
|
||||||
|
Cadence duration
|
||||||
}
|
}
|
||||||
tags struct {
|
tags struct {
|
||||||
Assignments []IDT
|
Assignments []IDT
|
||||||
|
|
@ -94,7 +95,15 @@ func (db yamlDB) Next(user IDU, q IDQ) time.Time {
|
||||||
}
|
}
|
||||||
log = append(log, v)
|
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 {
|
func (db yamlDB) Question(q IDQ) Question {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue