-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvo2max.py
81 lines (67 loc) · 2.24 KB
/
vo2max.py
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
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
def vo2max_male(distance_km):
return (22.351 * distance_km) - 11.288
def vo2max_female(distance_km):
return (21.097 * distance_km) - 8.41
# Mean and std dev values for VO2 max based on age and gender.
# These are values from the provided table; real-world data may differ.
VO2_MEAN_STD = {
'Male': {
'20-29': (54.4, 8.4),
'30-39': (49.1, 7.7),
'40-49': (47.2, 7.7),
'50-59': (42.6, 7.4),
'60-69': (39.2, 6.7),
'70+': (35.3, 6.5),
},
'Female': {
'20-29': (43.0, 7.7),
'30-39': (40.0, 6.8),
'40-49': (38.4, 6.9),
'50-59': (34.4, 5.7),
'60-69': (31.1, 5.1),
'70+': (28.3, 5.2),
}
}
st.title("Cooper Test VO2 Max Estimator")
gender = st.selectbox("Select Gender", ["Male", "Female"])
age = st.number_input("Enter your age", 5, 99)
distance = st.number_input("Enter distance covered in 12 minutes (km)", 0.0, 20.0)
# Determine age group
if age < 30:
age_group = '20-29'
elif age < 40:
age_group = '30-39'
elif age < 50:
age_group = '40-49'
elif age < 60:
age_group = '50-59'
elif age < 70:
age_group = '60-69'
else:
age_group = '70+'
mean, std_dev = VO2_MEAN_STD[gender][age_group]
# Calculate VO2 max
if st.button("Calculate VO2 Max"):
if gender == "Male":
vo2 = vo2max_male(distance)
else:
vo2 = vo2max_female(distance)
# Determine percentile
percentile = stats.norm.cdf(vo2, mean, std_dev) * 100
st.write(f"Your estimated VO2 max is: {vo2:.2f} ml/kg/min")
st.write(f"Your percentile for your age group and gender is: {percentile:.2f}%")
# Visualization
x = np.linspace(mean - 4*std_dev, mean + 4*std_dev, 1000)
y = stats.norm.pdf(x, mean, std_dev)
fig, ax = plt.subplots()
ax.plot(x, y, label=f"Age: {age_group}, Gender: {gender}")
ax.axvline(x=vo2, color="red", linestyle="--", label="Your VO2 Max")
ax.set_title("VO2 Max Distribution by Age and Gender")
ax.set_ylabel("Probability Density")
ax.set_xlabel("VO2 Max (ml/kg/min)")
ax.legend()
st.pyplot(fig)