-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
80 lines (70 loc) · 3.24 KB
/
app.py
File metadata and controls
80 lines (70 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import streamlit as st
from src.main.model.Exercise import Exercise
from src.main.model.Workout import Workout
# Initialize workout list in session state
if "workout_list" not in st.session_state:
st.session_state.workout_list = []
st.title("🏋️ Workout Tracker")
st.markdown("Track your workouts, exercises, and sets with ease!")
# Create Workout
st.sidebar.header("➕ Create New Workout")
new_workout_name = st.sidebar.text_input("Workout Name")
if st.sidebar.button("Create Workout"):
if new_workout_name:
st.session_state.workout_list.append(Workout(new_workout_name))
st.sidebar.success(f"Workout '{new_workout_name}' added!")
else:
st.sidebar.error("Workout name cannot be empty.")
# Workout Selection
st.header("📋 Your Workouts")
if st.session_state.workout_list:
workout_names = [w.getName() for w in st.session_state.workout_list]
selected_workout_name = st.selectbox("Choose a workout to view/edit:", workout_names)
selected_workout = next(w for w in st.session_state.workout_list if w.getName() == selected_workout_name)
# Remove Workout
if st.button("🗑️ Remove This Workout"):
st.session_state.workout_list.remove(selected_workout)
st.success(f"Removed workout '{selected_workout_name}'")
st.experimental_rerun()
st.subheader(f"🏃 Exercises in '{selected_workout.getName()}'")
# List Exercises
for exercise in selected_workout.getExercises():
with st.expander(f"💪 {exercise.getName()}"):
sets = exercise.getSets()
if sets:
for i, s in enumerate(sets, 1):
st.write(f"**Set {i}** - Weight: {s.getWeight()}kg | Reps: {s.getReps()} | Rest: {s.getRest()}s")
# Add Set
with st.form(f"add_set_{exercise.getName()}"):
st.write("➕ Add a Set")
weight = st.number_input("Weight (kg)", min_value=0)
reps = st.number_input("Reps", min_value=0)
rest = st.number_input("Rest (seconds)", min_value=0)
submitted_set = st.form_submit_button("Add Set")
if submitted_set:
exercise.addSet(weight, reps, rest)
st.success("Set added!")
st.experimental_rerun()
# Remove last set
if st.button(f"Remove Last Set - {exercise.getName()}"):
if sets:
sets.pop()
st.warning("Last set removed.")
st.experimental_rerun()
else:
st.info("No sets to remove.")
# Add Exercise
st.subheader("➕ Add a New Exercise")
with st.form("add_exercise_form"):
exercise_name = st.text_input("Exercise Name")
time_taken = st.number_input("Time Taken (minutes)", min_value=0)
submitted_exercise = st.form_submit_button("Add Exercise")
if submitted_exercise:
if exercise_name:
selected_workout.addExercise(exercise_name, time_taken)
st.success(f"Exercise '{exercise_name}' added to workout!")
st.experimental_rerun()
else:
st.error("Exercise name cannot be empty.")
else:
st.info("You haven't added any workouts yet.")