DawnC commited on
Commit
6501717
1 Parent(s): 2ec04df

Update breed_recommendation.py

Browse files
Files changed (1) hide show
  1. breed_recommendation.py +17 -57
breed_recommendation.py CHANGED
@@ -10,46 +10,6 @@ from recommendation_html_format import format_recommendation_html, get_breed_rec
10
  from search_history import create_history_tab, create_history_component
11
 
12
 
13
- def filter_breed_matches(user_prefs: UserPreferences, top_n: int = 10):
14
- """
15
- 根據使用者偏好篩選並推薦狗狗品種。
16
-
17
- Parameters:
18
- user_prefs: 使用者偏好設定
19
- top_n: 要返回的推薦數量
20
-
21
- Returns:
22
- List[Dict]: 排序後的推薦品種列表
23
- """
24
- all_breeds = []
25
- for breed_info in breed_database:
26
- score = calculate_compatibility_score(breed_info, user_prefs)
27
- if score is not None: # 只添加未被過濾的品種
28
- all_breeds.append({
29
- 'breed': breed_info['Breed'],
30
- 'final_score': score['overall'],
31
- 'base_score': score.get('base_score', 0),
32
- 'bonus_score': score.get('bonus_score', 0),
33
- 'size': breed_info['Size'],
34
- 'scores': score
35
- })
36
-
37
- # 根據體型偏好過濾
38
- if user_prefs.size_preference != "no_preference":
39
- filtered_breeds = [b for b in all_breeds if b['size'].lower() == user_prefs.size_preference.lower()]
40
- # 如果符合體型的品種太少,調整返回數量
41
- if len(filtered_breeds) < 5: # 設定最少要有5種品種
42
- top_n = len(filtered_breeds)
43
- else:
44
- filtered_breeds = all_breeds
45
-
46
- # 為每個品種添加排名
47
- sorted_breeds = sorted(filtered_breeds, key=lambda x: x['final_score'], reverse=True)
48
- for i, breed in enumerate(sorted_breeds, 1):
49
- breed['rank'] = i
50
-
51
- return sorted_breeds[:top_n]
52
-
53
  def create_recommendation_tab(UserPreferences, get_breed_recommendations, format_recommendation_html, history_component):
54
 
55
  with gr.TabItem("Breed Recommendation"):
@@ -214,23 +174,23 @@ def create_recommendation_tab(UserPreferences, get_breed_recommendations, format
214
  def on_find_match_click(*args):
215
  try:
216
  user_prefs = UserPreferences(
217
- living_space=args[0],
218
- yard_access=args[1],
219
- exercise_time=args[2],
220
- exercise_type=args[3],
221
- grooming_commitment=args[4],
222
- size_preference=args[5],
223
- experience_level=args[6],
224
- time_availability=args[7],
225
- has_children=args[8],
226
- children_age=args[9] if args[8] else None,
227
- noise_tolerance=args[10],
228
- space_for_play=True if args[0] != "apartment" else False,
229
- other_pets=False,
230
- climate="moderate",
231
- health_sensitivity="medium",
232
- barking_acceptance=args[10]
233
- )
234
 
235
  recommendations = get_breed_recommendations(user_prefs, top_n=10)
236
 
 
10
  from search_history import create_history_tab, create_history_component
11
 
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def create_recommendation_tab(UserPreferences, get_breed_recommendations, format_recommendation_html, history_component):
14
 
15
  with gr.TabItem("Breed Recommendation"):
 
174
  def on_find_match_click(*args):
175
  try:
176
  user_prefs = UserPreferences(
177
+ living_space=args[0],
178
+ yard_access=args[1],
179
+ exercise_time=args[2],
180
+ exercise_type=args[3],
181
+ grooming_commitment=args[4],
182
+ size_preference=args[5],
183
+ experience_level=args[6],
184
+ time_availability=args[7],
185
+ has_children=args[8],
186
+ children_age=args[9] if args[8] else None,
187
+ noise_tolerance=args[10],
188
+ space_for_play=True if args[0] != "apartment" else False,
189
+ other_pets=False,
190
+ climate="moderate",
191
+ health_sensitivity="medium",
192
+ barking_acceptance=args[10]
193
+ )
194
 
195
  recommendations = get_breed_recommendations(user_prefs, top_n=10)
196