Update app.py
Browse files
app.py
CHANGED
@@ -96,7 +96,8 @@ from datetime import datetime
|
|
96 |
GRAVITATIONAL_FORCE = 9.8 # Earth's gravitational force in m/s^2
|
97 |
POUND_TO_KG = 0.453592 # Conversion factor from pounds to kilograms
|
98 |
INCH_TO_METER = 0.0254 # Conversion factor from inches to meters
|
99 |
-
|
|
|
100 |
|
101 |
# Convert pounds to kilograms
|
102 |
def pounds_to_kg(pounds):
|
@@ -107,45 +108,50 @@ def feet_inches_to_meters(feet, inches):
|
|
107 |
total_inches = feet * 12 + inches
|
108 |
return total_inches * INCH_TO_METER
|
109 |
|
|
|
|
|
|
|
|
|
110 |
# Calculate Calories Burned Lifting Weights
|
111 |
-
def calculate_calories_burned(mass_kg, height_diff, sets, reps
|
112 |
total_mass_lifted = mass_kg * sets * reps
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
-
#
|
118 |
-
def
|
119 |
-
|
120 |
-
return
|
121 |
|
122 |
# UI
|
123 |
-
st.title('ποΈ
|
124 |
|
125 |
with st.form('input_form'):
|
|
|
126 |
feet = st.number_input('Height (feet):', min_value=0, value=5)
|
127 |
inches = st.number_input('Height (inches):', min_value=0, value=11)
|
128 |
weight = st.number_input('Enter the weight lifted (lbs):', min_value=0.0, value=30.0)
|
129 |
sets = st.number_input('Number of sets:', min_value=1, value=10)
|
130 |
reps = st.number_input('Repetitions per set:', min_value=1, value=10)
|
131 |
-
duration_hours = st.number_input('Duration of session (hours):', min_value=0.1, value=1.0)
|
132 |
-
duration_months = st.number_input('Duration of regular training (months):', min_value=1, value=1)
|
133 |
submitted = st.form_submit_button('Calculate')
|
134 |
|
135 |
if submitted:
|
136 |
height_meters = feet_inches_to_meters(feet, inches)
|
137 |
weight_kg = pounds_to_kg(weight)
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
st.success(f'
|
|
|
|
|
142 |
|
143 |
-
|
144 |
-
# Load history
|
145 |
-
def load_history():
|
146 |
-
files = [f for f in os.listdir('.') if f.startswith('data_')]
|
147 |
-
return files
|
148 |
-
|
149 |
# Display history
|
150 |
st.sidebar.header('π History')
|
151 |
for file in load_history():
|
|
|
96 |
GRAVITATIONAL_FORCE = 9.8 # Earth's gravitational force in m/s^2
|
97 |
POUND_TO_KG = 0.453592 # Conversion factor from pounds to kilograms
|
98 |
INCH_TO_METER = 0.0254 # Conversion factor from inches to meters
|
99 |
+
AVERAGE_CALORIES_MALE = 2500 # Average daily calorie burn for males
|
100 |
+
AVERAGE_CALORIES_FEMALE = 2000 # Average daily calorie burn for females
|
101 |
|
102 |
# Convert pounds to kilograms
|
103 |
def pounds_to_kg(pounds):
|
|
|
108 |
total_inches = feet * 12 + inches
|
109 |
return total_inches * INCH_TO_METER
|
110 |
|
111 |
+
# Calculate Basal Metabolic Rate
|
112 |
+
def calculate_bmr(gender):
|
113 |
+
return AVERAGE_CALORIES_MALE if gender == 'Male' else AVERAGE_CALORIES_FEMALE
|
114 |
+
|
115 |
# Calculate Calories Burned Lifting Weights
|
116 |
+
def calculate_calories_burned(mass_kg, height_diff, sets, reps):
|
117 |
total_mass_lifted = mass_kg * sets * reps
|
118 |
+
joules = total_mass_lifted * GRAVITATIONAL_FORCE * height_diff
|
119 |
+
return joules / 4184 # Convert joules to kilocalories
|
120 |
+
|
121 |
+
# Save to file
|
122 |
+
def save_data(gender, height, weight, calories):
|
123 |
+
filename = f"data_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv"
|
124 |
+
df = pd.DataFrame({'Date': [datetime.now()], 'Gender': [gender], 'Height': [height], 'Weight Lifted (lbs)': [weight], 'Calories Burned': [calories]})
|
125 |
+
df.to_csv(filename, index=False)
|
126 |
+
return filename
|
127 |
|
128 |
+
# Load history
|
129 |
+
def load_history():
|
130 |
+
files = [f for f in os.listdir('.') if f.startswith('data_')]
|
131 |
+
return files
|
132 |
|
133 |
# UI
|
134 |
+
st.title('ποΈ Personalized Calorie Counter for Weightlifting ποΈ')
|
135 |
|
136 |
with st.form('input_form'):
|
137 |
+
gender = st.radio('Select your Gender:', ('Male', 'Female'))
|
138 |
feet = st.number_input('Height (feet):', min_value=0, value=5)
|
139 |
inches = st.number_input('Height (inches):', min_value=0, value=11)
|
140 |
weight = st.number_input('Enter the weight lifted (lbs):', min_value=0.0, value=30.0)
|
141 |
sets = st.number_input('Number of sets:', min_value=1, value=10)
|
142 |
reps = st.number_input('Repetitions per set:', min_value=1, value=10)
|
|
|
|
|
143 |
submitted = st.form_submit_button('Calculate')
|
144 |
|
145 |
if submitted:
|
146 |
height_meters = feet_inches_to_meters(feet, inches)
|
147 |
weight_kg = pounds_to_kg(weight)
|
148 |
+
bmr = calculate_bmr(gender)
|
149 |
+
calories_burned = calculate_calories_burned(weight_kg, height_meters, sets, reps)
|
150 |
+
save_file = save_data(gender, f'{feet}\'{inches}"', weight, calories_burned)
|
151 |
+
st.success(f'π₯ Estimated Daily Calorie Burn (BMR): {bmr} kcal/day')
|
152 |
+
st.success(f'π₯ Calories Burned in Session: {calories_burned:.4f} kcal')
|
153 |
+
st.sidebar.success(f'π Saved as {save_file}')
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
# Display history
|
156 |
st.sidebar.header('π History')
|
157 |
for file in load_history():
|