Update app.py
Browse files
app.py
CHANGED
@@ -83,3 +83,63 @@ st.write(f"METS for chosen style: {swim_styles[swim_style]}")
|
|
83 |
|
84 |
st.subheader(f"Ring Style: {grip_style} πͺ")
|
85 |
st.write(f"Factor for chosen grip: {grip_styles[grip_style]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
st.subheader(f"Ring Style: {grip_style} πͺ")
|
85 |
st.write(f"Factor for chosen grip: {grip_styles[grip_style]}")
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
# BMR Calculator
|
90 |
+
|
91 |
+
import streamlit as st
|
92 |
+
import pandas as pd
|
93 |
+
import os
|
94 |
+
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(lbm):
|
101 |
+
return 500 + 22 * lbm
|
102 |
+
|
103 |
+
# Calculate Calories Burned Lifting Weights
|
104 |
+
def calculate_calories_burned(mass, height_diff):
|
105 |
+
joules = mass * GRAVITATIONAL_FORCE * height_diff
|
106 |
+
return joules / 4184 # Convert joules to kilocalories
|
107 |
+
|
108 |
+
# Save to file
|
109 |
+
def save_data(lbm, calories):
|
110 |
+
filename = f"data_{datetime.now().strftime('%Y%m%d_%H%M%S')}.csv"
|
111 |
+
df = pd.DataFrame({'Date': [datetime.now()], 'LBM': [lbm], 'Calories Burned': [calories]})
|
112 |
+
df.to_csv(filename, index=False)
|
113 |
+
return filename
|
114 |
+
|
115 |
+
# Load history
|
116 |
+
def load_history():
|
117 |
+
files = [f for f in os.listdir('.') if f.startswith('data_')]
|
118 |
+
return files
|
119 |
+
|
120 |
+
# UI
|
121 |
+
st.title('ποΈ Calorie Counter for Weightlifting ποΈ')
|
122 |
+
|
123 |
+
with st.form('input_form'):
|
124 |
+
lbm = st.number_input('Enter your Lean Body Mass (kg):', min_value=0.0, value=60.0)
|
125 |
+
mass = st.number_input('Enter the weight lifted (kg):', min_value=0.0, value=30.0)
|
126 |
+
height_diff = st.number_input('Enter the height difference (m):', min_value=0.0, value=1.0)
|
127 |
+
submitted = st.form_submit_button('Calculate')
|
128 |
+
|
129 |
+
if submitted:
|
130 |
+
bmr = calculate_bmr(lbm)
|
131 |
+
calories_burned = calculate_calories_burned(mass, height_diff)
|
132 |
+
save_file = save_data(lbm, calories_burned)
|
133 |
+
st.success(f'π₯ BMR: {bmr:.2f} kcal/day')
|
134 |
+
st.success(f'π₯ Calories Burned: {calories_burned:.4f} kcal')
|
135 |
+
st.sidebar.success(f'π Saved as {save_file}')
|
136 |
+
|
137 |
+
# Display history
|
138 |
+
st.sidebar.header('π History')
|
139 |
+
for file in load_history():
|
140 |
+
if st.sidebar.button(f'π
{file}', key=file):
|
141 |
+
df = pd.read_csv(file)
|
142 |
+
st.sidebar.write(df)
|
143 |
+
|
144 |
+
|
145 |
+
|