nagasurendra commited on
Commit
d6294c4
·
verified ·
1 Parent(s): 2d3a553

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +37 -34
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
- # Track the frequency of spice levels
146
- for addon in addons:
147
- print(f"Addon: {addon.strip()}")
148
- for spice in spice_levels:
149
- if spice.lower() in addon.lower():
150
- spice_counts[spice] = spice_counts.get(spice, 0) + 1
151
-
152
- # Track instructions
153
- for instruction in instructions:
154
- if instruction:
155
- instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
156
- print("\nAddon counts:")
 
 
157
  for addon, count in addon_counts.items():
158
- print(f"{addon}: {count}")
159
-
160
- # Get the most common add-ons, including spice levels
161
- most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3]
162
- most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3]
163
- # Print to check the final most common add-ons and instructions
164
- print("\nTop 3 Most Common Add-Ons:")
165
- for addon in most_common_addons:
166
- print(f"{addon}")
167
-
168
- # Include most ordered spice level if it's not already in the top 3
169
- if not any(spice in most_common_addons for spice in spice_levels):
170
- most_ordered_spice = max(spice_counts, key=spice_counts.get, default=None)
171
- if most_ordered_spice:
172
- print(f"\nMost Ordered Spice: {most_ordered_spice}")
173
- most_common_addons.append(most_ordered_spice)
174
- most_common_addons = most_common_addons[:3]
175
- print("\nFinal Most Common Add-Ons (Including Spice Level):")
176
- for addon in most_common_addons:
177
- print(f"{addon}")
 
 
 
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: