Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -240,12 +240,16 @@ elif menu == "History":
|
|
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 |
# # Extract only the date part (YYYY-MM-DD) for display
|
248 |
-
# date = record['Date']
|
249 |
# for index, row in record['Summary'].iterrows():
|
250 |
# for drink in row['Drinks'].split(', '):
|
251 |
# history_data.append({'Date': date, 'Item': drink, 'Type': 'Drink'})
|
@@ -313,18 +317,29 @@ elif menu == "Graph":
|
|
313 |
history_df = pd.DataFrame(history_data)
|
314 |
|
315 |
# Count occurrences of each item per date
|
316 |
-
item_counts = history_df.groupby(['Date', 'Item']).size().reset_index(name='Count')
|
317 |
|
318 |
-
#
|
319 |
-
|
|
|
320 |
|
321 |
# Create a dictionary to store the checkbox values for each item
|
322 |
item_visibility = {}
|
323 |
-
|
|
|
324 |
st.sidebar.header("Select Items to Display")
|
325 |
-
|
326 |
-
|
327 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
|
329 |
# Filter the data based on selected items
|
330 |
selected_items = [item for item, visible in item_visibility.items() if visible]
|
|
|
240 |
# elif menu == "Graph":
|
241 |
# st.title("Breakfast Poll History - Graph View")
|
242 |
|
243 |
+
# # Load the history if not already loaded
|
244 |
+
# if not st.session_state.history:
|
245 |
+
# st.session_state.history = load_history()
|
246 |
+
|
247 |
# # Prepare data for plotting
|
248 |
# if st.session_state.history:
|
249 |
# history_data = []
|
250 |
# for record in st.session_state.history:
|
251 |
# # Extract only the date part (YYYY-MM-DD) for display
|
252 |
+
# date = record['Date'].split("_")[0] # Use only the YYYY-MM-DD portion of the date
|
253 |
# for index, row in record['Summary'].iterrows():
|
254 |
# for drink in row['Drinks'].split(', '):
|
255 |
# history_data.append({'Date': date, 'Item': drink, 'Type': 'Drink'})
|
|
|
317 |
history_df = pd.DataFrame(history_data)
|
318 |
|
319 |
# Count occurrences of each item per date
|
320 |
+
item_counts = history_df.groupby(['Date', 'Item', 'Type']).size().reset_index(name='Count')
|
321 |
|
322 |
+
# Separate items into Drinks and Food, and sort them alphabetically
|
323 |
+
drinks = sorted(item_counts[item_counts['Type'] == 'Drink']['Item'].unique())
|
324 |
+
foods = sorted(item_counts[item_counts['Type'] == 'Food']['Item'].unique())
|
325 |
|
326 |
# Create a dictionary to store the checkbox values for each item
|
327 |
item_visibility = {}
|
328 |
+
|
329 |
+
# Create interactive checkboxes for Drinks and Food in the sidebar
|
330 |
st.sidebar.header("Select Items to Display")
|
331 |
+
|
332 |
+
# Drinks Section
|
333 |
+
if drinks:
|
334 |
+
st.sidebar.subheader("Drinks")
|
335 |
+
for item in drinks:
|
336 |
+
item_visibility[item] = st.sidebar.checkbox(item, value=True)
|
337 |
+
|
338 |
+
# Food Section
|
339 |
+
if foods:
|
340 |
+
st.sidebar.subheader("Food")
|
341 |
+
for item in foods:
|
342 |
+
item_visibility[item] = st.sidebar.checkbox(item, value=True)
|
343 |
|
344 |
# Filter the data based on selected items
|
345 |
selected_items = [item for item, visible in item_visibility.items() if visible]
|