ProtonDataLabs commited on
Commit
2a243f7
1 Parent(s): 564fdbc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -152,7 +152,7 @@ st.write(f"Data loaded in {time_taken:.2f} seconds")
152
  ############################################ CARD #1 ####################################################
153
  if st.session_state['active_card'] == 'card1':
154
  # Step 1: Sales Volume vs FyWeek for the whole dataset (no filter)
155
- st.subheader("Total Sales Volume vs Fiscal Week")
156
  df['FY_Week'] = df['FY'].astype(str) + '_' + df['Week'].astype(str)
157
  # Split FY_Week again for correct sorting
158
  if not df.empty and 'FY_Week' in df.columns:
@@ -163,13 +163,12 @@ if st.session_state['active_card'] == 'card1':
163
 
164
  # Create a line chart using Plotly
165
  fig = px.line(total_sales_df, x='FY_Week', y='SalesVolume',
166
- title='Total Sales Volume vs Fiscal Week',
167
  labels={'SalesVolume': 'Sales Volume', 'FY_Week': 'Fiscal Week'})
168
  st.plotly_chart(fig)
169
 
170
  # Step 2: Top 3 states based on sales volume as buttons/cards
171
  top_states = df.groupby('State', observed=True)['SalesVolume'].sum().nlargest(3).index
172
- st.write("### Top 3 Selling States :")
173
  col1, col2, col3 = st.columns(3)
174
  if len(top_states) > 0 and col1.button(top_states[0]):
175
  st.session_state['selected_state'] = top_states[0]
@@ -183,7 +182,7 @@ if st.session_state['active_card'] == 'card1':
183
  selected_state = st.session_state['selected_state']
184
 
185
  # Step 3: Sales volume vs FyWeek for the selected state
186
- st.subheader(f"Sales Volume vs Fiscal Week for {selected_state}")
187
  state_sales_df = df[df['State'] == selected_state].groupby('FY_Week', observed=True)['SalesVolume'].sum().reset_index()
188
 
189
  if not state_sales_df.empty and 'FY_Week' in state_sales_df.columns:
@@ -192,7 +191,6 @@ if st.session_state['active_card'] == 'card1':
192
  state_sales_df = state_sales_df.sort_values(by=['FY', 'Week'])
193
 
194
  fig = px.line(state_sales_df, x='FY_Week', y='SalesVolume',
195
- title=f'Sales Volume vs Fiscal Week in {selected_state}',
196
  labels={'SalesVolume': 'Sales Volume', 'FY_Week': 'Fiscal Week'})
197
  st.plotly_chart(fig)
198
 
@@ -214,7 +212,7 @@ if st.session_state['active_card'] == 'card1':
214
  selected_chaincode = st.session_state['selected_chaincode']
215
 
216
  # Step 5: Sales volume vs FyWeek for the selected chaincode in the selected state
217
- st.subheader(f"Sales Volume vs Fiscal Week for {selected_chaincode} in {selected_state}")
218
  chain_sales_df = df[(df['State'] == selected_state) & (df['Chaincode'] == selected_chaincode)].groupby('FY_Week', observed=True)['SalesVolume'].sum().reset_index()
219
 
220
  if not chain_sales_df.empty and 'FY_Week' in chain_sales_df.columns:
@@ -223,13 +221,13 @@ if st.session_state['active_card'] == 'card1':
223
  chain_sales_df = chain_sales_df.sort_values(by=['FY', 'Week'])
224
 
225
  fig = px.line(chain_sales_df, x='FY_Week', y='SalesVolume',
226
- title=f'Sales Volume vs Fiscal Week in {selected_chaincode}, {selected_state}',
227
  labels={'SalesVolume': 'Sales Volume', 'FY_Week': 'Fiscal Week'})
228
  st.plotly_chart(fig)
229
 
230
  # Step 6: Top 3 itemtypes based on sales volume as buttons/cards
231
  top_itemtypes = df[(df['State'] == selected_state) & (df['Chaincode'] == selected_chaincode)].groupby('Itemtype', observed=True)['SalesVolume'].sum().nlargest(3).index
232
- st.write(f"### Top Itemtype in {selected_chaincode}, {selected_state}:")
233
 
234
  col1, col2, col3 = st.columns(3)
235
  if len(top_itemtypes) > 0 and col1.button(top_itemtypes[0]):
@@ -244,7 +242,7 @@ if st.session_state['active_card'] == 'card1':
244
  selected_itemtype = st.session_state['selected_itemtype']
245
 
246
  # Step 7: Dual-axis plot for Sales volume and UnitPrice vs FyWeek for the selected itemtype
