nagasurendra commited on
Commit
47fe464
·
verified ·
1 Parent(s): 92a00b4

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +15 -33
menu.py CHANGED
@@ -126,10 +126,8 @@ def menu():
126
 
127
  # Frequency analysis for add-ons and instructions
128
  addon_counts = {}
129
- spice_counts = {}
130
  instruction_counts = {}
131
 
132
- # Analyzing past orders for add-ons and spice levels
133
  for order in past_orders:
134
  order_details = order.get('Order_Details__c', '').split('\n')
135
 
@@ -140,48 +138,32 @@ def menu():
140
  addons = item_parts[1].strip().replace('Add-Ons:', '').split(', ')
141
  instructions = item_parts[2].strip().replace('Instructions:', '').split(', ')
142
 
143
- # Count spice levels
144
- for addon in addons:
145
- for spice in ['Mild', 'Medium', 'Spicy', 'Extra Spicy']:
146
- if spice.lower() in addon.lower():
147
- spice_counts[spice] = spice_counts.get(spice, 0) + 1
148
-
149
- # Clean and count other add-ons
150
  cleaned_addons = [re.sub(r"\s?\(\$\d+(\.\d{2})?\)", "", addon) for addon in addons]
 
151
  for addon in cleaned_addons:
152
- individual_addons = addon.split(';')
 
153
  for individual_addon in individual_addons:
154
- individual_addon = individual_addon.strip()
155
  if individual_addon:
156
  addon_counts[individual_addon] = addon_counts.get(individual_addon, 0) + 1
157
 
158
- # Count instructions
159
  for instruction in instructions:
160
  if instruction:
161
  instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
162
 
163
- # Print out the cleaned add-ons and spice counts
164
  print(f"Add-ons fetched (cleaned): {addon_counts}")
165
- print(f"Spice Levels Count: {spice_counts}")
166
- print("Add-on Counts in the format [Add-onName[Count]]:")
167
- for addon, count in addon_counts.items():
168
- print(f"{addon}[{count}]")
169
-
170
- # Get the most frequent add-ons (top 3)
171
- most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3]
172
- print(f"Most common add-ons (cleaned): {most_common_addons}")
173
-
174
- # Get the most frequent spice level
175
- most_common_spice = max(spice_counts, key=spice_counts.get, default=None)
176
- print(f"Most Frequent Spice Level: {most_common_spice}")
177
 
178
- # Ensure the most frequent spice level is included if not already in the top 3
179
- if most_common_spice and most_common_spice not in most_common_addons:
180
- most_common_addons.append(most_common_spice)
181
 
182
- # Ensure the list does not exceed 3
183
- most_common_addons = most_common_addons[:3]
184
- print(f"Final Most Common Add-Ons (Including Spice Level): {most_common_addons}")
185
 
186
  categories = ["All", "Veg", "Non veg"]
187
 
@@ -202,8 +184,8 @@ def menu():
202
  reward_points=reward_points,
203
  user_name=user_name, # Pass name to the template
204
  first_letter=first_letter, # Pass first letter to the template
205
- most_common_addons=[addon.strip() for addon in most_common_addons] # Pass most common addons
206
-
207
  )
208
 
209
  @menu_blueprint.route('/api/addons', methods=['GET'])
 
126
 
127
  # Frequency analysis for add-ons and instructions
128
  addon_counts = {}
 
129
  instruction_counts = {}
130
 
 
131
  for order in past_orders:
132
  order_details = order.get('Order_Details__c', '').split('\n')
133
 
 
138
  addons = item_parts[1].strip().replace('Add-Ons:', '').split(', ')
139
  instructions = item_parts[2].strip().replace('Instructions:', '').split(', ')
140
 
141
+ # Clean the add-on names by removing any price information
 
 
 
 
 
 
142
  cleaned_addons = [re.sub(r"\s?\(\$\d+(\.\d{2})?\)", "", addon) for addon in addons]
143
+ # Split add-ons by semicolon and process separately
144
  for addon in cleaned_addons:
145
+ # If the add-on contains a semicolon, split it into multiple add-ons
146
+ individual_addons = addon.split(';') # Split add-ons separated by semicolons
147
  for individual_addon in individual_addons:
148
+ individual_addon = individual_addon.strip() # Remove extra spaces
149
  if individual_addon:
150
  addon_counts[individual_addon] = addon_counts.get(individual_addon, 0) + 1
151
 
152
+
153
  for instruction in instructions:
154
  if instruction:
155
  instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
156
 
157
+ # Print the cleaned add-ons and instructions to check what we're fetching
158
  print(f"Add-ons fetched (cleaned): {addon_counts}")
159
+
 
 
 
 
 
 
 
 
 
 
 
160
 
161
+ # Get the most frequent add-ons and instructions
162
+ most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:10] # Top 3 most frequent addons
163
+ most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3] # Top 3 most frequent instructions
164
 
165
+ # Print to check the final most common add-ons and instructions
166
+ print(f"Most common add-ons (cleaned): {most_common_addons}")
 
167
 
168
  categories = ["All", "Veg", "Non veg"]
169
 
 
184
  reward_points=reward_points,
185
  user_name=user_name, # Pass name to the template
186
  first_letter=first_letter, # Pass first letter to the template
187
+ most_common_addons=[addon.strip() for addon in most_common_addons], # Pass most common addons
188
+ most_common_instructions=most_common_instructions # Pass most common instructions
189
  )
190
 
191
  @menu_blueprint.route('/api/addons', methods=['GET'])