Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +68 -133
scoring_calculation_system.py
CHANGED
@@ -601,155 +601,90 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
601 |
|
602 |
|
603 |
def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
604 |
-
|
605 |
-
計算使用者經驗與品種需求的匹配分數
|
606 |
-
|
607 |
-
參數說明:
|
608 |
-
care_level: 品種的照顧難度 ("High", "Moderate", "Low")
|
609 |
-
user_experience: 使用者經驗等級 ("beginner", "intermediate", "advanced")
|
610 |
-
temperament: 品種的性格特徵描述
|
611 |
|
612 |
-
|
613 |
-
float: 0.2-1.0 之間的匹配分數
|
614 |
-
"""
|
615 |
-
# 基礎分數矩陣 - 更大的分數差異來反映經驗重要性
|
616 |
base_scores = {
|
617 |
"High": {
|
618 |
-
"beginner": 0.12,
|
619 |
-
"intermediate": 0.
|
620 |
-
"advanced":
|
621 |
},
|
622 |
"Moderate": {
|
623 |
-
"beginner": 0.35,
|
624 |
-
"intermediate": 0.
|
625 |
-
"advanced":
|
626 |
},
|
627 |
"Low": {
|
628 |
-
"beginner": 0.72,
|
629 |
-
"intermediate": 0.
|
630 |
-
"advanced":
|
631 |
}
|
632 |
}
|
633 |
|
634 |
-
# 取得基礎分數
|
635 |
score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
636 |
|
637 |
-
#
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
'
|
645 |
-
'
|
646 |
-
'
|
647 |
-
'strong-willed': -0.10, # 加重強勢的懲罰
|
648 |
-
'protective': -0.08, # 加重保護性的懲罰
|
649 |
-
'aloof': -0.08, # 加重冷漠的懲罰
|
650 |
-
'energetic': -0.06 # 輕微懲罰高能量
|
651 |
-
}
|
652 |
-
|
653 |
-
# 新手友善的特徵 - 提供更多獎勵
|
654 |
-
easy_traits = {
|
655 |
-
'gentle': 0.08, # 增加溫和的獎勵
|
656 |
-
'friendly': 0.08, # 增加友善的獎勵
|
657 |
-
'eager to please': 0.08, # 增加順從的獎勵
|
658 |
-
'patient': 0.06, # 獎勵耐心
|
659 |
-
'adaptable': 0.06, # 獎勵適應性
|
660 |
-
'calm': 0.05 # 獎勵冷靜
|
661 |
-
}
|
662 |
-
|
663 |
-
# 計算特徵調整
|
664 |
-
for trait, penalty in difficult_traits.items():
|
665 |
-
if trait in temperament_lower:
|
666 |
-
temperament_adjustments += penalty * 1.2 # 加重新手的懲罰
|
667 |
-
|
668 |
-
for trait, bonus in easy_traits.items():
|
669 |
-
if trait in temperament_lower:
|
670 |
-
temperament_adjustments += bonus
|
671 |
-
|
672 |
-
# 品種特殊調整
|
673 |
-
if any(term in temperament_lower for term in ['terrier', 'working', 'guard']):
|
674 |
-
temperament_adjustments -= 0.12 # 加重對特定類型品種的懲罰
|
675 |
-
|
676 |
-
elif user_experience == "intermediate":
|
677 |
-
base_scores = {
|
678 |
-
"High": {"intermediate": 0.65},
|
679 |
-
"Moderate": {"intermediate": 0.75},
|
680 |
-
"Low": {"intermediate": 0.85}
|
681 |
-
}
|
682 |
-
score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
683 |
-
|
684 |
-
# 中級玩家特徵評估 - 參考 beginner 的邏輯結構
|
685 |
-
challenging_traits = {
|
686 |
-
'stubborn': -0.10, # 仍然需要扣分,但比 beginner 輕
|
687 |
-
'independent': -0.08,
|
688 |
-
'dominant': -0.08,
|
689 |
-
'protective': -0.06,
|
690 |
-
'aggressive': -0.12, # 仍然嚴重扣分
|
691 |
-
'nervous': -0.08
|
692 |
}
|
693 |
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
'adaptable': 0.05,
|
698 |
-
'calm': 0.04,
|
699 |
-
'friendly': 0.04
|
700 |
-
}
|
701 |
-
|
702 |
-
# 計算特徵調整
|
703 |
-
for trait, penalty in challenging_traits.items():
|
704 |
-
if trait in temperament_lower:
|
705 |
-
temperament_adjustments += penalty
|
706 |
-
|
707 |
-
for trait, bonus in positive_traits.items():
|
708 |
-
if trait in temperament_lower:
|
709 |
-
if temperament_adjustments + bonus <= 0.12: # 限制正面特徵累積
|
710 |
-
temperament_adjustments += bonus
|
711 |
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
|
|
|
|
|
|
|
|
|
|
749 |
|
750 |
-
#
|
751 |
-
|
752 |
-
return final_score
|
753 |
|
754 |
|
755 |
def calculate_health_score(breed_name: str) -> float:
|
|
|
601 |
|
602 |
|
603 |
def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
604 |
+
temperament_lower = temperament.lower()
|
|
|
|
|
|
|
|
|
|
|
|
|
605 |
|
606 |
+
# 重新設計基礎分數,降低起始點以留出調整空間
|
|
|
|
|
|
|
607 |
base_scores = {
|
608 |
"High": {
|
609 |
+
"beginner": 0.12,
|
610 |
+
"intermediate": 0.45, # 降低基礎分數
|
611 |
+
"advanced": 0.60 # 降低基礎分數
|
612 |
},
|
613 |
"Moderate": {
|
614 |
+
"beginner": 0.35,
|
615 |
+
"intermediate": 0.55,
|
616 |
+
"advanced": 0.70
|
617 |
},
|
618 |
"Low": {
|
619 |
+
"beginner": 0.72,
|
620 |
+
"intermediate": 0.65,
|
621 |
+
"advanced": 0.75
|
622 |
}
|
623 |
}
|
624 |
|
|
|
625 |
score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
626 |
|
627 |
+
# 計算品種複雜度分數
|
628 |
+
def calculate_complexity_score(temperament: str) -> float:
|
629 |
+
complexity_factors = {
|
630 |
+
'aggressive': 0.3,
|
631 |
+
'stubborn': 0.25,
|
632 |
+
'independent': 0.2,
|
633 |
+
'protective': 0.2,
|
634 |
+
'dominant': 0.2,
|
635 |
+
'strong-willed': 0.15,
|
636 |
+
'energetic': 0.15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
637 |
}
|
638 |
|
639 |
+
complexity = sum(value for trait, value in complexity_factors.items()
|
640 |
+
if trait in temperament_lower)
|
641 |
+
return min(1.0, complexity)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
642 |
|
643 |
+
complexity = calculate_complexity_score(temperament)
|
644 |
+
|
645 |
+
# 根據經驗等級調整複雜度的影響
|
646 |
+
experience_multipliers = {
|
647 |
+
"beginner": 1.5, # 新手受複雜度影響最大
|
648 |
+
"intermediate": 0.8, # 中級玩家受中等影響
|
649 |
+
"advanced": 0.4 # 資深玩家受影響較小但仍然存在
|
650 |
+
}
|
651 |
+
|
652 |
+
# 應用複雜度調整
|
653 |
+
complexity_impact = complexity * experience_multipliers[user_experience]
|
654 |
+
score = score * (1 - complexity_impact)
|
655 |
+
|
656 |
+
# 特徵評估(保持動態性)
|
657 |
+
positive_trait_limit = {
|
658 |
+
"beginner": 0.1,
|
659 |
+
"intermediate": 0.15,
|
660 |
+
"advanced": 0.2
|
661 |
+
}
|
662 |
+
|
663 |
+
negative_trait_impact = {
|
664 |
+
"beginner": 1.5,
|
665 |
+
"intermediate": 1.0,
|
666 |
+
"advanced": 0.7
|
667 |
+
}
|
668 |
+
|
669 |
+
# 累積特徵影響
|
670 |
+
positive_impact = 0
|
671 |
+
negative_impact = 0
|
672 |
+
|
673 |
+
# 計算特徵影響
|
674 |
+
for trait in temperament_lower.split():
|
675 |
+
if trait in ['gentle', 'friendly', 'patient', 'calm']:
|
676 |
+
positive_impact += 0.05
|
677 |
+
if trait in ['aggressive', 'nervous', 'unpredictable']:
|
678 |
+
negative_impact += 0.08 * negative_trait_impact[user_experience]
|
679 |
+
|
680 |
+
# 限制正面特徵影響
|
681 |
+
positive_impact = min(positive_trait_limit[user_experience], positive_impact)
|
682 |
+
|
683 |
+
# 應用特徵調整
|
684 |
+
final_score = score + positive_impact - negative_impact
|
685 |
|
686 |
+
# 確保分數在合理範圍內
|
687 |
+
return max(0.2, min(0.95, final_score))
|
|
|
688 |
|
689 |
|
690 |
def calculate_health_score(breed_name: str) -> float:
|