Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -244,6 +244,7 @@ elif menu == "History":
|
|
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(', '):
|
@@ -257,9 +258,24 @@ elif menu == "History":
|
|
257 |
# # Count occurrences of each item per date
|
258 |
# item_counts = history_df.groupby(['Date', 'Item']).size().reset_index(name='Count')
|
259 |
|
260 |
-
# #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
# plt.figure(figsize=(12, 6))
|
262 |
-
# sns.lineplot(data=
|
263 |
|
264 |
# # Customize the plot
|
265 |
# plt.xticks(rotation=45)
|
@@ -277,12 +293,16 @@ elif menu == "History":
|
|
277 |
elif menu == "Graph":
|
278 |
st.title("Breakfast Poll History - Graph View")
|
279 |
|
|
|
|
|
|
|
|
|
280 |
# Prepare data for plotting
|
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']
|
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'})
|
@@ -324,4 +344,4 @@ elif menu == "Graph":
|
|
324 |
# Display the plot
|
325 |
st.pyplot(plt.gcf())
|
326 |
else:
|
327 |
-
st.write("No historical data available to plot.")
|
|
|
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(', '):
|
|
|
258 |
# # Count occurrences of each item per date
|
259 |
# item_counts = history_df.groupby(['Date', 'Item']).size().reset_index(name='Count')
|
260 |
|
261 |
+
# # Get a list of unique items (Drinks and Food)
|
262 |
+
# unique_items = item_counts['Item'].unique()
|
263 |
+
|
264 |
+
# # Create a dictionary to store the checkbox values for each item
|
265 |
+
# item_visibility = {}
|
266 |
+
|
267 |
+
# st.sidebar.header("Select Items to Display")
|
268 |
+
# # Create a checkbox for each unique item in the sidebar
|
269 |
+
# for item in unique_items:
|
270 |
+
# item_visibility[item] = st.sidebar.checkbox(item, value=True)
|
271 |
+
|
272 |
+
# # Filter the data based on selected items
|
273 |
+
# selected_items = [item for item, visible in item_visibility.items() if visible]
|
274 |
+
# filtered_item_counts = item_counts[item_counts['Item'].isin(selected_items)]
|
275 |
+
|
276 |
+
# # Create a line plot for each selected item over time
|
277 |
# plt.figure(figsize=(12, 6))
|
278 |
+
# sns.lineplot(data=filtered_item_counts, x='Date', y='Count', hue='Item', marker='o')
|
279 |
|
280 |
# # Customize the plot
|
281 |
# plt.xticks(rotation=45)
|
|
|
293 |
elif menu == "Graph":
|
294 |
st.title("Breakfast Poll History - Graph View")
|
295 |
|
296 |
+
# Load the history if not already loaded
|
297 |
+
if not st.session_state.history:
|
298 |
+
st.session_state.history = load_history()
|
299 |
+
|
300 |
# Prepare data for plotting
|
301 |
if st.session_state.history:
|
302 |
history_data = []
|
303 |
for record in st.session_state.history:
|
304 |
# Extract only the date part (YYYY-MM-DD) for display
|
305 |
+
date = record['Date'].split("_")[0] # Use only the YYYY-MM-DD portion of the date
|
306 |
for index, row in record['Summary'].iterrows():
|
307 |
for drink in row['Drinks'].split(', '):
|
308 |
history_data.append({'Date': date, 'Item': drink, 'Type': 'Drink'})
|
|
|
344 |
# Display the plot
|
345 |
st.pyplot(plt.gcf())
|
346 |
else:
|
347 |
+
st.write("No historical data available to plot.")
|