This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heartrate.go
104 lines (89 loc) · 2.93 KB
/
heartrate.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"fmt"
"math"
"github.com/jedib0t/go-pretty/table"
"github.com/jedib0t/go-pretty/text"
)
// HRZone define a heart rate zone with a name, minimum and maximum percentage
type HRZone struct {
MinPCT int // The minimum percentage of the heart rate
MaxPCT int // The maximum percentage of the heart rate
Name string // The name of the zone
}
// ToHeartRate calculates the lower and upper heart rate for the zone
func (hrZone *HRZone) ToHeartRate(rest int, max int) (int, int) {
lower := hrZone.calcHeartRate(hrZone.MinPCT, rest, max)
upper := hrZone.calcHeartRate(hrZone.MaxPCT, rest, max)
return lower, upper
}
func (hrZone *HRZone) calcHeartRate(pct int, rest int, max int) int {
pctAsFloat := float64(pct) / 100.0
restAsFloat := float64(rest)
diffAsFloat := float64(max - rest)
return int(math.Round((pctAsFloat * diffAsFloat) + restAsFloat))
}
func printZones(restHR int, maxHR int, zones []*HRZone) {
tw := table.NewWriter()
tw.SetStyle(table.StyleBold)
tw.AppendHeader(table.Row{"type", "% min", "% max", "hr min", "hr max"})
tw.SetAlign([]text.Align{
text.AlignLeft,
text.AlignRight,
text.AlignRight,
text.AlignRight,
text.AlignRight,
})
for _, zone := range zones {
lowerHR, upperHR := zone.ToHeartRate(restHR, maxHR)
tw.AppendRow(table.Row{
zone.Name,
fmt.Sprintf("%d%%", zone.MinPCT),
fmt.Sprintf("%d%%", zone.MaxPCT),
lowerHR,
upperHR,
})
}
fmt.Printf("%s\n", tw.Render())
}
func main() {
restHR := 45
maxHR := 194
fmt.Printf("Rest HR: %d\n Max HR: %d\n", restHR, maxHR)
fmt.Println("\nSysteem Wellens")
printZones(restHR, maxHR, []*HRZone{
{45, 60, "Recuperatietraining"},
{61, 64, "Long Slow Distance"},
{65, 70, "Extensieve Uithouding"},
{71, 78, "Tempoduurtraining"},
{79, 84, "Bloktrainging"},
{85, 89, "Extensieve Intervaltraining"},
{90, 100, "Weerstandstraining"},
})
fmt.Println("\nhttp://doefiets.nl/training/basisprincipes/hartslagzones-karvonen")
printZones(restHR, maxHR, []*HRZone{
{45, 60, "Hersteltraining (H)"},
{60, 70, "Rustige duurtraining (D1)"},
{70, 80, "Intensieve duurtraining (D2)"},
{80, 90, "MLSS-training (D3)"},
{90, 100, "Weerstandstraining (W)"},
})
fmt.Println("\nhttps://www.3athlon.be/2005/09/29/formule-van-karvonen/ (fietsen)")
printZones(restHR, maxHR, []*HRZone{
{55, 60, "recuperatie training"},
{60, 65, "LSD training (Long Slow Distance)"},
{65, 70, "extensieve uithouding"},
{70, 80, "intensieve uithouding"},
{80, 90, "tempo-interval"},
{90, 95, "Weerstand"},
})
fmt.Println("\nhttps://www.3athlon.be/2005/09/29/formule-van-karvonen/ (lopen)")
printZones(restHR, maxHR, []*HRZone{
{55, 65, "recuperatie training"},
{65, 70, "LSD training (Long Slow Distance)"},
{70, 75, "extensieve uithouding"},
{75, 85, "intensieve uithouding"},
{85, 90, "tempo-interval"},
{90, 95, "Weerstand"},
})
}