11import streamlit as sl
22from data_fetcher import get_user_workouts , insert_user_post
33from modules import display_activity_summary , display_recent_workouts
4+ from datetime import datetime
45
5- def display (user_id = "user1" ):
6- sl .title ("🏃♂️ Activities Dashboard" )
6+ #Used GPT 4o to help with share logic
7+
8+ def display_activity_page (user_id = "user1" ):
9+ # sl.title("🏃♂️ Activities Dashboard")
710
811 fetcher = lambda : get_user_workouts (user_id )
912 workouts = fetcher ()
10- recent_workouts = workouts [- 3 :] if len (workouts ) >= 3 else workouts
1113
12- side_view (user_id , fetcher )
14+ # Sort by timestamp descending (most recent first)
15+ sorted_workouts = sorted (
16+ workouts ,
17+ key = lambda w : w ['start_timestamp' ][:w ['start_timestamp' ].index (' ' )],
18+ reverse = True
19+ )
20+
21+ # Get the 3 most recent
22+ recent_workouts = sorted_workouts [:3 ]
23+
24+ side_view (user_id , recent_workouts )
1325
1426 total_distance = sl .session_state .get ("total_distance" , 0 )
1527 total_steps = sl .session_state .get ("total_steps" , 0 )
1628 total_calories = sl .session_state .get ("total_calories" , 0 )
1729
1830 handle_share_section (user_id , workouts , recent_workouts )
1931
20- def side_view (user_id , fetcher ):
32+ def side_view (user_id , workouts_list ):
2133 left_col , right_col = sl .columns (2 )
2234
2335 with left_col :
24- sl .subheader ("🕒 Recent Workouts" )
25- # display_activity_summary expects a fetcher function
26- display_recent_workouts (userId = user_id , workouts_func = get_user_workouts , streamlit_module = sl )
36+ # Developeed with GPT 4o
37+ display_recent_workouts (
38+ user_id ,
39+ workouts_func = lambda uid : sorted (get_user_workouts (uid ), key = lambda w : w ['start_timestamp' ], reverse = True )[:3 ]
40+ )
2741
2842 with right_col :
29- sl .subheader ("📊 Summary" )
30- # display_recent_workouts directly takes the get_user_workouts function
31- display_activity_summary (fetcher = fetcher )
43+ display_activity_summary (workouts_list )
3244
3345
3446def handle_share_section (user_id , workouts , recent_workouts ):
@@ -41,6 +53,9 @@ def handle_share_section(user_id, workouts, recent_workouts):
4153 share_total_stats (user_id )
4254 elif data_source == "A Specific Workout" :
4355 share_specific_workout (user_id , recent_workouts )
56+ sl .markdown ("---" )
57+ sl .markdown ("When you press the sharing button, wait a few seconds until the shared notification appears!" )
58+
4459
4560def share_total_stats (user_id ):
4661
@@ -52,9 +67,9 @@ def share_total_stats(user_id):
5267
5368 if sl .button ("📤 Share" ):
5469 if stat_type == "Steps" :
55- message = f"👟 I walked { steps } steps this week!"
70+ message = f"👟 I walked { round ( steps ) } steps this week!"
5671 elif stat_type == "Distance" :
57- message = f"🏃 I ran { distance } miles this week!"
72+ message = f"🏃 I ran { round ( distance ) } miles this week!"
5873 elif stat_type == "Calories" :
5974 message = f"🔥 I burned { calories } calories this week!"
6075 elif stat_type == "All" :
0 commit comments