awacke1 commited on
Commit
666122b
Β·
1 Parent(s): 08d0a41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -22
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
- 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,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, 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
- # 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():