Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -227,21 +227,6 @@ elif menu == "Current":
|
|
227 |
current_df = load_current_selections()
|
228 |
st.table(current_df)
|
229 |
|
230 |
-
# Button to submit the summary to history
|
231 |
-
if st.button("Submit Summary to History"):
|
232 |
-
timestamp = save_summary_to_history()
|
233 |
-
st.success(f"Summary saved to history at {timestamp}")
|
234 |
-
st.session_state.history = load_history()
|
235 |
-
|
236 |
-
# Clear local and remote current selections
|
237 |
-
if os.path.exists(TEMP_FILE):
|
238 |
-
os.remove(TEMP_FILE)
|
239 |
-
delete_file_from_repo(TEMP_FILE) # Delete the file from the remote repo
|
240 |
-
|
241 |
-
# Create an empty CSV to replace the deleted one
|
242 |
-
pd.DataFrame(columns=["Name", "Drinks", "Food"]).to_csv(TEMP_FILE, index=False)
|
243 |
-
upload_temp_file_to_repo()
|
244 |
-
|
245 |
# Define item prices
|
246 |
item_prices = {
|
247 |
"Café con leche": 1.20, "Colacao": 1.00, "Descafeinado con leche": 1.20, "Cortado": 1.20,
|
@@ -256,9 +241,11 @@ elif menu == "Current":
|
|
256 |
"desayuno + café (tomate)": 2.50
|
257 |
}
|
258 |
|
|
|
|
|
|
|
259 |
# Generate Ticket Button and Logic
|
260 |
if st.button("Generate Ticket"):
|
261 |
-
# Create a list to hold the ticket items
|
262 |
ticket = []
|
263 |
|
264 |
# Iterate over each user's selections
|
@@ -266,7 +253,6 @@ elif menu == "Current":
|
|
266 |
drinks = row['Drinks'].split(", ") if isinstance(row['Drinks'], str) else []
|
267 |
food = row['Food'].split(", ") if isinstance(row['Food'], str) else []
|
268 |
|
269 |
-
# Track which items have been used in combinations
|
270 |
used_drinks = set()
|
271 |
used_food = set()
|
272 |
|
@@ -276,7 +262,7 @@ elif menu == "Current":
|
|
276 |
ticket.append({"Item": "desayuno + café (aceite)", "Price": combo_prices["desayuno + café (aceite)"]})
|
277 |
used_drinks.add(drink)
|
278 |
used_food.add("Barrita con aceite")
|
279 |
-
break
|
280 |
|
281 |
# Handle combinations of café + barrita con tomate
|
282 |
for drink in drinks:
|
@@ -284,7 +270,7 @@ elif menu == "Current":
|
|
284 |
ticket.append({"Item": "desayuno + café (tomate)", "Price": combo_prices["desayuno + café (tomate)"]})
|
285 |
used_drinks.add(drink)
|
286 |
used_food.add("Barrita con tomate")
|
287 |
-
break
|
288 |
|
289 |
# Add remaining individual drinks not used in combinations
|
290 |
for drink in drinks:
|
@@ -300,13 +286,36 @@ elif menu == "Current":
|
|
300 |
|
301 |
# Create a DataFrame to display the ticket
|
302 |
ticket_df = pd.DataFrame(ticket)
|
|
|
|
|
|
|
|
|
303 |
st.subheader("Generated Ticket")
|
304 |
st.table(ticket_df)
|
305 |
|
306 |
# Calculate and display the total price
|
307 |
-
total_price = ticket_df["Price"]
|
308 |
st.write(f"**Total Price:** {total_price:.2f} €")
|
309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
# History view to check past summaries
|
311 |
elif menu == "History":
|
312 |
st.title("Breakfast Poll History")
|
|
|
227 |
current_df = load_current_selections()
|
228 |
st.table(current_df)
|
229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
# Define item prices
|
231 |
item_prices = {
|
232 |
"Café con leche": 1.20, "Colacao": 1.00, "Descafeinado con leche": 1.20, "Cortado": 1.20,
|
|
|
241 |
"desayuno + café (tomate)": 2.50
|
242 |
}
|
243 |
|
244 |
+
# Variable to track if ticket is generated
|
245 |
+
ticket_generated = False
|
246 |
+
|
247 |
# Generate Ticket Button and Logic
|
248 |
if st.button("Generate Ticket"):
|
|
|
249 |
ticket = []
|
250 |
|
251 |
# Iterate over each user's selections
|
|
|
253 |
drinks = row['Drinks'].split(", ") if isinstance(row['Drinks'], str) else []
|
254 |
food = row['Food'].split(", ") if isinstance(row['Food'], str) else []
|
255 |
|
|
|
256 |
used_drinks = set()
|
257 |
used_food = set()
|
258 |
|
|
|
262 |
ticket.append({"Item": "desayuno + café (aceite)", "Price": combo_prices["desayuno + café (aceite)"]})
|
263 |
used_drinks.add(drink)
|
264 |
used_food.add("Barrita con aceite")
|
265 |
+
break
|
266 |
|
267 |
# Handle combinations of café + barrita con tomate
|
268 |
for drink in drinks:
|
|
|
270 |
ticket.append({"Item": "desayuno + café (tomate)", "Price": combo_prices["desayuno + café (tomate)"]})
|
271 |
used_drinks.add(drink)
|
272 |
used_food.add("Barrita con tomate")
|
273 |
+
break
|
274 |
|
275 |
# Add remaining individual drinks not used in combinations
|
276 |
for drink in drinks:
|
|
|
286 |
|
287 |
# Create a DataFrame to display the ticket
|
288 |
ticket_df = pd.DataFrame(ticket)
|
289 |
+
|
290 |
+
# Format prices to show only 2 decimals
|
291 |
+
ticket_df["Price"] = ticket_df["Price"].apply(lambda x: f"{x:.2f}")
|
292 |
+
|
293 |
st.subheader("Generated Ticket")
|
294 |
st.table(ticket_df)
|
295 |
|
296 |
# Calculate and display the total price
|
297 |
+
total_price = sum([float(price) for price in ticket_df["Price"]])
|
298 |
st.write(f"**Total Price:** {total_price:.2f} €")
|
299 |
|
300 |
+
# Set ticket_generated to True to show the "Submit Summary" button below
|
301 |
+
ticket_generated = True
|
302 |
+
|
303 |
+
# Only show the "Submit Summary to History" button after generating the ticket
|
304 |
+
if ticket_generated:
|
305 |
+
if st.button("Submit Summary to History"):
|
306 |
+
timestamp = save_summary_to_history()
|
307 |
+
st.success(f"Summary saved to history at {timestamp}")
|
308 |
+
st.session_state.history = load_history()
|
309 |
+
|
310 |
+
# Clear local and remote current selections
|
311 |
+
if os.path.exists(TEMP_FILE):
|
312 |
+
os.remove(TEMP_FILE)
|
313 |
+
delete_file_from_repo(TEMP_FILE)
|
314 |
+
|
315 |
+
# Create an empty CSV to replace the deleted one
|
316 |
+
pd.DataFrame(columns=["Name", "Drinks", "Food"]).to_csv(TEMP_FILE, index=False)
|
317 |
+
upload_temp_file_to_repo()
|
318 |
+
|
319 |
# History view to check past summaries
|
320 |
elif menu == "History":
|
321 |
st.title("Breakfast Poll History")
|