DawnC commited on
Commit
37c8c7d
1 Parent(s): 8aa9d02

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. 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
- 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
 
 
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