deepakpathania commited on
Commit
7071a82
·
verified ·
1 Parent(s): 2747fc4

Upload src/app.py

Browse files

added app.py to src folder.

Files changed (1) hide show
  1. src/app.py +285 -0
src/app.py ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import plotly.express as px
4
+ import plotly.graph_objects as go
5
+
6
+ # -----------------------------------
7
+ # PAGE CONFIG
8
+ # -----------------------------------
9
+
10
+ st.set_page_config(
11
+ page_title="Product Performance Dashboard",
12
+ layout="wide"
13
+ )
14
+
15
+ # -----------------------------------
16
+ # LOAD DATA
17
+ # -----------------------------------
18
+
19
+ @st.cache_data
20
+ def load_data():
21
+ df = pd.read_excel(
22
+ "weekly_synthetic_product_performance_dashboard.xlsx"
23
+ )
24
+ return df
25
+
26
+ df = load_data()
27
+
28
+ # -----------------------------------
29
+ # SIDEBAR
30
+ # -----------------------------------
31
+
32
+ st.sidebar.title("Executive Filters")
33
+
34
+ quarter_filter = st.sidebar.multiselect(
35
+ "Quarter",
36
+ df["Quarter"].unique(),
37
+ default=df["Quarter"].unique()
38
+ )
39
+
40
+ customer_filter = st.sidebar.multiselect(
41
+ "Customer",
42
+ df["Customer Name"].unique(),
43
+ default=df["Customer Name"].unique()
44
+ )
45
+
46
+ risk_filter = st.sidebar.multiselect(
47
+ "Risk",
48
+ df["Overall Business Risk"].unique(),
49
+ default=df["Overall Business Risk"].unique()
50
+ )
51
+
52
+ filtered_df = df[
53
+ (df["Quarter"].isin(quarter_filter)) &
54
+ (df["Customer Name"].isin(customer_filter)) &
55
+ (df["Overall Business Risk"].isin(risk_filter))
56
+ ]
57
+
58
+ # -----------------------------------
59
+ # KPI CALCULATIONS
60
+ # -----------------------------------
61
+
62
+ revenue = filtered_df["Revenue (USD)"].sum()
63
+
64
+ product_score = filtered_df[
65
+ "Product Performance Score"
66
+ ].mean()
67
+
68
+ engagement = filtered_df[
69
+ "Engagement Score"
70
+ ].mean()
71
+
72
+ sentiment = filtered_df[
73
+ "Sentiment Score"
74
+ ].mean()
75
+
76
+ satisfaction = filtered_df[
77
+ "Satisfaction Score"
78
+ ].mean()
79
+
80
+ high_risk = len(
81
+ filtered_df[
82
+ filtered_df["Overall Business Risk"] == "High"
83
+ ]
84
+ )
85
+
86
+ # -----------------------------------
87
+ # HEADER
88
+ # -----------------------------------
89
+
90
+ st.title("Product Performance Dashboard")
91
+ st.caption("Executive Product Analytics")
92
+
93
+ # -----------------------------------
94
+ # KPI ROW
95
+ # -----------------------------------
96
+
97
+ k1, k2, k3, k4, k5, k6 = st.columns(6)
98
+
99
+ k1.metric("Revenue", f"${revenue:,.0f}")
100
+ k2.metric("Product Score", f"{product_score:.1f}")
101
+ k3.metric("Engagement", f"{engagement:.1f}")
102
+ k4.metric("Sentiment", f"{sentiment:.1f}")
103
+ k5.metric("Satisfaction", f"{satisfaction:.1f}")
104
+ k6.metric("High Risk", high_risk)
105
+
106
+ # -----------------------------------
107
+ # TREND SECTION
108
+ # -----------------------------------
109
+
110
+ c1, c2 = st.columns(2)
111
+
112
+ with c1:
113
+
114
+ st.subheader("Product Performance Trend")
115
+
116
+ trend_df = filtered_df.groupby(
117
+ "Week Start Date"
118
+ )["Product Performance Score"].mean().reset_index()
119
+
120
+ fig = px.line(
121
+ trend_df,
122
+ x="Week Start Date",
123
+ y="Product Performance Score",
124
+ markers=True
125
+ )
126
+
127
+ st.plotly_chart(fig, use_container_width=True)
128
+
129
+ with c2:
130
+
131
+ st.subheader("Revenue Trend")
132
+
133
+ rev_df = filtered_df.groupby(
134
+ "Quarter"
135
+ )["Revenue (USD)"].sum().reset_index()
136
+
137
+ fig2 = px.bar(
138
+ rev_df,
139
+ x="Quarter",
140
+ y="Revenue (USD)"
141
+ )
142
+
143
+ st.plotly_chart(fig2, use_container_width=True)
144
+
145
+ # -----------------------------------
146
+ # PERFORMANCE SECTION
147
+ # -----------------------------------
148
+
149
+ c3, c4 = st.columns(2)
150
+
151
+ with c3:
152
+
153
+ st.subheader("Performance Metrics")
154
+
155
+ perf_df = filtered_df.groupby(
156
+ "Week Start Date"
157
+ )[
158
+ [
159
+ "Build Performance",
160
+ "Simulation Performance",
161
+ "Engagement Score"
162
+ ]
163
+ ].mean().reset_index()
164
+
165
+ fig3 = go.Figure()
166
+
167
+ fig3.add_trace(go.Scatter(
168
+ x=perf_df["Week Start Date"],
169
+ y=perf_df["Build Performance"],
170
+ mode='lines',
171
+ name='Build'
172
+ ))
173
+
174
+ fig3.add_trace(go.Scatter(
175
+ x=perf_df["Week Start Date"],
176
+ y=perf_df["Simulation Performance"],
177
+ mode='lines',
178
+ name='Simulation'
179
+ ))
180
+
181
+ fig3.add_trace(go.Scatter(
182
+ x=perf_df["Week Start Date"],
183
+ y=perf_df["Engagement Score"],
184
+ mode='lines',
185
+ name='Engagement'
186
+ ))
187
+
188
+ st.plotly_chart(fig3, use_container_width=True)
189
+
190
+ with c4:
191
+
192
+ st.subheader("Business Risk Distribution")
193
+
194
+ risk_df = filtered_df[
195
+ "Overall Business Risk"
196
+ ].value_counts().reset_index()
197
+
198
+ risk_df.columns = ["Risk", "Count"]
199
+
200
+ fig4 = px.pie(
201
+ risk_df,
202
+ names="Risk",
203
+ values="Count",
204
+ hole=0.5
205
+ )
206
+
207
+ st.plotly_chart(fig4, use_container_width=True)
208
+
209
+ # -----------------------------------
210
+ # GAP ANALYSIS
211
+ # -----------------------------------
212
+
213
+ st.subheader("Gap vs OT Distribution")
214
+
215
+ filtered_df["Gap Category"] = filtered_df[
216
+ "Gap vs OT (%)"
217
+ ].apply(
218
+ lambda x:
219
+ "High" if x > 15 else
220
+ "Medium" if x >= 5 else
221
+ "Low"
222
+ )
223
+
224
+ gap_df = filtered_df[
225
+ "Gap Category"
226
+ ].value_counts().reset_index()
227
+
228
+ gap_df.columns = ["Gap", "Count"]
229
+
230
+ fig5 = px.pie(
231
+ gap_df,
232
+ names="Gap",
233
+ values="Count",
234
+ hole=0.5
235
+ )
236
+
237
+ st.plotly_chart(fig5, use_container_width=True)
238
+
239
+ # -----------------------------------
240
+ # CUSTOMER TABLE
241
+ # -----------------------------------
242
+
243
+ st.subheader("Customer Performance Table")
244
+
245
+ cols = [
246
+ "Quarter",
247
+ "Week Start Date",
248
+ "Customer Name",
249
+ "Build Performance",
250
+ "Simulation Performance",
251
+ "Engagement Score",
252
+ "Sentiment Score",
253
+ "Satisfaction Score",
254
+ "Product Performance Score",
255
+ "Gap vs OT (%)",
256
+ "Overall Business Risk",
257
+ "Revenue (USD)"
258
+ ]
259
+
260
+ st.dataframe(
261
+ filtered_df[cols],
262
+ use_container_width=True
263
+ )
264
+
265
+ # -----------------------------------
266
+ # EXECUTIVE INSIGHTS
267
+ # -----------------------------------
268
+
269
+ st.subheader("Executive Insights")
270
+
271
+ best_customer = filtered_df.groupby(
272
+ "Customer Name"
273
+ )["Product Performance Score"].mean().idxmax()
274
+
275
+ worst_customer = filtered_df.groupby(
276
+ "Customer Name"
277
+ )["Product Performance Score"].mean().idxmin()
278
+
279
+ st.success(
280
+ f"Top Performing Customer: {best_customer}"
281
+ )
282
+
283
+ st.warning(
284
+ f"Customer Requiring Attention: {worst_customer}"
285
+ )