DawnC commited on
Commit
1b88764
1 Parent(s): a5a0a2f

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. 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.65, # 中級玩家可以應付,但仍有改善空間
620
- "advanced": 1.0 # 資深者能完全勝任
621
  },
622
  "Moderate": {
623
- "beginner": 0.35, # 適中難度對新手來說仍具挑戰
624
- "intermediate": 0.82, # 中級玩家有很好的勝任能力
625
- "advanced": 1.0 # 資深者完全勝任
626
  },
627
  "Low": {
628
- "beginner": 0.72, # 低難度品種適合新手
629
- "intermediate": 0.92, # 中級玩家幾乎完全勝任
630
- "advanced": 1.0 # 資深者完全勝任
631
  }
632
  }
633
 
634
- # 取得基礎分數
635
  score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
636
 
637
- # 性格特徵評估 - 根據經驗等級調整權重
638
- temperament_lower = temperament.lower()
639
- temperament_adjustments = 0.0
640
-
641
- if user_experience == "beginner":
642
- # 新手不適合的特徵 - 更嚴格的懲罰
643
- difficult_traits = {
644
- 'stubborn': -0.15, # 加重固執的懲罰
645
- 'independent': -0.12, # 加重獨立性的懲罰
646
- 'dominant': -0.12, # 加重支配性的懲罰
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
- positive_traits = {
695
- 'intelligent': 0.06,
696
- 'trainable': 0.06,
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
- else: # advanced
713
- base_scores = {
714
- "High": {"advanced": 0.75}, # 降低基礎分數
715
- "Moderate": {"advanced": 0.82},
716
- "Low": {"advanced": 0.88}
717
- }
718
- score = base_scores.get(care_level, base_scores["Moderate"])[user_experience]
719
-
720
- # 即使是進階玩家也需要考慮的風險特徵
721
- risk_traits = {
722
- 'aggressive': -0.15, # 最嚴重的風險特徵
723
- 'nervous': -0.12,
724
- 'unpredictable': -0.12,
725
- 'territorial': -0.10,
726
- 'dominant': -0.08,
727
- 'strong-willed': -0.06
728
- }
729
-
730
- # 進階玩家可以處理的特徵,但仍需謹慎
731
- manageable_traits = {
732
- 'intelligent': 0.05,
733
- 'trainable': 0.04,
734
- 'independent': 0.03,
735
- 'protective': 0.02
736
- }
737
-
738
- # 先計算風險特徵
739
- for trait, penalty in risk_traits.items():
740
- if trait in temperament_lower:
741
- temperament_adjustments += penalty
742
-
743
- # 再加上可控制特徵,但有限制
744
- positive_adjustment = 0
745
- for trait, bonus in manageable_traits.items():
746
- if trait in temperament_lower:
747
- positive_adjustment += bonus
748
- temperament_adjustments += min(0.10, positive_adjustment) # 限制正面特徵的總影響
 
 
 
 
 
749
 
750
- # 確���最終分數在合理範圍內
751
- final_score = max(0.2, min(1.0, score + temperament_adjustments))
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: