Update app.py
Browse files
app.py
CHANGED
@@ -87,7 +87,6 @@ st.write(f"Factor for chosen grip: {grip_styles[grip_style]}")
|
|
87 |
|
88 |
|
89 |
# BMR Calculator
|
90 |
-
|
91 |
import streamlit as st
|
92 |
import pandas as pd
|
93 |
import os
|
@@ -95,20 +94,34 @@ from datetime import datetime
|
|
95 |
|
96 |
# Constants
|
97 |
GRAVITATIONAL_FORCE = 9.8 # Earth's gravitational force in m/s^2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
# Calculate Basal Metabolic Rate
|
100 |
-
def calculate_bmr(
|
101 |
-
return
|
102 |
|
103 |
# Calculate Calories Burned Lifting Weights
|
104 |
-
def calculate_calories_burned(
|
105 |
-
|
|
|
106 |
return joules / 4184 # Convert joules to kilocalories
|
107 |
|
108 |
# Save to file
|
109 |
-
def save_data(
|
110 |
filename = f"data_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv"
|
111 |
-
df = pd.DataFrame({'Date': [datetime.now()], '
|
112 |
df.to_csv(filename, index=False)
|
113 |
return filename
|
114 |
|
@@ -118,20 +131,25 @@ def load_history():
|
|
118 |
return files
|
119 |
|
120 |
# UI
|
121 |
-
st.title('ποΈ Calorie Counter for Weightlifting ποΈ')
|
122 |
|
123 |
with st.form('input_form'):
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
127 |
submitted = st.form_submit_button('Calculate')
|
128 |
|
129 |
if submitted:
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
135 |
st.sidebar.success(f'π Saved as {save_file}')
|
136 |
|
137 |
# Display history
|
@@ -141,5 +159,3 @@ for file in load_history():
|
|
141 |
df = pd.read_csv(file)
|
142 |
st.sidebar.write(df)
|
143 |
|
144 |
-
|
145 |
-
|
|
|
87 |
|
88 |
|
89 |
# BMR Calculator
|
|
|
90 |
import streamlit as st
|
91 |
import pandas as pd
|
92 |
import os
|
|
|
94 |
|
95 |
# Constants
|
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):
|
104 |
+
return pounds * POUND_TO_KG
|
105 |
+
|
106 |
+
# Convert feet and inches to meters
|
107 |
+
def feet_inches_to_meters(feet, inches):
|
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 |
|
|
|
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
|
|
|
159 |
df = pd.read_csv(file)
|
160 |
st.sidebar.write(df)
|
161 |
|
|
|
|