-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fitness.kt
112 lines (93 loc) · 3.15 KB
/
Fitness.kt
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
105
106
107
108
109
110
111
112
object Fitness
{
const val kilogramsInPounds = 2.205
const val centimetersInInches = 2.54
/*************************************
* Source: https://sites.google.com/site/compendiumofphysicalactivities/
*************************************/
const val MET_SITTING_STILL = 1.0
const val MET_BELAYING = 2.0
const val MET_RAPPELLING = 5.0
const val MET_CLIMBING_EASY = 5.8
const val MET_CLIMBING_MODERATE = 7.5
const val MET_CLIMBING_HARD = 8.0
enum class Gender
{
Unspecified,
Male,
Female
}
var gender = Unspecified
var age = 0
var kilograms = 0.0
var centimeters = 0.0
var restingHeartRate = 0
/*************************************
* Source: https://www.openfit.com/max-heart-rate
*************************************/
var maxHeartRate = 0.0
get() = if (field != 0.0 || age == 0) field else maxHeartRate()
fun maxHeartRate(age: Int = this.age) = 205.8 - (0.685 * age)
/*************************************
* Source: https://www.omnicalculator.com/sports/vo2-max
*************************************/
var vO2max = 0.0
get() = if (field != 0.0 || (field == 0.0 && age == 0)) field else vO2max()
fun vO2max(restingHeartRate: Int = this.restingHeartRate,
maxHeartRate: Double = this.maxHeartRate) =
if (restingHeartRate != 0) 15.3 * (maxHeartRate / restingHeartRate) else 0.0
var pounds
set(value)
{
kilograms = value / kilogramsInPounds
}
get() = kilograms * kilogramsInPounds
var inches
set(value)
{
centimeters = value * centimetersInInches
}
get() = centimeters / centimetersInInches
/*************************************
* Source: https://sendedition.com/how-many-calories-do-you-burn-from-climbing/
*************************************/
fun calories(duration: Duration,
averageHeartRate: Int,
metabolicEquivalentOfTask: Double = 0.0): Int
{
if (kilograms == 0.0) return 0
return if (averageHeartRate != 0 && gender != Unspecified && age != 0)
{
(if (vO2max != 0.0)
{
if (gender == Male)
(-95.7735 + (0.634 * averageHeartRate) + (0.404 * vO2max) + (0.394 * kilograms) + (0.271 * age)) / 4.184
else
(-59.3954 + (0.450 * averageHeartRate) + (0.380 * vO2max) + (0.103 * kilograms) + (0.274 * age)) / 4.184
}
else
{
if (gender == Male)
(-55.0969 + (0.6309 * averageHeartRate) + (0.1988 * kilograms) + (0.2017 * age)) / 4.184
else
(-20.4022 + (0.4472 * averageHeartRate) - (0.1263 * kilograms) + (0.074 * age)) / 4.184
} * (duration.seconds / 60.0)).roundToInt()
}
else
calories(duration, metabolicEquivalentOfTask)
}
fun calories(duration: Duration, metabolicEquivalentOfTask: Double): Int
{
return (kilograms * metabolicEquivalentOfTask * (duration.seconds / 3600.0)).roundToInt()
}
fun clear()
{
gender = Unspecified
age = 0
kilograms = 0.0
centimeters = 0.0
restingHeartRate = 0
maxHeartRate = 0.0
vO2max = 0.0
}
}