nagasurendra commited on
Commit
3f67e98
·
verified ·
1 Parent(s): 8bf17c9

Update menu.py

Browse files
Files changed (1) hide show
  1. menu.py +53 -45
menu.py CHANGED
@@ -9,6 +9,14 @@ sf = get_salesforce_connection()
9
  @menu_blueprint.route("/menu", methods=["GET", "POST"])
10
  def menu():
11
  selected_category = request.args.get("category", "All")
 
 
 
 
 
 
 
 
12
  user_email = session.get('user_email')
13
 
14
  if not user_email:
@@ -37,49 +45,6 @@ def menu():
37
  referral_code = user_result['records'][0].get('Referral__c', 'N/A')
38
  reward_points = user_result['records'][0].get('Reward_Points__c', 0)
39
 
40
- # Fetch the most selected add-ons and instructions based on the user's previous orders
41
- past_orders_query = f"""
42
- SELECT Order_Details__c FROM Order__c
43
- WHERE Customer_Email__c = '{user_email}'
44
- """
45
- past_orders_result = sf.query(past_orders_query)
46
- past_orders = past_orders_result.get('records', [])
47
-
48
- # Frequency analysis for add-ons and instructions
49
- addon_counts = {}
50
- instruction_counts = {}
51
-
52
- for order in past_orders:
53
- order_details = order.get('Order_Details__c', '').split('\n')
54
-
55
- for line in order_details:
56
- item_parts = line.split('|')
57
- if len(item_parts) >= 5:
58
- # Extract Add-Ons and Instructions from the order details string
59
- addons = item_parts[1].strip().replace('Add-Ons:', '').split(', ')
60
- instructions = item_parts[2].strip().replace('Instructions:', '').split(', ')
61
-
62
- # Count occurrences for add-ons and instructions
63
- for addon in addons:
64
- if addon:
65
- addon_counts[addon] = addon_counts.get(addon, 0) + 1
66
-
67
- for instruction in instructions:
68
- if instruction:
69
- instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
70
-
71
- # Debugging print statements for the most common add-ons and instructions
72
- print(f"Most frequent add-ons: {addon_counts}")
73
- print(f"Most frequent instructions: {instruction_counts}")
74
-
75
- # Get the most frequent add-ons and instructions
76
- most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3] # Top 3 most frequent addons
77
- most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3] # Top 3 most frequent instructions
78
-
79
- # Debugging print statements to observe the most frequent add-ons and instructions
80
- print(f"Top 3 most common add-ons: {most_common_addons}")
81
- print(f"Top 3 most common instructions: {most_common_instructions}")
82
-
83
  # Query to fetch Menu_Item__c records including Total_Ordered__c for best sellers
84
  menu_query = """
85
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c
@@ -112,6 +77,7 @@ def menu():
112
  # Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
113
  best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
114
 
 
115
  if selected_category == "Veg":
116
  best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
117
  elif selected_category == "Non veg":
@@ -148,7 +114,49 @@ def menu():
148
 
149
  # Remove empty sections
150
  ordered_menu = {section: items for section, items in ordered_menu.items() if items}
151
- print(f"Final ordered menu: {ordered_menu.keys()}") # Debugging
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
 
153
  categories = ["All", "Veg", "Non veg"]
154
 
@@ -159,7 +167,7 @@ def menu():
159
  referral_code = 'N/A'
160
  reward_points = 0
161
 
162
- # Pass the user's first letter (first_letter) to the template
163
  return render_template(
164
  "menu.html",
165
  ordered_menu=ordered_menu,
 
9
  @menu_blueprint.route("/menu", methods=["GET", "POST"])
10
  def menu():
11
  selected_category = request.args.get("category", "All")
12
+ is_veg_only = request.args.get("veg") == 'on'
13
+
14
+ # Priority to Customized Dish only if it's selected
15
+ if request.args.get("category") == "Customized Dish":
16
+ selected_category = "Customized Dish"
17
+ else:
18
+ selected_category = "Veg" if is_veg_only else "All"
19
+
20
  user_email = session.get('user_email')
21
 
22
  if not user_email:
 
45
  referral_code = user_result['records'][0].get('Referral__c', 'N/A')
46
  reward_points = user_result['records'][0].get('Reward_Points__c', 0)
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  # Query to fetch Menu_Item__c records including Total_Ordered__c for best sellers
49
  menu_query = """
50
  SELECT Name, Price__c, Description__c, Image1__c, Image2__c, Veg_NonVeg__c, Section__c, Total_Ordered__c
 
77
  # Sort items by Total_Ordered__c in descending order and pick top 4 as best sellers
78
  best_sellers = sorted(all_items, key=lambda x: x.get("Total_Ordered__c", 0), reverse=True)
79
 
80
+ # If the category is "Veg", filter for Veg items
81
  if selected_category == "Veg":
82
  best_sellers = [item for item in best_sellers if item.get("Veg_NonVeg__c") in ["Veg", "both"]]
83
  elif selected_category == "Non veg":
 
114
 
115
  # Remove empty sections
116
  ordered_menu = {section: items for section, items in ordered_menu.items() if items}
117
+
118
+ # Fetch the most selected add-ons and instructions based on the user's previous orders
119
+ past_orders_query = f"""
120
+ SELECT Order_Details__c FROM Order__c
121
+ WHERE Customer_Email__c = '{user_email}'
122
+ """
123
+ past_orders_result = sf.query(past_orders_query)
124
+ past_orders = past_orders_result.get('records', [])
125
+
126
+ # Frequency analysis for add-ons and instructions
127
+ addon_counts = {}
128
+ instruction_counts = {}
129
+
130
+ for order in past_orders:
131
+ order_details = order.get('Order_Details__c', '').split('\n')
132
+
133
+ for line in order_details:
134
+ item_parts = line.split('|')
135
+ if len(item_parts) >= 5:
136
+ # Extract Add-Ons and Instructions from the order details string
137
+ addons = item_parts[1].strip().replace('Add-Ons:', '').split(', ')
138
+ instructions = item_parts[2].strip().replace('Instructions:', '').split(', ')
139
+
140
+ # Count occurrences for add-ons and instructions
141
+ for addon in addons:
142
+ if addon:
143
+ addon_counts[addon] = addon_counts.get(addon, 0) + 1
144
+
145
+ for instruction in instructions:
146
+ if instruction:
147
+ instruction_counts[instruction] = instruction_counts.get(instruction, 0) + 1
148
+
149
+ # Print the add-ons and instructions to check what we're fetching
150
+ print(f"Add-ons fetched: {addon_counts}")
151
+ print(f"Instructions fetched: {instruction_counts}")
152
+
153
+ # Get the most frequent add-ons and instructions
154
+ most_common_addons = sorted(addon_counts, key=addon_counts.get, reverse=True)[:3] # Top 3 most frequent addons
155
+ most_common_instructions = sorted(instruction_counts, key=instruction_counts.get, reverse=True)[:3] # Top 3 most frequent instructions
156
+
157
+ # Print to check the final most common add-ons and instructions
158
+ print(f"Most common add-ons: {most_common_addons}")
159
+ print(f"Most common instructions: {most_common_instructions}")
160
 
161
  categories = ["All", "Veg", "Non veg"]
162
 
 
167
  referral_code = 'N/A'
168
  reward_points = 0
169
 
170
+ # Pass the most common add-ons and instructions to the template
171
  return render_template(
172
  "menu.html",
173
  ordered_menu=ordered_menu,