-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathperformance.go
65 lines (54 loc) · 1.34 KB
/
performance.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
package traindown
import (
"encoding/json"
)
// Performance is an expression of a movement.
type Performance struct {
Fails int `json:"fails"`
Load float32 `json:"load"`
PercentOfMax float32 `json:"percentOfMax,omitempty"`
Reps int `json:"reps"`
Sequence int `json:"sequence"`
Sets int `json:"sets"`
Unit string `json:"unit"`
Metadata Metadata `json:"metadata"`
Notes []string `json:"notes"`
}
/* Public */
// NewPerformance spits out a new Performance
func NewPerformance() *Performance {
return &Performance{
Metadata: make(Metadata),
Notes: make([]string, 0),
Reps: 1,
Sets: 1,
Unit: "unknown unit",
}
}
func (p Performance) String() string {
ps, _ := json.Marshal(p)
return string(ps)
}
// Volume produces a float and a string containing the unit.
func (p Performance) Volume() (float32, string) {
v := (float32(p.Reps) - float32(p.Fails)) * float32(p.Sets) * p.Load
return v, p.Unit
}
/* Private */
func (p *Performance) assignSpecial(k string, v string) bool {
if isUnit(k) {
p.Unit = v
return true
}
return false
}
func (p *Performance) maybeInheritUnit(s *Session, m *Movement) {
if p.Unit == "unknown unit" || p.Unit == "" {
if s.DefaultUnit != "" {
p.Unit = s.DefaultUnit
}
if m.DefaultUnit != "" {
p.Unit = m.DefaultUnit
}
}
}