diff --git a/testdata/sample.yaml b/testdata/sample.yaml index bb5861c..f246727 100644 --- a/testdata/sample.yaml +++ b/testdata/sample.yaml @@ -25,10 +25,3 @@ users: uuid1: - {a: uuid0, pass: true} - {a: uuid2, pass: true} -cadence: -- 1d -- 3d -- 1w -- 3w -- 1m -- 3m diff --git a/testdata/tofugu.yaml b/testdata/tofugu.yaml index 0107f86..14f2e79 100644 --- a/testdata/tofugu.yaml +++ b/testdata/tofugu.yaml @@ -12,12 +12,3 @@ users: - hiragana - katakana history: {} -cadence: -- 1h -- 3h -- 1d -- 3d -- 1w -- 3w -- 1m -- 3m diff --git a/yamldb.go b/yamldb.go index 6c29d3e..d4f2767 100644 --- a/yamldb.go +++ b/yamldb.go @@ -13,7 +13,6 @@ type ( addr string Knowledge knowledge Users map[IDU]user - Cadence []duration } knowledge struct { Questions map[IDQ]Question @@ -35,8 +34,7 @@ func newYamlDB(p string) (yamlDB, error) { Questions: map[IDQ]Question{}, Answers: map[IDA]Answer{}, }, - Users: map[IDU]user{}, - Cadence: []duration{}, + Users: map[IDU]user{}, } if b, err := os.ReadFile(p); err != nil { return yamlDB{}, err @@ -79,20 +77,16 @@ func (db yamlDB) HistoryOf(user IDU) map[IDQ][]History { func (db yamlDB) Next(user IDU, q IDQ) time.Time { history := db.Users[user].History[q] - progress := 0 + last := db.lastTS(user, q) + log := make([]int, 0, len(history)) for i := range history { + v := 0 if history[i].Pass { - progress += 1 - } else { - progress -= 1 + v = 5 } + log = append(log, v) } - if progress < 0 { - progress = 0 - } else if progress > len(db.Cadence) { - return time.Now().Add(time.Hour * 24 * 365 * 10) - } - return db.lastTS(user, q).Add(time.Duration(db.Cadence[progress])) + return Next(last, log) } func (db yamlDB) Question(q IDQ) Question {