DawnC commited on
Commit
b50c0de
1 Parent(s): 64f1cd6

Update breed_recommendation.py

Browse files
Files changed (1) hide show
  1. breed_recommendation.py +16 -74
breed_recommendation.py CHANGED
@@ -125,63 +125,6 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
125
  elem_id="recommendation-output" # 添加唯一ID以便追蹤
126
  )
127
 
128
- # def on_find_match_click(*args):
129
- # try:
130
- # user_prefs = UserPreferences(
131
- # living_space=args[0],
132
- # yard_access=args[1],
133
- # exercise_time=args[2],
134
- # exercise_type=args[3],
135
- # grooming_commitment=args[4],
136
- # experience_level=args[5],
137
- # time_availability=args[6],
138
- # has_children=args[7],
139
- # children_age=args[8] if args[7] else None,
140
- # noise_tolerance=args[9],
141
- # space_for_play=True if args[0] != "apartment" else False,
142
- # other_pets=False,
143
- # climate="moderate",
144
- # health_sensitivity="medium",
145
- # barking_acceptance=args[9]
146
- # )
147
-
148
- # recommendations = get_breed_recommendations(user_prefs, top_n=10)
149
-
150
- # history_results = [{
151
- # 'breed': rec['breed'],
152
- # 'rank': rec['rank'],
153
- # 'overall_score': rec['final_score'],
154
- # 'base_score': rec['base_score'],
155
- # 'bonus_score': rec['bonus_score'],
156
- # 'scores': rec['scores']
157
- # } for rec in recommendations]
158
-
159
- # history_component.save_search(
160
- # user_preferences={
161
- # 'living_space': args[0],
162
- # 'yard_access': args[1],
163
- # 'exercise_time': args[2],
164
- # 'exercise_type': args[3],
165
- # 'grooming_commitment': args[4],
166
- # 'experience_level': args[5],
167
- # 'time_availability': args[6],
168
- # 'has_children': args[7],
169
- # 'children_age': args[8] if args[7] else None,
170
- # 'noise_tolerance': args[9],
171
- # 'search_type': 'Criteria'
172
- # },
173
- # results=history_results
174
- # )
175
-
176
- # return format_recommendation_html(recommendations, is_description_search=False)
177
-
178
- # except Exception as e:
179
- # print(f"Error in find match: {str(e)}")
180
- # import traceback
181
- # print(traceback.format_exc())
182
- # return "Error getting recommendations"
183
-
184
-
185
  def on_find_match_click(*args):
186
  try:
187
  user_prefs = UserPreferences(
@@ -201,20 +144,18 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
201
  health_sensitivity="medium",
202
  barking_acceptance=args[9]
203
  )
204
-
205
  recommendations = get_breed_recommendations(user_prefs, top_n=10)
206
-
207
- history_results = []
208
- for i, rec in enumerate(recommendations, 1):
209
- history_result = {
210
- 'breed': rec['breed'],
211
- 'rank': i, # 確保有排名
212
- 'overall_score': float(rec['final_score']), # 確保分數為數字
213
- 'scores': rec.get('scores', {}), # 保存詳細分數
214
- }
215
- history_results.append(history_result)
216
-
217
- # 保存搜尋記錄
218
  history_component.save_search(
219
  user_preferences={
220
  'living_space': args[0],
@@ -227,15 +168,16 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
227
  'has_children': args[7],
228
  'children_age': args[8] if args[7] else None,
229
  'noise_tolerance': args[9],
 
230
  },
231
- results=history_results, # 傳遞處理後的結果
232
- search_type='criteria'
233
  )
234
-
235
  return format_recommendation_html(recommendations, is_description_search=False)
236
-
237
  except Exception as e:
238
  print(f"Error in find match: {str(e)}")
 
239
  print(traceback.format_exc())
240
  return "Error getting recommendations"
241
 
 
125
  elem_id="recommendation-output" # 添加唯一ID以便追蹤
126
  )
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  def on_find_match_click(*args):
129
  try:
130
  user_prefs = UserPreferences(
 
144
  health_sensitivity="medium",
145
  barking_acceptance=args[9]
146
  )
147
+
148
  recommendations = get_breed_recommendations(user_prefs, top_n=10)
149
+
150
+ history_results = [{
151
+ 'breed': rec['breed'],
152
+ 'rank': rec['rank'],
153
+ 'overall_score': rec['final_score'],
154
+ 'base_score': rec['base_score'],
155
+ 'bonus_score': rec['bonus_score'],
156
+ 'scores': rec['scores']
157
+ } for rec in recommendations]
158
+
 
 
159
  history_component.save_search(
160
  user_preferences={
161
  'living_space': args[0],
 
168
  'has_children': args[7],
169
  'children_age': args[8] if args[7] else None,
170
  'noise_tolerance': args[9],
171
+ 'search_type': 'Criteria'
172
  },
173
+ results=history_results
 
174
  )
175
+
176
  return format_recommendation_html(recommendations, is_description_search=False)
177
+
178
  except Exception as e:
179
  print(f"Error in find match: {str(e)}")
180
+ import traceback
181
  print(traceback.format_exc())
182
  return "Error getting recommendations"
183