Spaces:
Running
on
Zero
Running
on
Zero
Update recommendation_html_format.py
Browse files
recommendation_html_format.py
CHANGED
|
@@ -441,7 +441,7 @@ def format_recommendation_html(recommendations: List[Dict], is_description_searc
|
|
| 441 |
html_content += "</div>"
|
| 442 |
return html_content
|
| 443 |
|
| 444 |
-
def get_breed_recommendations(user_prefs: UserPreferences, top_n: int =
|
| 445 |
"""基於使用者偏好推薦狗品種,確保正確的分數排序"""
|
| 446 |
print("Starting get_breed_recommendations")
|
| 447 |
recommendations = []
|
|
@@ -547,18 +547,17 @@ def get_breed_recommendations(user_prefs: UserPreferences, top_n: int = 10) -> L
|
|
| 547 |
last_score = None
|
| 548 |
rank = 1
|
| 549 |
|
|
|
|
|
|
|
|
|
|
| 550 |
for rec in recommendations:
|
| 551 |
-
|
| 552 |
-
if user_prefs.size_preference == "no_preference" and len(final_recommendations) >= top_n:
|
| 553 |
break
|
| 554 |
-
|
| 555 |
current_score = rec['final_score']
|
| 556 |
-
|
| 557 |
-
# 確保分數遞減
|
| 558 |
if last_score is not None and current_score > last_score:
|
| 559 |
continue
|
| 560 |
-
|
| 561 |
-
# 添加排名資訊
|
| 562 |
rec['rank'] = rank
|
| 563 |
final_recommendations.append(rec)
|
| 564 |
last_score = current_score
|
|
|
|
| 441 |
html_content += "</div>"
|
| 442 |
return html_content
|
| 443 |
|
| 444 |
+
def get_breed_recommendations(user_prefs: UserPreferences, top_n: int = 15) -> List[Dict]:
|
| 445 |
"""基於使用者偏好推薦狗品種,確保正確的分數排序"""
|
| 446 |
print("Starting get_breed_recommendations")
|
| 447 |
recommendations = []
|
|
|
|
| 547 |
last_score = None
|
| 548 |
rank = 1
|
| 549 |
|
| 550 |
+
available_breeds = len(recommendations)
|
| 551 |
+
max_to_return = min(available_breeds, top_n) # 不會超過實際可用品種數
|
| 552 |
+
|
| 553 |
for rec in recommendations:
|
| 554 |
+
if len(final_recommendations) >= max_to_return:
|
|
|
|
| 555 |
break
|
| 556 |
+
|
| 557 |
current_score = rec['final_score']
|
|
|
|
|
|
|
| 558 |
if last_score is not None and current_score > last_score:
|
| 559 |
continue
|
| 560 |
+
|
|
|
|
| 561 |
rec['rank'] = rank
|
| 562 |
final_recommendations.append(rec)
|
| 563 |
last_score = current_score
|