Skip to content

Commit 339df98

Browse files
Added Sensor Data information to activity_page.py
1 parent f73a79a commit 339df98

3 files changed

Lines changed: 55 additions & 17 deletions

File tree

activity_page.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import streamlit as sl
2-
from data_fetcher import get_user_workouts, insert_user_post
2+
from data_fetcher import get_user_workouts, insert_user_post,get_user_sensor_data
33
from modules import display_activity_summary, display_recent_workouts
44
from datetime import datetime
5+
import pandas as pd
6+
from google.cloud import bigquery
7+
58

69
#Used GPT 4o to help with share logic
710

@@ -41,6 +44,31 @@ def side_view(user_id, workouts_list):
4144

4245
with right_col:
4346
display_activity_summary(workouts_list)
47+
sl.markdown(" ")
48+
sl.markdown("---")
49+
handle_sensor_data(workouts_list, user_id)
50+
51+
52+
def handle_sensor_data(workouts_list, user_id):
53+
client = bigquery.Client()
54+
sl.header("Sensor Data")
55+
56+
for workout in workouts_list:
57+
sl.subheader(f"{workout['workout_id']}")
58+
59+
sensor_data = get_user_sensor_data(
60+
client,
61+
user_id=user_id,
62+
workout_id=workout['workout_id']
63+
)
64+
65+
if sensor_data:
66+
with sl.expander("Sensor Data"):
67+
sl.write("Sensor Data:")
68+
df = pd.DataFrame(sensor_data)
69+
sl.table(df) # or st.dataframe(df)
70+
else:
71+
sl.write("No sensor data found for this workout.")
4472

4573

4674
def handle_share_section(user_id, workouts, recent_workouts):

data_fetcher.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@
6262
},
6363
}
6464

65-
65+
@sl.cache_data(
66+
ttl=60,
67+
hash_funcs={
68+
bigquery.Client: lambda _: None, # or id(_)
69+
types.FunctionType: lambda _: None, # ignore function hashing
70+
types.MethodType: lambda _: None, # ignore method hashing
71+
}
72+
)
6673
def get_user_sensor_data(client: bigquery.Client, user_id: str, workout_id: str):
6774
"""Returns a list of timestampped information for a given workout.
6875
"""
@@ -130,7 +137,7 @@ def get_user_sensor_data(client: bigquery.Client, user_id: str, workout_id: str)
130137

131138

132139
@sl.cache_data(
133-
ttl=60, # Set a 300-second TTL
140+
ttl=60,
134141
hash_funcs={
135142
bigquery.Client: lambda _: None, # or id(_)
136143
types.FunctionType: lambda _: None, # ignore function hashing
@@ -166,6 +173,7 @@ def default_execute_query(client, query):
166173

167174
#used gemini for assistance:
168175
@sl.cache_data(
176+
ttl=200,
169177
hash_funcs={
170178
bigquery.Client: lambda _: None, # or id(_)
171179
types.FunctionType: lambda _: None, # ignore function hashing
@@ -219,11 +227,11 @@ def default_execute_query(client, query):
219227

220228
#used gemini for assistance:
221229
@sl.cache_data(
222-
ttl=30, # Set a 300-second TTL
230+
ttl=30,
223231
hash_funcs={
224-
bigquery.Client: lambda _: None, # or id(_)
225-
types.FunctionType: lambda _: None, # ignore function hashing
226-
types.MethodType: lambda _: None, # ignore method hashing
232+
bigquery.Client: lambda _: None,
233+
types.FunctionType: lambda _: None,
234+
types.MethodType: lambda _: None,
227235
}
228236
)
229237
def get_user_posts(user_id, query_db=bigquery, execute_query=None):
@@ -302,9 +310,9 @@ def default_execute_query(client, query):
302310
@sl.cache_data(
303311
ttl=300, # Set a 300-second TTL
304312
hash_funcs={
305-
bigquery.Client: lambda _: None, # or id(_)
306-
types.FunctionType: lambda _: None, # ignore function hashing
307-
types.MethodType: lambda _: None, # ignore method hashing
313+
bigquery.Client: lambda _: None,
314+
types.FunctionType: lambda _: None,
315+
types.MethodType: lambda _: None,
308316
}
309317
)
310318
def get_user_friends(user_id, query_db=bigquery, execute_query=None):
@@ -331,9 +339,9 @@ def default_execute_query(client, query):
331339

332340
@sl.cache_data(
333341
hash_funcs={
334-
bigquery.Client: lambda _: None, # or id(_)
335-
types.FunctionType: lambda _: None, # ignore function hashing
336-
types.MethodType: lambda _: None, # ignore method hashing
342+
bigquery.Client: lambda _: None,
343+
types.FunctionType: lambda _: None,
344+
types.MethodType: lambda _: None,
337345
}
338346
)
339347
def get_user_info(user_id, query_db=bigquery, execute_query=None):
@@ -367,11 +375,13 @@ def default_execute_query(client, query):
367375
else:
368376
return None
369377

370-
@sl.cache_data(
378+
379+
380+
@sl.cache_data(
381+
ttl=120,
371382
hash_funcs={
372-
bigquery.Client: lambda _: None, # or id(_)
373-
types.FunctionType: lambda _: None, # ignore function hashing
374-
types.MethodType: lambda _: None, # ignore method hashing
383+
bigquery.Client: lambda _: None,
384+
types.FunctionType: lambda _: None,
375385
}
376386
)
377387
def get_genai_advice(
3.01 MB
Loading

0 commit comments

Comments
 (0)