DawnC commited on
Commit
6a90adf
1 Parent(s): 21662d2

Update scoring_calculation_system.py

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