-
Notifications
You must be signed in to change notification settings - Fork 0
/
outcome.go
69 lines (56 loc) · 1.24 KB
/
outcome.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
package meta
import (
"fmt"
"time"
)
type OutcomeMap map[Key]*Outcome
type Outcome struct {
base
target bool
}
func NewOutcomeFromPredict(p *Predict, now time.Time, target bool) *Outcome {
r := &Outcome{
base: p.base,
target: target,
}
r.next = now.UTC()
// For new cards, the outcome makes more sense to be instant.
if r.curr.IsZero() {
r.curr = now.UTC()
}
return r
}
func NewOutcomeFromStrings(strs ...string) *Outcome {
return &Outcome{
base: *newMetaFromStrings(strs...),
target: getParam(strs, 6) == "1",
}
}
func (r *Outcome) PredYesCount() int { return r.newCount(true, r.yesCount) }
func (r *Outcome) PredNoCount() int { return r.newCount(false, r.noCount) }
func (r *Outcome) PredStreak() int {
if r.target && r.streak >= 0 {
return r.streak + 1
} else if !r.target && r.streak <= 0 {
return r.streak - 1
} else {
return 0
}
}
func (r *Outcome) Target() bool { return r.target }
func (r *Outcome) String() string {
return fmt.Sprintf("%s %s", r.base.String(), r.targetStr())
}
func (r *Outcome) targetStr() string {
if r.target {
return "1"
} else {
return "0"
}
}
func (r *Outcome) newCount(expecting bool, count int) int {
if expecting == r.target {
count++
}
return count
}