|
import streamlit as st |
|
|
|
|
|
def calories_swim(time_hr, weight_lb, style_mets): |
|
return (time_hr * style_mets * 3.5 * weight_lb) / 10 |
|
|
|
|
|
def calories_pullup(reps, weight, grip_style_factor): |
|
return (reps * 5 * weight) / 150 * grip_style_factor |
|
|
|
|
|
st.title("Calories Burned Calculator πββοΈπͺ") |
|
st.sidebar.header("Input Parameters π οΈ") |
|
|
|
|
|
time_swim = st.sidebar.slider("Swimming Time (hours)", 0.0, 5.0, 2.0) |
|
weight = st.sidebar.number_input("Your weight (lbs)", 100, 300, 175) |
|
|
|
|
|
reps = st.sidebar.slider("Number of Pull-Ups", 0, 500, 200) |
|
|
|
|
|
st.sidebar.subheader("Choose Exercise Type π€ΈββοΈ") |
|
exercise_type = st.sidebar.selectbox( |
|
"", |
|
["Swim Jim πββοΈ", "Ring King π", "Both Boost π"] |
|
) |
|
|
|
|
|
swim_styles = { |
|
"Treading Water π": 6, |
|
"Backstroke πββοΈ": 9, |
|
"Breaststroke πΈ": 10, |
|
"Freestyle Light π¦": 11, |
|
"Freestyle Vigorous π": 14.3, |
|
"Butterfly π¦": 14.3, |
|
"Dog Paddle πΆ": 7 |
|
} |
|
|
|
|
|
grip_styles = { |
|
"Standard π": 1, |
|
"Mixed Grip β¨": 1.1, |
|
"Wide Grip π ": 1.2 |
|
} |
|
|
|
st.sidebar.subheader("Choose Swim Style π") |
|
swim_style = st.sidebar.selectbox( |
|
"", |
|
list(swim_styles.keys()) |
|
) |
|
|
|
st.sidebar.subheader("Choose Ring Style πͺ") |
|
grip_style = st.sidebar.selectbox( |
|
"", |
|
list(grip_styles.keys()) |
|
) |
|
|
|
|
|
calories_from_swimming = calories_swim(time_swim, weight, swim_styles[swim_style]) |
|
calories_from_pullups = calories_pullup(reps, weight, grip_styles[grip_style]) |
|
|
|
|
|
st.subheader(f"Calories Burned π₯") |
|
if exercise_type == "Swim Jim πββοΈ": |
|
st.write(f"Calories burned from swimming: {calories_from_swimming:.2f}") |
|
elif exercise_type == "Ring King π": |
|
st.write(f"Calories burned from pull-ups: {calories_from_pullups:.2f}") |
|
else: |
|
total_calories = calories_from_swimming + calories_from_pullups |
|
st.write(f"Total calories burned: {total_calories:.2f}") |
|
|
|
st.subheader("Muscle Groups Worked π¦Ύ") |
|
if exercise_type == "Swim Jim πββοΈ": |
|
st.write("Swimming works the back, shoulders, arms, and legs.") |
|
elif exercise_type == "Ring King π": |
|
st.write("Pull-ups work the back, biceps, and forearms.") |
|
else: |
|
st.write("Doing both exercises works almost all major muscle groups!") |
|
|
|
st.subheader(f"Swim Style: {swim_style} π") |
|
st.write(f"METS for chosen style: {swim_styles[swim_style]}") |
|
|
|
st.subheader(f"Ring Style: {grip_style} πͺ") |
|
st.write(f"Factor for chosen grip: {grip_styles[grip_style]}") |
|
|
|
|
|
|
|
|
|
import streamlit as st |
|
import pandas as pd |
|
import os |
|
from datetime import datetime |
|
|
|
|
|
GRAVITATIONAL_FORCE = 9.8 |
|
POUND_TO_KG = 0.453592 |
|
INCH_TO_METER = 0.0254 |
|
AVERAGE_CALORIES_MALE = 2500 |
|
AVERAGE_CALORIES_FEMALE = 2000 |
|
|
|
|
|
def pounds_to_kg(pounds): |
|
return pounds * POUND_TO_KG |
|
|
|
|
|
def feet_inches_to_meters(feet, inches): |
|
total_inches = feet * 12 + inches |
|
return total_inches * INCH_TO_METER |
|
|
|
|
|
def calculate_bmr(gender): |
|
return AVERAGE_CALORIES_MALE if gender == 'Male' else AVERAGE_CALORIES_FEMALE |
|
|
|
|
|
def calculate_calories_burned(mass_kg, height_diff, sets, reps): |
|
total_mass_lifted = mass_kg * sets * reps |
|
joules = total_mass_lifted * GRAVITATIONAL_FORCE * height_diff |
|
return joules / 4184 |
|
|
|
|
|
def save_data(gender, height, weight, calories): |
|
filename = f"data_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv" |
|
df = pd.DataFrame({'Date': [datetime.now()], 'Gender': [gender], 'Height': [height], 'Weight Lifted (lbs)': [weight], 'Calories Burned': [calories]}) |
|
df.to_csv(filename, index=False) |
|
return filename |
|
|
|
|
|
def load_history(): |
|
files = [f for f in os.listdir('.') if f.startswith('data_')] |
|
return files |
|
|
|
|
|
st.title('ποΈ Personalized Calorie Counter for Weightlifting ποΈ') |
|
|
|
with st.form('input_form'): |
|
gender = st.radio('Select your Gender:', ('Male', 'Female')) |
|
feet = st.number_input('Height (feet):', min_value=0, value=5) |
|
inches = st.number_input('Height (inches):', min_value=0, value=11) |
|
weight = st.number_input('Enter the weight lifted (lbs):', min_value=0.0, value=30.0) |
|
sets = st.number_input('Number of sets:', min_value=1, value=10) |
|
reps = st.number_input('Repetitions per set:', min_value=1, value=10) |
|
submitted = st.form_submit_button('Calculate') |
|
|
|
if submitted: |
|
height_meters = feet_inches_to_meters(feet, inches) |
|
weight_kg = pounds_to_kg(weight) |
|
bmr = calculate_bmr(gender) |
|
calories_burned = calculate_calories_burned(weight_kg, height_meters, sets, reps) |
|
save_file = save_data(gender, f'{feet}\'{inches}"', weight, calories_burned) |
|
st.success(f'π₯ Estimated Daily Calorie Burn (BMR): {bmr} kcal/day') |
|
st.success(f'π₯ Calories Burned in Session: {calories_burned:.4f} kcal') |
|
st.sidebar.success(f'π Saved as {save_file}') |
|
|
|
|
|
st.sidebar.header('π History') |
|
for file in load_history(): |
|
if st.sidebar.button(f'π
{file}', key=file): |
|
df = pd.read_csv(file) |
|
st.sidebar.write(df) |
|
|
|
|