MarcosRodrigo commited on
Commit
3d61091
·
verified ·
1 Parent(s): a6a14b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -4
app.py CHANGED
@@ -236,6 +236,43 @@ elif menu == "History":
236
  else:
237
  st.write("No history records found.")
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  # Graph view to display a line chart of item selections over time
240
  elif menu == "Graph":
241
  st.title("Breakfast Poll History - Graph View")
@@ -244,7 +281,8 @@ elif menu == "Graph":
244
  if st.session_state.history:
245
  history_data = []
246
  for record in st.session_state.history:
247
- date = record['Date']
 
248
  for index, row in record['Summary'].iterrows():
249
  for drink in row['Drinks'].split(', '):
250
  history_data.append({'Date': date, 'Item': drink, 'Type': 'Drink'})
@@ -257,9 +295,24 @@ elif menu == "Graph":
257
  # Count occurrences of each item per date
258
  item_counts = history_df.groupby(['Date', 'Item']).size().reset_index(name='Count')
259
 
260
- # Create a line plot for each item over time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  plt.figure(figsize=(12, 6))
262
- sns.lineplot(data=item_counts, x='Date', y='Count', hue='Item', marker='o')
263
 
264
  # Customize the plot
265
  plt.xticks(rotation=45)
@@ -271,4 +324,4 @@ elif menu == "Graph":
271
  # Display the plot
272
  st.pyplot(plt.gcf())
273
  else:
274
- st.write("No historical data available to plot.")
 
236
  else:
237
  st.write("No history records found.")
238
 
239
+ # # Graph view to display a line chart of item selections over time
240
+ # elif menu == "Graph":
241
+ # st.title("Breakfast Poll History - Graph View")
242
+
243
+ # # Prepare data for plotting
244
+ # if st.session_state.history:
245
+ # history_data = []
246
+ # for record in st.session_state.history:
247
+ # date = record['Date']
248
+ # for index, row in record['Summary'].iterrows():
249
+ # for drink in row['Drinks'].split(', '):
250
+ # history_data.append({'Date': date, 'Item': drink, 'Type': 'Drink'})
251
+ # for food in row['Food'].split(', '):
252
+ # history_data.append({'Date': date, 'Item': food, 'Type': 'Food'})
253
+
254
+ # # Create a DataFrame from history data
255
+ # history_df = pd.DataFrame(history_data)
256
+
257
+ # # Count occurrences of each item per date
258
+ # item_counts = history_df.groupby(['Date', 'Item']).size().reset_index(name='Count')
259
+
260
+ # # Create a line plot for each item over time
261
+ # plt.figure(figsize=(12, 6))
262
+ # sns.lineplot(data=item_counts, x='Date', y='Count', hue='Item', marker='o')
263
+
264
+ # # Customize the plot
265
+ # plt.xticks(rotation=45)
266
+ # plt.title('Item Selections Over Time')
267
+ # plt.xlabel('Date')
268
+ # plt.ylabel('Number of Selections')
269
+ # plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=3)
270
+
271
+ # # Display the plot
272
+ # st.pyplot(plt.gcf())
273
+ # else:
274
+ # st.write("No historical data available to plot.")
275
+
276
  # Graph view to display a line chart of item selections over time
277
  elif menu == "Graph":
278
  st.title("Breakfast Poll History - Graph View")
 
281
  if st.session_state.history:
282
  history_data = []
283
  for record in st.session_state.history:
284
+ # Extract only the date part (YYYY-MM-DD) for display
285
+ date = record['Date'].split("_")[0] # Use only the YYYY-MM-DD portion of the date
286
  for index, row in record['Summary'].iterrows():
287
  for drink in row['Drinks'].split(', '):
288
  history_data.append({'Date': date, 'Item': drink, 'Type': 'Drink'})
 
295
  # Count occurrences of each item per date
296
  item_counts = history_df.groupby(['Date', 'Item']).size().reset_index(name='Count')
297
 
298
+ # Get a list of unique items (Drinks and Food)
299
+ unique_items = item_counts['Item'].unique()
300
+
301
+ # Create a dictionary to store the checkbox values for each item
302
+ item_visibility = {}
303
+
304
+ st.sidebar.header("Select Items to Display")
305
+ # Create a checkbox for each unique item in the sidebar
306
+ for item in unique_items:
307
+ item_visibility[item] = st.sidebar.checkbox(item, value=True)
308
+
309
+ # Filter the data based on selected items
310
+ selected_items = [item for item, visible in item_visibility.items() if visible]
311
+ filtered_item_counts = item_counts[item_counts['Item'].isin(selected_items)]
312
+
313
+ # Create a line plot for each selected item over time
314
  plt.figure(figsize=(12, 6))
315
+ sns.lineplot(data=filtered_item_counts, x='Date', y='Count', hue='Item', marker='o')
316
 
317
  # Customize the plot
318
  plt.xticks(rotation=45)
 
324
  # Display the plot
325
  st.pyplot(plt.gcf())
326
  else:
327
+ st.write("No historical data available to plot.")