nagasurendra commited on
Commit
0a50389
·
verified ·
1 Parent(s): afcdcac

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +18 -22
menu.py CHANGED
@@ -128,7 +128,10 @@ def menu():
128
  # Frequency analysis for add-ons and instructions
129
  addon_counts = {}
130
  instruction_counts = {}
 
131
 
 
 
132
  for order in past_orders:
133
  order_details = order.get('Order_Details__c', '').split('\n')
134
 
@@ -139,33 +142,27 @@ def menu():
139
  addons = item_parts[1].strip().replace('Add-Ons:', '').split(', ')
140
  instructions = item_parts[2].strip().replace('Instructions:', '').split(', ')
141
 
142
- # Clean the add-on names by removing any price information
143
- cleaned_addons = [re.sub(r"\s?\(\$\d+(\.\d{2})?\)", "", addon) for addon in addons]
144
- # Split add-ons by semicolon and process separately
145
- for addon in cleaned_addons:
146
- # If the add-on contains a semicolon, split it into multiple add-ons
147
- individual_addons = addon.split(';') # Split add-ons separated by semicolons
148
- for individual_addon in individual_addons:
149
- individual_addon = individual_addon.strip() # Remove extra spaces
150
- if individual_addon:
151
- addon_counts[individual_addon] = addon_counts.get(individual_addon, 0) + 1
152
-
153
 
 
154
  for instruction in instructions:
155
  if instruction:
156
  instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
157
 
158
- # Print the cleaned add-ons and instructions to check what we're fetching
159
- print(f"Add-ons fetched (cleaned): {addon_counts}")
160
- print(f"Instructions fetched: {instruction_counts}")
161
-
162
- # Get the most frequent add-ons and instructions
163
- most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3] # Top 3 most frequent addons
164
- most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3] # Top 3 most frequent instructions
165
 
166
- # Print to check the final most common add-ons and instructions
167
- print(f"Most common add-ons (cleaned): {most_common_addons}")
168
- print(f"Most common instructions: {most_common_instructions}")
 
 
 
169
 
170
  categories = ["All", "Veg", "Non veg"]
171
 
@@ -190,7 +187,6 @@ def menu():
190
  most_common_instructions=most_common_instructions # Pass most common instructions
191
  )
192
 
193
-
194
  @menu_blueprint.route('/api/addons', methods=['GET'])
195
  def get_addons():
196
  item_name = request.args.get('item_name')
 
128
  # Frequency analysis for add-ons and instructions
129
  addon_counts = {}
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
  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
+ for spice in spice_levels:
148
+ if spice.lower() in addon.lower():
149
+ spice_counts[spice] = spice_counts.get(spice, 0) + 1
 
 
 
 
 
 
150
 
151
+ # Track instructions
152
  for instruction in instructions:
153
  if instruction:
154
  instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
155
 
156
+ # Get the most common add-ons, including spice levels
157
+ most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3]
158
+ most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3]
 
 
 
 
159
 
160
+ # Include most ordered spice level if it's not already in the top 3
161
+ if not any(spice in most_common_addons for spice in spice_levels):
162
+ most_ordered_spice = max(spice_counts, key=spice_counts.get, default=None)
163
+ if most_ordered_spice:
164
+ most_common_addons.append(most_ordered_spice)
165
+ most_common_addons = most_common_addons[:3]
166
 
167
  categories = ["All", "Veg", "Non veg"]
168
 
 
187
  most_common_instructions=most_common_instructions # Pass most common instructions
188
  )
189
 
 
190
  @menu_blueprint.route('/api/addons', methods=['GET'])
191
  def get_addons():
192
  item_name = request.args.get('item_name')