Update app.py
Browse files
app.py
CHANGED
@@ -96,8 +96,7 @@ 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 |
-
AVERAGE_CALORIES_FEMALE = 2000 # Average daily calorie burn for females
|
101 |
|
102 |
# Convert pounds to kilograms
|
103 |
def pounds_to_kg(pounds):
|
@@ -108,49 +107,39 @@ 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 |
-
|
119 |
-
|
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 |
-
#
|
129 |
-
def
|
130 |
-
|
131 |
-
return
|
132 |
|
133 |
# UI
|
134 |
-
st.title('ποΈ
|
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 |
-
|
149 |
-
|
150 |
-
|
151 |
-
st.success(f'
|
152 |
-
|
153 |
-
st.sidebar.success(f'π Saved as {save_file}')
|
154 |
|
155 |
# Display history
|
156 |
st.sidebar.header('π 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 |
+
CALORIES_PER_KG_MUSCLE = 13 # Average additional calories burned per day per kg of muscle gained
|
|
|
100 |
|
101 |
# Convert pounds to kilograms
|
102 |
def pounds_to_kg(pounds):
|
|
|
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, duration_hours):
|
112 |
total_mass_lifted = mass_kg * sets * reps
|
113 |
+
joules_per_rep = total_mass_lifted * GRAVITATIONAL_FORCE * height_diff
|
114 |
+
joules_total = joules_per_rep * duration_hours * 3600 / (sets * reps) # Assuming continuous lifting for the duration
|
115 |
+
return joules_total / 4184 # Convert joules to kilocalories
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
# Calculate Additional Daily Calorie Burn from Muscle Gain
|
118 |
+
def estimate_additional_calorie_burn(weight_kg, duration_months):
|
119 |
+
muscle_gain = weight_kg * duration_months * 0.025 # Estimate muscle gain: 2.5% of lifted weight per month
|
120 |
+
return muscle_gain * CALORIES_PER_KG_MUSCLE
|
121 |
|
122 |
# UI
|
123 |
+
st.title('ποΈ Advanced Calorie Counter for Weightlifting ποΈ')
|
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 |
+
calories_burned = calculate_calories_burned(weight_kg, height_meters, sets, reps, duration_hours)
|
139 |
+
additional_calories = estimate_additional_calorie_burn(weight_kg, duration_months)
|
140 |
+
st.success(f'π₯ Calories Burned in Session: {calories_burned:.2f} kcal')
|
141 |
+
st.success(f'π Additional Daily Calorie Burn from Muscle Gain: {additional_calories:.2f} kcal/day')
|
142 |
+
|
|
|
143 |
|
144 |
# Display history
|
145 |
st.sidebar.header('π History')
|