Spaces:
Running
Running
Update recommendation_html_format.py
Browse files
recommendation_html_format.py
CHANGED
@@ -469,6 +469,12 @@ def get_breed_recommendations(user_prefs: UserPreferences, top_n: int = 10) -> L
|
|
469 |
if not isinstance(breed_info, dict):
|
470 |
continue
|
471 |
|
|
|
|
|
|
|
|
|
|
|
|
|
472 |
# 獲取噪音資訊
|
473 |
noise_info = breed_noise_info.get(breed, {
|
474 |
"noise_notes": "Noise information not available",
|
@@ -532,8 +538,9 @@ def get_breed_recommendations(user_prefs: UserPreferences, top_n: int = 10) -> L
|
|
532 |
'info': breed_info,
|
533 |
'noise_info': noise_info # 添加噪音資訊到推薦結果
|
534 |
})
|
|
|
535 |
# 嚴格按照 final_score 排序
|
536 |
-
recommendations.sort(key=lambda x: (round(-x['final_score'], 4), x['breed'] )) #
|
537 |
|
538 |
# 選擇前N名並確保正確排序
|
539 |
final_recommendations = []
|
@@ -541,19 +548,19 @@ def get_breed_recommendations(user_prefs: UserPreferences, top_n: int = 10) -> L
|
|
541 |
rank = 1
|
542 |
|
543 |
for rec in recommendations:
|
544 |
-
|
|
|
545 |
break
|
546 |
-
|
547 |
current_score = rec['final_score']
|
548 |
-
|
549 |
# 確保分數遞減
|
550 |
if last_score is not None and current_score > last_score:
|
551 |
continue
|
552 |
-
|
553 |
# 添加排名資訊
|
554 |
rec['rank'] = rank
|
555 |
final_recommendations.append(rec)
|
556 |
-
|
557 |
last_score = current_score
|
558 |
rank += 1
|
559 |
|
|
|
469 |
if not isinstance(breed_info, dict):
|
470 |
continue
|
471 |
|
472 |
+
if user_prefs.size_preference != "no_preference":
|
473 |
+
breed_size = breed_info.get('Size', '').lower()
|
474 |
+
user_size = user_prefs.size_preference.lower()
|
475 |
+
if breed_size != user_size:
|
476 |
+
continue
|
477 |
+
|
478 |
# 獲取噪音資訊
|
479 |
noise_info = breed_noise_info.get(breed, {
|
480 |
"noise_notes": "Noise information not available",
|
|
|
538 |
'info': breed_info,
|
539 |
'noise_info': noise_info # 添加噪音資訊到推薦結果
|
540 |
})
|
541 |
+
|
542 |
# 嚴格按照 final_score 排序
|
543 |
+
recommendations.sort(key=lambda x: (round(-x['final_score'], 4), x['breed'] )) # 負號降序排列
|
544 |
|
545 |
# 選擇前N名並確保正確排序
|
546 |
final_recommendations = []
|
|
|
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
|
565 |
rank += 1
|
566 |
|