deepakpathania commited on
Commit
d535eba
·
verified ·
1 Parent(s): 77f1879

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +354 -55
src/streamlit_app.py CHANGED
@@ -1,20 +1,176 @@
 
 
 
 
 
 
1
  # ---------------------------------------------------
2
- # ADD THIS SECTION AFTER load_data()
3
  # ---------------------------------------------------
4
 
 
 
 
 
 
 
5
  # SESSION STATE
 
6
 
7
  if "selected_page" not in st.session_state:
8
  st.session_state.selected_page = "Overview"
9
 
10
  if "selected_quarter" not in st.session_state:
11
- st.session_state.selected_quarter = "Q2 FY2024"
12
 
13
  if "compare_quarter" not in st.session_state:
14
- st.session_state.compare_quarter = "Q1 FY2024"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # ---------------------------------------------------
17
- # REPLACE ENTIRE SIDEBAR NAVIGATION SECTION WITH THIS
18
  # ---------------------------------------------------
19
 
20
  st.sidebar.markdown(
@@ -41,48 +197,39 @@ menu_items = [
41
 
42
  for item in menu_items:
43
 
44
- active = (
45
- "menu-item-active"
46
- if st.session_state.selected_page == item
47
- else "menu-item"
48
- )
49
-
50
- if st.sidebar.button(
51
- item,
52
- use_container_width=True,
53
- key=f"nav_{item}"
54
- ):
55
  st.session_state.selected_page = item
56
 
57
- st.sidebar.markdown(
58
- f"""
59
- <style>
60
-
61
- div[data-testid="stButton"] button {{
62
- background: rgba(10,15,30,0.75);
63
- border: 1px solid rgba(255,255,255,0.08);
64
- color: white;
65
- border-radius: 12px;
66
- padding: 12px;
67
- margin-bottom: 8px;
68
- text-align: left;
69
- font-size: 15px;
70
- }}
71
-
72
- div[data-testid="stButton"] button:hover {{
73
- background: #155EEF;
74
- color: white;
75
- border: 1px solid #155EEF;
76
- }}
77
-
78
- </style>
79
- """,
80
- unsafe_allow_html=True
81
- )
 
 
82
 
83
  # ---------------------------------------------------
84
- # TOP BAR FILTERS (WORKING)
85
- # REPLACE EXISTING TOP BAR SECTION
86
  # ---------------------------------------------------
87
 
88
  top1, top2, top3, top4 = st.columns([6,2,2,1])
@@ -146,7 +293,7 @@ with top4:
146
  )
147
 
148
  # ---------------------------------------------------
149
- # FILTER DATA USING TOP FILTER
150
  # ---------------------------------------------------
151
 
152
  filtered_df = filtered_df[
@@ -155,21 +302,173 @@ filtered_df = filtered_df[
155
  ]
156
 
157
  # ---------------------------------------------------
158
- # OPTIONAL PAGE CONTENT CONTROL
159
- # ADD BEFORE KPI SECTION
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  # ---------------------------------------------------
161
 
162
- if st.session_state.selected_page == "Overview":
163
- st.caption("Executive Product Analytics")
 
 
 
164
 
165
- elif st.session_state.selected_page == "Revenue":
166
- st.caption("Revenue Performance Analytics")
167
 
168
- elif st.session_state.selected_page == "Risk & Gaps":
169
- st.caption("Business Risk Analysis")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
- elif st.session_state.selected_page == "Customer Performance":
172
- st.caption("Customer Insights Dashboard")
173
 
174
- else:
175
- st.caption(f"{st.session_state.selected_page} Dashboard")
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import plotly.graph_objects as go
5
+ import os
6
+
7
  # ---------------------------------------------------
8
+ # PAGE CONFIG
9
  # ---------------------------------------------------
10
 
11
+ st.set_page_config(
12
+ page_title="Product Performance Dashboard",
13
+ layout="wide"
14
+ )
15
+
16
+ # ---------------------------------------------------
17
  # SESSION STATE
18
+ # ---------------------------------------------------
19
 
20
  if "selected_page" not in st.session_state:
21
  st.session_state.selected_page = "Overview"
22
 
23
  if "selected_quarter" not in st.session_state:
24
+ st.session_state.selected_quarter = "Q2-2024"
25
 
26
  if "compare_quarter" not in st.session_state:
27
+ st.session_state.compare_quarter = "Q1-2024"
28
+
29
+ # ---------------------------------------------------
30
+ # LOAD DATA
31
+ # ---------------------------------------------------
32
+
33
+ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
34
+
35
+ excel_path = os.path.join(
36
+ BASE_DIR,
37
+ "weekly_synthetic_product_performance_dashboard.xlsx"
38
+ )
39
+
40
+ @st.cache_data
41
+ def load_data():
42
+ return pd.read_excel(excel_path)
43
+
44
+ df = load_data()
45
+
46
+ # ---------------------------------------------------
47
+ # CUSTOM CSS
48
+ # ---------------------------------------------------
49
+
50
+ st.markdown("""
51
+ <style>
52
+
53
+ html, body, [class*="css"] {
54
+ font-family: 'Inter', sans-serif;
55
+ }
56
+
57
+ .main {
58
+ background: linear-gradient(180deg,#050816,#071224);
59
+ }
60
+
61
+ .block-container {
62
+ padding-top: 1rem;
63
+ padding-left: 1.5rem;
64
+ padding-right: 1.5rem;
65
+ max-width: 100%;
66
+ }
67
+
68
+ section[data-testid="stSidebar"] {
69
+ background: #0A1020;
70
+ border-right: 1px solid rgba(255,255,255,0.08);
71
+ width: 270px !important;
72
+ }
73
+
74
+ /* Sidebar Buttons */
75
+
76
+ div[data-testid="stButton"] button {
77
+ background: rgba(10,15,30,0.75);
78
+ border: 1px solid rgba(255,255,255,0.08);
79
+ color: white;
80
+ border-radius: 12px;
81
+ padding: 14px;
82
+ margin-bottom: 10px;
83
+ text-align: left;
84
+ font-size: 15px;
85
+ width: 100%;
86
+ }
87
+
88
+ div[data-testid="stButton"] button:hover {
89
+ background: #155EEF;
90
+ color: white;
91
+ border: 1px solid #155EEF;
92
+ }
93
+
94
+ /* Dashboard Title */
95
+
96
+ .dashboard-title {
97
+ color: white;
98
+ font-size: 52px;
99
+ font-weight: 700;
100
+ }
101
+
102
+ .dashboard-subtitle {
103
+ color: #A1A1AA;
104
+ font-size: 18px;
105
+ margin-bottom: 20px;
106
+ }
107
+
108
+ /* KPI Cards */
109
+
110
+ .kpi-card {
111
+ background: rgba(10,15,30,0.75);
112
+ border: 1px solid rgba(255,255,255,0.08);
113
+ border-radius: 18px;
114
+ padding: 20px;
115
+ min-height: 120px;
116
+ backdrop-filter: blur(12px);
117
+ }
118
+
119
+ .kpi-title {
120
+ color: #D1D5DB;
121
+ font-size: 15px;
122
+ }
123
+
124
+ .kpi-value {
125
+ color: white;
126
+ font-size: 42px;
127
+ font-weight: 700;
128
+ margin-top: 10px;
129
+ }
130
+
131
+ .kpi-change {
132
+ color: #22C55E;
133
+ font-size: 14px;
134
+ margin-top: 8px;
135
+ }
136
+
137
+ /* Chart Cards */
138
+
139
+ .chart-card {
140
+ background: rgba(10,15,30,0.75);
141
+ border: 1px solid rgba(255,255,255,0.08);
142
+ border-radius: 18px;
143
+ padding: 20px;
144
+ margin-top: 18px;
145
+ backdrop-filter: blur(12px);
146
+ }
147
+
148
+ /* Insight Cards */
149
+
150
+ .insight-card {
151
+ background: rgba(10,15,30,0.75);
152
+ border: 1px solid rgba(255,255,255,0.08);
153
+ border-radius: 16px;
154
+ padding: 16px;
155
+ margin-bottom: 12px;
156
+ color: white;
157
+ font-size: 14px;
158
+ }
159
+
160
+ /* Top Filters */
161
+
162
+ .top-filter {
163
+ background: rgba(10,15,30,0.75);
164
+ border: 1px solid rgba(255,255,255,0.12);
165
+ border-radius: 12px;
166
+ padding: 12px;
167
+ }
168
+
169
+ </style>
170
+ """, unsafe_allow_html=True)
171
 
172
  # ---------------------------------------------------
173
+ # SIDEBAR
174
  # ---------------------------------------------------
175
 
176
  st.sidebar.markdown(
 
197
 
198
  for item in menu_items:
199
 
200
+ if st.sidebar.button(item):
 
 
 
 
 
 
 
 
 
 
201
  st.session_state.selected_page = item
202
 
203
+ # ---------------------------------------------------
204
+ # FILTERS
205
+ # ---------------------------------------------------
206
+
207
+ quarter_filter = st.sidebar.multiselect(
208
+ "Quarter",
209
+ df["Quarter"].unique(),
210
+ default=df["Quarter"].unique()
211
+ )
212
+
213
+ customer_filter = st.sidebar.multiselect(
214
+ "Customer",
215
+ df["Customer Name"].unique(),
216
+ default=df["Customer Name"].unique()
217
+ )
218
+
219
+ risk_filter = st.sidebar.multiselect(
220
+ "Business Risk",
221
+ df["Overall Business Risk"].unique(),
222
+ default=df["Overall Business Risk"].unique()
223
+ )
224
+
225
+ filtered_df = df[
226
+ (df["Quarter"].isin(quarter_filter)) &
227
+ (df["Customer Name"].isin(customer_filter)) &
228
+ (df["Overall Business Risk"].isin(risk_filter))
229
+ ].copy()
230
 
231
  # ---------------------------------------------------
232
+ # TOP BAR
 
233
  # ---------------------------------------------------
234
 
235
  top1, top2, top3, top4 = st.columns([6,2,2,1])
 
293
  )
294
 
295
  # ---------------------------------------------------
296
+ # FILTER BY TOP QUARTER
297
  # ---------------------------------------------------
298
 
299
  filtered_df = filtered_df[
 
302
  ]
303
 
304
  # ---------------------------------------------------
305
+ # KPI VALUES
306
+ # ---------------------------------------------------
307
+
308
+ revenue = filtered_df["Revenue (USD)"].sum()
309
+
310
+ product_score = filtered_df[
311
+ "Product Performance Score"
312
+ ].mean()
313
+
314
+ engagement = filtered_df[
315
+ "Engagement Score"
316
+ ].mean()
317
+
318
+ sentiment = filtered_df[
319
+ "Sentiment Score"
320
+ ].mean()
321
+
322
+ satisfaction = filtered_df[
323
+ "Satisfaction Score"
324
+ ].mean()
325
+
326
+ # ---------------------------------------------------
327
+ # KPI ROW
328
+ # ---------------------------------------------------
329
+
330
+ k1, k2, k3, k4, k5, k6 = st.columns(6)
331
+
332
+ cards = [
333
+ ("Total Revenue", f"${revenue/1000000:.1f}M"),
334
+ ("Product Performance Score", f"{product_score:.1f}"),
335
+ ("Engagement Score", f"{engagement:.1f}"),
336
+ ("Sentiment Score", f"{sentiment:.1f}"),
337
+ ("Satisfaction Score", f"{satisfaction:.1f}"),
338
+ ("Overall Business Risk", "Medium")
339
+ ]
340
+
341
+ for col, (title, value) in zip(
342
+ [k1, k2, k3, k4, k5, k6],
343
+ cards
344
+ ):
345
+
346
+ with col:
347
+
348
+ st.markdown(f"""
349
+ <div class="kpi-card">
350
+ <div class="kpi-title">{title}</div>
351
+ <div class="kpi-value">{value}</div>
352
+ <div class="kpi-change">↑ Improved vs last quarter</div>
353
+ </div>
354
+ """, unsafe_allow_html=True)
355
+
356
+ # ---------------------------------------------------
357
+ # ROW 1
358
  # ---------------------------------------------------
359
 
360
+ r1c1, r1c2, r1c3 = st.columns([2,1.5,2])
361
+
362
+ with r1c1:
363
+
364
+ st.markdown('<div class="chart-card">', unsafe_allow_html=True)
365
 
366
+ st.subheader("Product Performance Score Trend")
 
367
 
368
+ trend_df = filtered_df.groupby(
369
+ "Quarter"
370
+ )["Product Performance Score"].mean().reset_index()
371
+
372
+ fig = px.line(
373
+ trend_df,
374
+ x="Quarter",
375
+ y="Product Performance Score",
376
+ markers=True,
377
+ template="plotly_dark"
378
+ )
379
+
380
+ fig.update_layout(
381
+ paper_bgcolor='rgba(0,0,0,0)',
382
+ plot_bgcolor='rgba(0,0,0,0)',
383
+ height=350
384
+ )
385
+
386
+ st.plotly_chart(fig, use_container_width=True)
387
+
388
+ st.markdown('</div>', unsafe_allow_html=True)
389
+
390
+ with r1c2:
391
+
392
+ st.markdown('<div class="chart-card">', unsafe_allow_html=True)
393
+
394
+ st.subheader("Score Breakdown")
395
+
396
+ donut_df = pd.DataFrame({
397
+ "Category": [
398
+ "Engagement",
399
+ "Sentiment",
400
+ "Satisfaction"
401
+ ],
402
+ "Value": [
403
+ engagement,
404
+ abs(sentiment)*10,
405
+ abs(satisfaction)*10
406
+ ]
407
+ })
408
+
409
+ fig2 = px.pie(
410
+ donut_df,
411
+ names="Category",
412
+ values="Value",
413
+ hole=0.7,
414
+ template="plotly_dark"
415
+ )
416
+
417
+ fig2.update_layout(
418
+ paper_bgcolor='rgba(0,0,0,0)',
419
+ height=350
420
+ )
421
+
422
+ st.plotly_chart(fig2, use_container_width=True)
423
+
424
+ st.markdown('</div>', unsafe_allow_html=True)
425
+
426
+ with r1c3:
427
+
428
+ st.markdown('<div class="chart-card">', unsafe_allow_html=True)
429
+
430
+ st.subheader("Performance Scores Over Time")
431
+
432
+ perf_df = filtered_df.groupby(
433
+ "Quarter"
434
+ )[
435
+ [
436
+ "Build Performance",
437
+ "Simulation Performance",
438
+ "Engagement Score"
439
+ ]
440
+ ].mean().reset_index()
441
+
442
+ fig3 = go.Figure()
443
+
444
+ fig3.add_trace(go.Scatter(
445
+ x=perf_df["Quarter"],
446
+ y=perf_df["Build Performance"],
447
+ mode='lines+markers',
448
+ name='Build'
449
+ ))
450
+
451
+ fig3.add_trace(go.Scatter(
452
+ x=perf_df["Quarter"],
453
+ y=perf_df["Simulation Performance"],
454
+ mode='lines+markers',
455
+ name='Simulation'
456
+ ))
457
+
458
+ fig3.add_trace(go.Scatter(
459
+ x=perf_df["Quarter"],
460
+ y=perf_df["Engagement Score"],
461
+ mode='lines+markers',
462
+ name='Engagement'
463
+ ))
464
+
465
+ fig3.update_layout(
466
+ template="plotly_dark",
467
+ paper_bgcolor='rgba(0,0,0,0)',
468
+ plot_bgcolor='rgba(0,0,0,0)',
469
+ height=350
470
+ )
471
 
472
+ st.plotly_chart(fig3, use_container_width=True)
 
473
 
474
+ st.markdown('</div>', unsafe_allow_html=True)