-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
188 lines (162 loc) · 5.75 KB
/
app.py
File metadata and controls
188 lines (162 loc) · 5.75 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#############################################################################
# app.py
#
# Entrypoint for the StudySync app.
#############################################################################
import streamlit as st
from data_fetcher import get_my_groups, get_user_profile, get_final_recommendations
st.set_page_config(
page_title="StudySync",
page_icon="📚",
layout="wide",
initial_sidebar_state="collapsed",
)
from modules import (
apply_styles,
render_top_nav,
display_user_profile,
navigation_bar,
display_explore_page,
display_my_groups_page,
display_genai_advice,
display_account_settings_page
)
PAGES = ["Explore Groups", "My Groups", "User Profile", "AI Recommendations", "Account Settings"]
def normalize_page(raw_value: str) -> str:
if not raw_value:
return "Explore Groups"
value = str(raw_value).strip().lower()
for page in PAGES:
if value == page.lower():
return page
return "Explore Groups"
def sync_query_params() -> None:
st.query_params["page"] = st.session_state.page
def display_app_page() -> None:
if "page" not in st.session_state:
st.session_state.page = "Explore Groups"
query_page = normalize_page(st.query_params.get("page", st.session_state.page))
st.session_state.page = query_page
apply_styles()
render_top_nav(selected_page=st.session_state.page)
matches_data = [
{
"major": "Computer Science",
"title": "GenAI & Systems Design",
"match_pct": 98,
"keywords": ["Algorithms", "Python", "GenAI"],
"time": "Tuesdays 5:00 PM",
"location": "Fisk Library",
"members": "3/5",
},
{
"major": "Computer Science",
"title": "iOS Dev Hackers",
"match_pct": 92,
"keywords": ["Swift", "Hackathons", "App Dev"],
"time": "Fridays 3:00 PM",
"location": "Nashville Tech Hub",
"members": "4/6",
},
{
"major": "Computer Science",
"title": "Technical Interview Prep",
"match_pct": 85,
"keywords": ["Data Structures", "Mock Interviews"],
"time": "Wednesdays 6:00 PM",
"location": "Remote / Discord",
"members": "2/4",
},
]
mock_study_groups = [
{
"group_title": "Calc II Cram Session",
"subject": "Math",
"description": "Preparing for the midterm with guided practice and quick review sheets.",
"date": "Oct 12",
"time": "4:00 PM",
"location": "Library Room 3",
"members": "4/6",
},
{
"group_title": "Bio 101 Lab Prep",
"subject": "Science",
"description": "Reviewing cell structures, lab notes, and quiz questions before Friday.",
"date": "Oct 13",
"time": "2:00 PM",
"location": "Science Hall",
"members": "2/4",
},
{
"group_title": "Art History Chat",
"subject": "Arts",
"description": "A discussion-based session focused on Renaissance themes and major works.",
"date": "Oct 15",
"time": "11:00 AM",
"location": "Cafe Blue",
"members": "8/10",
},
{
"group_title": "Python Basics",
"subject": "CS",
"description": "Looping, conditionals, and debugging practice for beginners.",
"date": "Oct 16",
"time": "6:00 PM",
"location": "Zoom",
"members": "12/20",
},
]
# -------------------------------------------------------------------------
# MY GROUPS MODULE: BigQuery-backed data loading
#
# This section fetches real "My Groups" data from BigQuery for the
# My Groups page only.
#
#
# Current test user:
# user-uuid-1
# -------------------------------------------------------------------------
current_user_id = "user-uuid-1"
try:
my_groups = get_my_groups(current_user_id)
except Exception as exc:
st.error(f"Unable to load My Groups: {exc}")
my_groups = []
# -------------------------------------------------------------------------
# USER PROFILE MODULE: BigQuery-backed data loading
#
# Fetches real profile data from the Users and GroupMemberships tables.
# -------------------------------------------------------------------------
try:
profile = get_user_profile(current_user_id)
except Exception as exc:
st.error(f"Unable to load User Profile: {exc}")
profile = None
sync_query_params()
# -------------------------------------------------------------------------
# PAGE ROUTING
#
# My contribution:
# - "My Groups" page uses BigQuery data through get_my_groups()
#
# Teammates' sections:
# - "Explore Groups"
# - "User Profile"
# - "AI Recommendations"
# -------------------------------------------------------------------------
page = st.session_state.page
u_id = st.session_state.get("user_id")
u_interests = st.session_state.get("about_me", "Computer Science")
if page == "Explore Groups":
filtered_list = navigation_bar(mock_study_groups, current_user_id)
display_explore_page(filtered_list)
elif page == "My Groups":
display_my_groups_page(my_groups)
elif page == "User Profile":
display_user_profile(profile)
elif page == "AI Recommendations":
display_genai_advice(user_id=u_id, user_interests=u_interests)
elif page == "Account Settings":
display_account_settings_page(u_id)
if __name__ == "__main__":
display_app_page()