-
Notifications
You must be signed in to change notification settings - Fork 4
/
card.go
73 lines (64 loc) · 1.29 KB
/
card.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import "time"
type (
Status int
Difficulty int
)
const (
New Status = iota
Learning
Review
Complete
)
const (
Again Difficulty = iota
Good
Easy
)
type Card struct {
Front string `json:"front"`
Back string `json:"back"`
Score int `json:"score"`
Interval int `json:"interval"`
EaseFactor float64 `json:"easeFactor"`
Status Status `json:"status"`
LastReviewed time.Time `json:"LastReviewed"`
}
func (c Card) FilterValue() string { return c.Front }
func (c Card) Title() string { return c.Front }
func (c Card) Description() string { return c.Back }
func NewCard(front, back string) *Card {
return &Card{
Front: front,
Back: back,
Score: 0,
Interval: 0,
Status: New,
}
}
func (c *Card) SM2(diff Difficulty) {
switch diff {
case Again:
c.Score = 0
c.Interval = 0
c.Status = Learning
case Good:
if c.Score == 0 {
c.Interval = 10
} else {
c.Interval = int(float64(c.Interval) * c.EaseFactor)
}
c.Status = Complete
c.Score++
case Easy:
if c.Score == 0 {
c.Interval = 20
} else {
c.Interval = int(float64(c.Interval) * c.EaseFactor)
}
c.Status = Complete
c.Score++
}
c.EaseFactor = c.EaseFactor + 0.1 - (5-float64(diff))*(0.08+(5-float64(diff))*0.02)
c.LastReviewed = time.Now()
}