nagasurendra commited on
Commit
a7b928b
·
verified ·
1 Parent(s): a393296

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +26 -20
menu.py CHANGED
@@ -7,7 +7,6 @@ menu_blueprint = Blueprint('menu', __name__)
7
  sf = get_salesforce_connection()
8
 
9
  import re # Importing regular expression module
10
-
11
  @menu_blueprint.route("/menu", methods=["GET", "POST"])
12
  def menu():
13
  selected_category = request.args.get("category", "All")
@@ -127,9 +126,10 @@ def menu():
127
 
128
  # Frequency analysis for add-ons and instructions
129
  addon_counts = {}
 
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,42 +140,47 @@ def menu():
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"]
@@ -197,7 +202,8 @@ def menu():
197
  reward_points=reward_points,
198
  user_name=user_name, # Pass name to the template
199
  first_letter=first_letter, # Pass first letter to the template
200
- most_common_addons=[addon.strip() for addon in most_common_addons] # Pass most common addons
 
201
  )
202
 
203
  @menu_blueprint.route('/api/addons', methods=['GET'])
 
7
  sf = get_salesforce_connection()
8
 
9
  import re # Importing regular expression module
 
10
  @menu_blueprint.route("/menu", methods=["GET", "POST"])
11
  def menu():
12
  selected_category = request.args.get("category", "All")
 
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
  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"]
 
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
+ most_common_instructions=most_common_instructions # Pass most common instructions
207
  )
208
 
209
  @menu_blueprint.route('/api/addons', methods=['GET'])