-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmovement.go
61 lines (49 loc) · 1.11 KB
/
movement.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
package traindown
import (
"encoding/json"
)
// Movement is an thing you do, you know?
type Movement struct {
DefaultUnit string `json:"defaultUnit,omitempty"`
Name string `json:"name"`
Sequence int `json:"sequence"`
SuperSet bool `json:"superSet"`
Performances []*Performance `json:"performances"`
Metadata Metadata `json:"metadata"`
Notes []string `json:"notes"`
}
/* Public */
// NewMovement spits out a new Movement
func NewMovement() *Movement {
return &Movement{
Metadata: make(Metadata),
Notes: make([]string, 0),
Performances: make([]*Performance, 0),
}
}
func (m Movement) String() string {
ms, _ := json.Marshal(m)
return string(ms)
}
// Volumes computes the volume performed by unit.
func (m Movement) Volumes() map[string]float32 {
v := make(map[string]float32)
for _, p := range m.Performances {
pv, pu := p.Volume()
val, ok := v[pu]
if ok {
v[pu] = val + pv
} else {
v[pu] = pv
}
}
return v
}
/* Private */
func (m *Movement) assignSpecial(k string, v string) bool {
if isUnit(k) {
m.DefaultUnit = v
return true
}
return false
}