Spaces:
Runtime error
Runtime error
Update menu.py
Browse files
menu.py
CHANGED
@@ -130,8 +130,6 @@ def menu():
|
|
130 |
instruction_counts = {}
|
131 |
spice_levels = ['Mild', 'Medium', 'Spicy', 'Extra Spicy']
|
132 |
|
133 |
-
# Iterate through past orders and calculate frequency of add-ons and spice levels
|
134 |
-
spice_counts = {}
|
135 |
for order in past_orders:
|
136 |
order_details = order.get('Order_Details__c', '').split('\n')
|
137 |
|
@@ -142,39 +140,44 @@ def menu():
|
|
142 |
addons = item_parts[1].strip().replace('Add-Ons:', '').split(', ')
|
143 |
instructions = item_parts[2].strip().replace('Instructions:', '').split(', ')
|
144 |
|
145 |
-
#
|
146 |
-
for addon in addons
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
|
|
157 |
for addon, count in addon_counts.items():
|
158 |
-
print(f"{addon}
|
159 |
-
|
160 |
-
# Get the most
|
161 |
-
most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3]
|
162 |
-
|
163 |
-
|
164 |
-
print("
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
most_common_addons
|
175 |
-
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
178 |
categories = ["All", "Veg", "Non veg"]
|
179 |
|
180 |
except Exception as e:
|
|
|
130 |
instruction_counts = {}
|
131 |
spice_levels = ['Mild', 'Medium', 'Spicy', 'Extra Spicy']
|
132 |
|
|
|
|
|
133 |
for order in past_orders:
|
134 |
order_details = order.get('Order_Details__c', '').split('\n')
|
135 |
|
|
|
140 |
addons = item_parts[1].strip().replace('Add-Ons:', '').split(', ')
|
141 |
instructions = item_parts[2].strip().replace('Instructions:', '').split(', ')
|
142 |
|
143 |
+
# Clean the add-on names by removing any price information
|
144 |
+
cleaned_addons = [re.sub(r"\s?\(\$\d+(\.\d{2})?\)", "", addon) for addon in addons]
|
145 |
+
# Split add-ons by semicolon and process separately
|
146 |
+
for addon in cleaned_addons:
|
147 |
+
# If the add-on contains a semicolon, split it into multiple add-ons
|
148 |
+
individual_addons = addon.split(';') # Split add-ons separated by semicolons
|
149 |
+
for individual_addon in individual_addons:
|
150 |
+
individual_addon = individual_addon.strip() # Remove extra spaces
|
151 |
+
if individual_addon:
|
152 |
+
addon_counts[individual_addon] = addon_counts.get(individual_addon, 0) + 1
|
153 |
+
|
154 |
+
# Print the cleaned add-ons and their counts in the requested format
|
155 |
+
print(f"Add-ons fetched (cleaned): {addon_counts}")
|
156 |
+
print("Add-on Counts in the format [Add-onName[Count]]:")
|
157 |
for addon, count in addon_counts.items():
|
158 |
+
print(f"{addon}[{count}]")
|
159 |
+
|
160 |
+
# Get the most frequent add-ons
|
161 |
+
most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3] # Top 3 most frequent addons
|
162 |
+
|
163 |
+
# Print the most common add-ons in the required format
|
164 |
+
print(f"Most common add-ons (cleaned): {most_common_addons}")
|
165 |
+
|
166 |
+
# Now include any spice level if it's not already in the top 3
|
167 |
+
most_common_spice = None
|
168 |
+
for spice in spice_levels:
|
169 |
+
if spice in addon_counts:
|
170 |
+
most_common_spice = spice
|
171 |
+
break
|
172 |
+
|
173 |
+
if most_common_spice and most_common_spice not in most_common_addons:
|
174 |
+
most_common_addons.append(most_common_spice)
|
175 |
+
|
176 |
+
# Ensure the list does not exceed 3
|
177 |
+
most_common_addons = most_common_addons[:3]
|
178 |
+
|
179 |
+
print(f"Final Most Common Add-Ons (Including Spice Level): {most_common_addons}")
|
180 |
+
|
181 |
categories = ["All", "Veg", "Non veg"]
|
182 |
|
183 |
except Exception as e:
|