Spaces:
Running
Running
MarcosRodrigo
commited on
Commit
•
66e70a0
1
Parent(s):
1d0335d
Update app.py
Browse files
app.py
CHANGED
@@ -196,7 +196,29 @@ elif menu == "History":
|
|
196 |
else:
|
197 |
st.write("No history records found.")
|
198 |
|
199 |
-
# "Current" view to display the current summary of all users' selections and submit to history
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
elif menu == "Current":
|
201 |
st.title("Current Selections of All Users")
|
202 |
if st.button("Reload Selections"):
|
@@ -204,21 +226,70 @@ elif menu == "Current":
|
|
204 |
current_df = load_current_selections()
|
205 |
st.table(current_df)
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
|
223 |
# History view to check past summaries
|
224 |
elif menu == "History":
|
@@ -236,76 +307,6 @@ 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")
|
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']
|
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'})
|
256 |
-
# for food in row['Food'].split(', '):
|
257 |
-
# history_data.append({'Date': date, 'Item': food, 'Type': 'Food'})
|
258 |
-
|
259 |
-
# # Create a DataFrame from history data
|
260 |
-
# history_df = pd.DataFrame(history_data)
|
261 |
-
|
262 |
-
# # Count occurrences of each item per date
|
263 |
-
# item_counts = history_df.groupby(['Date', 'Item', 'Type']).size().reset_index(name='Count')
|
264 |
-
|
265 |
-
# # Separate items into Drinks and Food, and sort them alphabetically
|
266 |
-
# drinks = sorted(item_counts[item_counts['Type'] == 'Drink']['Item'].unique())
|
267 |
-
# foods = sorted(item_counts[item_counts['Type'] == 'Food']['Item'].unique())
|
268 |
-
|
269 |
-
# # Create a dictionary to store the checkbox values for each item
|
270 |
-
# item_visibility = {}
|
271 |
-
|
272 |
-
# # Create interactive checkboxes for Drinks and Food in the sidebar
|
273 |
-
# st.sidebar.header("Select Items to Display")
|
274 |
-
|
275 |
-
# # Drinks Section
|
276 |
-
# if drinks:
|
277 |
-
# st.sidebar.subheader("Drinks")
|
278 |
-
# for item in drinks:
|
279 |
-
# # Add a unique key to each checkbox to avoid duplicate widget IDs
|
280 |
-
# item_visibility[item] = st.sidebar.checkbox(item, value=True, key=f"checkbox_{item}_Drink")
|
281 |
-
|
282 |
-
# # Food Section
|
283 |
-
# if foods:
|
284 |
-
# st.sidebar.subheader("Food")
|
285 |
-
# for item in foods:
|
286 |
-
# # Add a unique key to each checkbox to avoid duplicate widget IDs
|
287 |
-
# item_visibility[item] = st.sidebar.checkbox(item, value=True, key=f"checkbox_{item}_Food")
|
288 |
-
|
289 |
-
# # Filter the data based on selected items
|
290 |
-
# selected_items = [item for item, visible in item_visibility.items() if visible]
|
291 |
-
# filtered_item_counts = item_counts[item_counts['Item'].isin(selected_items)]
|
292 |
-
|
293 |
-
# # Create a line plot for each selected item over time
|
294 |
-
# plt.figure(figsize=(12, 6))
|
295 |
-
# sns.lineplot(data=filtered_item_counts, x='Date', y='Count', hue='Item', marker='o')
|
296 |
-
|
297 |
-
# # Customize the plot
|
298 |
-
# plt.xticks(rotation=45)
|
299 |
-
# plt.title('Item Selections Over Time')
|
300 |
-
# plt.xlabel('Date')
|
301 |
-
# plt.ylabel('Number of Selections')
|
302 |
-
# plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), ncol=3)
|
303 |
-
|
304 |
-
# # Display the plot
|
305 |
-
# st.pyplot(plt.gcf())
|
306 |
-
# else:
|
307 |
-
# st.write("No historical data available to plot.")
|
308 |
-
|
309 |
# Graph view to display a line chart of item selections over time
|
310 |
elif menu == "Graph":
|
311 |
st.title("Breakfast Poll History - Graph View")
|
|
|
196 |
else:
|
197 |
st.write("No history records found.")
|
198 |
|
199 |
+
# # "Current" view to display the current summary of all users' selections and submit to history
|
200 |
+
# elif menu == "Current":
|
201 |
+
# st.title("Current Selections of All Users")
|
202 |
+
# if st.button("Reload Selections"):
|
203 |
+
# download_temp_file_from_repo()
|
204 |
+
# current_df = load_current_selections()
|
205 |
+
# st.table(current_df)
|
206 |
+
|
207 |
+
# if st.button("Submit Summary to History"):
|
208 |
+
# timestamp = save_summary_to_history()
|
209 |
+
# st.success(f"Summary saved to history at {timestamp}")
|
210 |
+
# st.session_state.history = load_history()
|
211 |
+
|
212 |
+
# # Clear local and remote current selections
|
213 |
+
# if os.path.exists(TEMP_FILE):
|
214 |
+
# os.remove(TEMP_FILE)
|
215 |
+
# delete_file_from_repo(TEMP_FILE) # Delete the file from the remote repo
|
216 |
+
|
217 |
+
# # Create an empty CSV to replace the deleted one
|
218 |
+
# pd.DataFrame(columns=["Name", "Drinks", "Food"]).to_csv(TEMP_FILE, index=False)
|
219 |
+
# upload_temp_file_to_repo()
|
220 |
+
|
221 |
+
# "Current" view to display the current summary of all users' selections and generate ticket
|
222 |
elif menu == "Current":
|
223 |
st.title("Current Selections of All Users")
|
224 |
if st.button("Reload Selections"):
|
|
|
226 |
current_df = load_current_selections()
|
227 |
st.table(current_df)
|
228 |
|
229 |
+
# Define item prices
|
230 |
+
item_prices = {
|
231 |
+
"Café con leche": 1.20, "Colacao": 1.00, "Descafeinado con leche": 1.20, "Cortado": 1.20,
|
232 |
+
"Aguasusia": 1.20, "Aguasusia susia": 1.20, "Café descafeinado con leche desnatada": 1.20,
|
233 |
+
"Italiano": 1.20, "Café con soja": 1.20, "Té": 1.00, "Manzanilla": 1.00, "Nada": 0.00,
|
234 |
+
"Barrita con aceite": 1.00, "Barrita con tomate": 1.00, "Palmera de chocolate": 1.00,
|
235 |
+
"Palmera de chocolate blanco": 1.00, "Yogurt": 1.00, "Pincho de tortilla": 1.00
|
236 |
+
}
|
237 |
+
# Define combined prices for special combinations
|
238 |
+
combo_prices = {
|
239 |
+
"desayuno + café (aceite)": 1.85,
|
240 |
+
"desayuno + café (tomate)": 2.50
|
241 |
+
}
|
242 |
+
|
243 |
+
# Generate Ticket
|
244 |
+
if st.button("Generate Ticket"):
|
245 |
+
# Create a list to hold the ticket items
|
246 |
+
ticket = []
|
247 |
+
|
248 |
+
# Iterate over each user's selections
|
249 |
+
for _, row in current_df.iterrows():
|
250 |
+
drinks = row['Drinks'].split(", ") if isinstance(row['Drinks'], str) else []
|
251 |
+
food = row['Food'].split(", ") if isinstance(row['Food'], str) else []
|
252 |
+
|
253 |
+
# Track which items have been used in combinations
|
254 |
+
used_drinks = set()
|
255 |
+
used_food = set()
|
256 |
+
|
257 |
+
# Handle combinations of café + barrita con aceite
|
258 |
+
for drink in drinks:
|
259 |
+
if "café" in drink.lower() and "Barrita con aceite" in food:
|
260 |
+
ticket.append({"Item": "desayuno + café (aceite)", "Price": combo_prices["desayuno + café (aceite)"]})
|
261 |
+
used_drinks.add(drink)
|
262 |
+
used_food.add("Barrita con aceite")
|
263 |
+
break # Only one combo per user for this
|
264 |
+
|
265 |
+
# Handle combinations of café + barrita con tomate
|
266 |
+
for drink in drinks:
|
267 |
+
if "café" in drink.lower() and "Barrita con tomate" in food and drink not in used_drinks:
|
268 |
+
ticket.append({"Item": "desayuno + café (tomate)", "Price": combo_prices["desayuno + café (tomate)"]})
|
269 |
+
used_drinks.add(drink)
|
270 |
+
used_food.add("Barrita con tomate")
|
271 |
+
break # Only one combo per user for this
|
272 |
+
|
273 |
+
# Add remaining individual drinks not used in combinations
|
274 |
+
for drink in drinks:
|
275 |
+
if drink not in used_drinks and drink in item_prices:
|
276 |
+
ticket.append({"Item": drink, "Price": item_prices[drink]})
|
277 |
+
used_drinks.add(drink)
|
278 |
+
|
279 |
+
# Add remaining individual food not used in combinations
|
280 |
+
for f in food:
|
281 |
+
if f not in used_food and f in item_prices:
|
282 |
+
ticket.append({"Item": f, "Price": item_prices[f]})
|
283 |
+
used_food.add(f)
|
284 |
+
|
285 |
+
# Create a DataFrame to display the ticket
|
286 |
+
ticket_df = pd.DataFrame(ticket)
|
287 |
+
st.subheader("Generated Ticket")
|
288 |
+
st.table(ticket_df)
|
289 |
+
|
290 |
+
# Calculate and display the total price
|
291 |
+
total_price = ticket_df["Price"].sum()
|
292 |
+
st.write(f"**Total Price:** {total_price:.2f} €")
|
293 |
|
294 |
# History view to check past summaries
|
295 |
elif menu == "History":
|
|
|
307 |
else:
|
308 |
st.write("No history records found.")
|
309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
# Graph view to display a line chart of item selections over time
|
311 |
elif menu == "Graph":
|
312 |
st.title("Breakfast Poll History - Graph View")
|