Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +40 -108
scoring_calculation_system.py
CHANGED
@@ -601,125 +601,57 @@ 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 |
base_scores = {
|
608 |
"High": {
|
609 |
-
"beginner": 0.
|
610 |
-
"intermediate": 0.
|
611 |
-
"advanced": 0.
|
612 |
},
|
613 |
"Moderate": {
|
614 |
-
"beginner": 0.
|
615 |
-
"intermediate": 0.
|
616 |
-
"advanced": 0.
|
617 |
},
|
618 |
"Low": {
|
619 |
-
"beginner": 0.
|
620 |
-
"intermediate": 0.
|
621 |
-
"advanced": 0.
|
622 |
}
|
623 |
}
|
624 |
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
'stubborn': -0.15,
|
632 |
-
|
633 |
-
|
634 |
-
'
|
635 |
-
'
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
easy_traits = {
|
641 |
-
'gentle': 0.08,
|
642 |
-
'friendly': 0.08,
|
643 |
-
'eager to please': 0.08,
|
644 |
-
'patient': 0.06,
|
645 |
-
'adaptable': 0.06,
|
646 |
-
'calm': 0.05
|
647 |
-
}
|
648 |
-
|
649 |
-
for trait, penalty in difficult_traits.items():
|
650 |
-
if trait in temperament_lower:
|
651 |
-
temperament_adjustments += penalty * 1.2
|
652 |
-
|
653 |
-
for trait, bonus in easy_traits.items():
|
654 |
-
if trait in temperament_lower:
|
655 |
-
temperament_adjustments += bonus
|
656 |
-
|
657 |
-
elif user_experience == "intermediate":
|
658 |
-
# 重新設計 intermediate 的評估邏輯
|
659 |
-
challenging_traits = {
|
660 |
-
'aggressive': -0.18, # 加重危險特徵的懲罰
|
661 |
-
'stubborn': -0.12,
|
662 |
-
'dominant': -0.10,
|
663 |
-
'protective': -0.08,
|
664 |
-
'independent': -0.08,
|
665 |
-
'energetic': -0.06
|
666 |
-
}
|
667 |
-
|
668 |
-
manageable_traits = {
|
669 |
-
'intelligent': 0.06,
|
670 |
-
'trainable': 0.06,
|
671 |
-
'adaptable': 0.05,
|
672 |
-
'patient': 0.04
|
673 |
-
}
|
674 |
-
|
675 |
-
# 計算特徵影響
|
676 |
-
negative_impact = 0
|
677 |
-
positive_impact = 0
|
678 |
-
|
679 |
-
for trait, penalty in challenging_traits.items():
|
680 |
-
if trait in temperament_lower:
|
681 |
-
negative_impact += penalty
|
682 |
-
|
683 |
-
for trait, bonus in manageable_traits.items():
|
684 |
-
if trait in temperament_lower:
|
685 |
-
positive_impact += bonus
|
686 |
-
|
687 |
-
# 限制正面特徵的累積效果
|
688 |
-
temperament_adjustments = negative_impact + min(0.12, positive_impact)
|
689 |
-
|
690 |
-
else: # advanced
|
691 |
-
# 重新設計 advanced 的評估邏輯
|
692 |
-
risk_traits = {
|
693 |
-
'aggressive': -0.15, # 即使是 advanced 也要懲罰危險特徵
|
694 |
-
'nervous': -0.12,
|
695 |
-
'unpredictable': -0.12,
|
696 |
-
'territorial': -0.10
|
697 |
-
}
|
698 |
-
|
699 |
-
skill_traits = {
|
700 |
-
'intelligent': 0.04,
|
701 |
-
'trainable': 0.04,
|
702 |
-
'independent': 0.03,
|
703 |
-
'protective': 0.03
|
704 |
}
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
temperament_adjustments = negative_impact + min(0.10, positive_impact)
|
720 |
|
721 |
-
|
722 |
-
final_score = max(0.2, min(0.95, score + temperament_adjustments))
|
723 |
return final_score
|
724 |
|
725 |
|
|
|
601 |
|
602 |
|
603 |
def calculate_experience_score(care_level: str, user_experience: str, temperament: str) -> float:
|
604 |
+
# 基礎分數矩陣
|
|
|
|
|
605 |
base_scores = {
|
606 |
"High": {
|
607 |
+
"beginner": 0.3, # 高難度品種對新手較難
|
608 |
+
"intermediate": 0.6,
|
609 |
+
"advanced": 0.8 # 即使是高手也要留有調整空間
|
610 |
},
|
611 |
"Moderate": {
|
612 |
+
"beginner": 0.5,
|
613 |
+
"intermediate": 0.7,
|
614 |
+
"advanced": 0.85
|
615 |
},
|
616 |
"Low": {
|
617 |
+
"beginner": 0.7,
|
618 |
+
"intermediate": 0.8,
|
619 |
+
"advanced": 0.9
|
620 |
}
|
621 |
}
|
622 |
|
623 |
+
base_score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
624 |
+
|
625 |
+
# 根據經驗等級有不同的特徵評估標準
|
626 |
+
trait_scores = {
|
627 |
+
"beginner": {
|
628 |
+
'positive': {'friendly': 0.1, 'gentle': 0.1, 'patient': 0.08},
|
629 |
+
'negative': {'aggressive': -0.2, 'stubborn': -0.15, 'dominant': -0.15}
|
630 |
+
},
|
631 |
+
"intermediate": {
|
632 |
+
'positive': {'intelligent': 0.08, 'trainable': 0.08, 'adaptable': 0.06},
|
633 |
+
'negative': {'aggressive': -0.15, 'stubborn': -0.1, 'dominant': -0.1}
|
634 |
+
},
|
635 |
+
"advanced": {
|
636 |
+
'positive': {'intelligent': 0.06, 'independent': 0.06, 'protective': 0.05},
|
637 |
+
'negative': {'aggressive': -0.1, 'nervous': -0.08, 'unpredictable': -0.08}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
638 |
}
|
639 |
+
}
|
640 |
+
|
641 |
+
temperament_lower = temperament.lower()
|
642 |
+
current_traits = trait_scores[user_experience]
|
643 |
+
|
644 |
+
# 計算特徵調整
|
645 |
+
trait_adjustment = 0
|
646 |
+
for trait, value in current_traits['positive'].items():
|
647 |
+
if trait in temperament_lower:
|
648 |
+
trait_adjustment += value
|
649 |
+
|
650 |
+
for trait, value in current_traits['negative'].items():
|
651 |
+
if trait in temperament_lower:
|
652 |
+
trait_adjustment += value
|
|
|
653 |
|
654 |
+
final_score = max(0.2, min(0.95, base_score + trait_adjustment))
|
|
|
655 |
return final_score
|
656 |
|
657 |
|