247
- st.subheader(f"Sales Volume & Unit Price vs Fiscal Week for {selected_itemtype} in {selected_chaincode}, {selected_state}")
248
  item_sales_df = df[(df['State'] == selected_state) & (df['Chaincode'] == selected_chaincode) & (df['Itemtype'] == selected_itemtype)].groupby('FY_Week', observed=True).agg({
249
  'SalesVolume': 'sum',
250
  'UnitPrice': 'mean'
@@ -280,7 +278,7 @@ if st.session_state['active_card'] == 'card1':
280
 
281
  # Update layout for dual axes
282
  fig.update_layout(
283
- title=f"Sales Volume & Unit Price vs Fiscal Week in {selected_itemtype}, {selected_chaincode}, {selected_state}",
284
  xaxis_title='Fiscal Week',
285
  yaxis_title='Sales Volume',
286
  yaxis2=dict(title='Unit Price', overlaying='y', side='right'),
 
152
  ############################################ CARD #1 ####################################################
153
  if st.session_state['active_card'] == 'card1':
154
  # Step 1: Sales Volume vs FyWeek for the whole dataset (no filter)
155
+ st.subheader("Total Sales Volume by Fiscal Week")
156
  df['FY_Week'] = df['FY'].astype(str) + '_' + df['Week'].astype(str)
157
  # Split FY_Week again for correct sorting
158
  if not df.empty and 'FY_Week' in df.columns:
 
163
 
164
  # Create a line chart using Plotly
165
  fig = px.line(total_sales_df, x='FY_Week', y='SalesVolume',
 
166
  labels={'SalesVolume': 'Sales Volume', 'FY_Week': 'Fiscal Week'})
167
  st.plotly_chart(fig)
168
 
169
  # Step 2: Top 3 states based on sales volume as buttons/cards
170
  top_states = df.groupby('State', observed=True)['SalesVolume'].sum().nlargest(3).index
171
+ st.write("### Top 3 Selling States in the last 4 years (drill down by state)")
172
  col1, col2, col3 = st.columns(3)
173
  if len(top_states) > 0 and col1.button(top_states[0]):
174
  st.session_state['selected_state'] = top_states[0]
 
182
  selected_state = st.session_state['selected_state']
183
 
184
  # Step 3: Sales volume vs FyWeek for the selected state
185
+ st.subheader(f"Sales Volume by Fiscal Week for {selected_state} (drill down by Chaincode) ")
186
  state_sales_df = df[df['State'] == selected_state].groupby('FY_Week', observed=True)['SalesVolume'].sum().reset_index()
187
 
188
  if not state_sales_df.empty and 'FY_Week' in state_sales_df.columns:
 
191
  state_sales_df = state_sales_df.sort_values(by=['FY', 'Week'])
192
 
193
  fig = px.line(state_sales_df, x='FY_Week', y='SalesVolume',
 
194
  labels={'SalesVolume': 'Sales Volume', 'FY_Week': 'Fiscal Week'})
195
  st.plotly_chart(fig)
196
 
 
212
  selected_chaincode = st.session_state['selected_chaincode']
213
 
214
  # Step 5: Sales volume vs FyWeek for the selected chaincode in the selected state
215
+ st.subheader(f"Sales Volume by Fiscal Week for {selected_chaincode} in {selected_state}")
216
  chain_sales_df = df[(df['State'] == selected_state) & (df['Chaincode'] == selected_chaincode)].groupby('FY_Week', observed=True)['SalesVolume'].sum().reset_index()
217
 
218
  if not chain_sales_df.empty and 'FY_Week' in chain_sales_df.columns:
 
221
  chain_sales_df = chain_sales_df.sort_values(by=['FY', 'Week'])
222
 
223
  fig = px.line(chain_sales_df, x='FY_Week', y='SalesVolume',
224
+ # title=f'Sales Volume vs Fiscal Week in {selected_chaincode}, {selected_state}',
225
  labels={'SalesVolume': 'Sales Volume', 'FY_Week': 'Fiscal Week'})
226
  st.plotly_chart(fig)
227
 
228
  # Step 6: Top 3 itemtypes based on sales volume as buttons/cards
229
  top_itemtypes = df[(df['State'] == selected_state) & (df['Chaincode'] == selected_chaincode)].groupby('Itemtype', observed=True)['SalesVolume'].sum().nlargest(3).index
230
+ st.write(f"### Top Item Type in {selected_chaincode}, {selected_state} (drill down by ItemType) :")
231
 
232
  col1, col2, col3 = st.columns(3)
233
  if len(top_itemtypes) > 0 and col1.button(top_itemtypes[0]):
 
242
  selected_itemtype = st.session_state['selected_itemtype']
243
 
244
  # Step 7: Dual-axis plot for Sales volume and UnitPrice vs FyWeek for the selected itemtype
245
+ # st.subheader(f"Sales Volume & Unit Price vs Fiscal Week for {selected_itemtype} in {selected_chaincode}, {selected_state}")
246
  item_sales_df = df[(df['State'] == selected_state) & (df['Chaincode'] == selected_chaincode) & (df['Itemtype'] == selected_itemtype)].groupby('FY_Week', observed=True).agg({
247
  'SalesVolume': 'sum',
248
  'UnitPrice': 'mean'
 
278
 
279
  # Update layout for dual axes
280
  fig.update_layout(
281
+ title=f"Sales Volume vs Unit Price by Fiscal Week for {selected_itemtype}, {selected_chaincode}, {selected_state}",
282
  xaxis_title='Fiscal Week',
283
  yaxis_title='Sales Volume',
284
  yaxis2=dict(title='Unit Price', overlaying='y', side='right'),