Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +102 -66
scoring_calculation_system.py
CHANGED
@@ -603,88 +603,124 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
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.
|
611 |
-
"advanced": 0.
|
612 |
},
|
613 |
"Moderate": {
|
614 |
"beginner": 0.35,
|
615 |
-
"intermediate": 0.
|
616 |
-
"advanced": 0.
|
617 |
},
|
618 |
"Low": {
|
619 |
"beginner": 0.72,
|
620 |
-
"intermediate": 0.
|
621 |
-
"advanced": 0.
|
622 |
}
|
623 |
}
|
624 |
|
625 |
score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
'stubborn': 0.
|
632 |
-
'independent': 0.
|
633 |
-
'
|
634 |
-
'
|
635 |
-
'
|
636 |
-
'
|
|
|
637 |
}
|
638 |
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
685 |
|
686 |
-
#
|
687 |
-
|
|
|
688 |
|
689 |
|
690 |
def calculate_health_score(breed_name: str) -> float:
|
|
|
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.55, # 從 0.65 降低,留出更多調整空間
|
611 |
+
"advanced": 0.75 # 從 1.0 降低,確保需要根據特徵調整
|
612 |
},
|
613 |
"Moderate": {
|
614 |
"beginner": 0.35,
|
615 |
+
"intermediate": 0.65, # 適當降低
|
616 |
+
"advanced": 0.82 # 適當降低
|
617 |
},
|
618 |
"Low": {
|
619 |
"beginner": 0.72,
|
620 |
+
"intermediate": 0.80,
|
621 |
+
"advanced": 0.88 # 仍然保持較高,但有調整空間
|
622 |
}
|
623 |
}
|
624 |
|
625 |
score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
|
626 |
+
temperament_adjustments = 0.0
|
627 |
+
|
628 |
+
if user_experience == "beginner":
|
629 |
+
# 保持原有的 beginner 邏輯,因為它運作良好
|
630 |
+
difficult_traits = {
|
631 |
+
'stubborn': -0.15,
|
632 |
+
'independent': -0.12,
|
633 |
+
'dominant': -0.12,
|
634 |
+
'strong-willed': -0.10,
|
635 |
+
'protective': -0.08,
|
636 |
+
'aloof': -0.08,
|
637 |
+
'energetic': -0.06
|
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 |
+
negative_impact = 0
|
708 |
+
positive_impact = 0
|
709 |
+
|
710 |
+
for trait, penalty in risk_traits.items():
|
711 |
+
if trait in temperament_lower:
|
712 |
+
negative_impact += penalty
|
713 |
+
|
714 |
+
for trait, bonus in skill_traits.items():
|
715 |
+
if trait in temperament_lower:
|
716 |
+
positive_impact += bonus
|
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 |
|
726 |
def calculate_health_score(breed_name: str) -> float:
|