DawnC commited on
Commit
2764ccd
1 Parent(s): d6a4bd7

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +33 -30
scoring_calculation_system.py CHANGED
@@ -838,51 +838,54 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
838
 
839
  # 調整權重配置
840
  base_weights = {
841
- 'space': 0.25, # 從 0.28 降低
842
- 'exercise': 0.15, # 從 0.18 降低
843
- 'grooming': 0.10, # 從 0.12 降低
844
- 'experience': 0.20, # 從 0.22 降低
845
- 'health': 0.10, # 從 0.12 降低
846
- 'noise': 0.05 # 從 0.08 降低
847
  }
848
 
849
- # 如果有孩童,加入家庭安全權重
850
  if user_prefs.has_children:
851
- base_weights['family_safety'] = 0.15 # 新增家庭安全權重
852
- # 重新標準化其他權重
853
- total = sum(base_weights.values())
854
- weights = {k: v/total for k, v in base_weights.items()}
 
 
 
 
 
 
 
855
  else:
856
- weights = base_weights
 
857
 
858
- # 計算加權總分
859
- weighted_score = sum(score * weights[category] for category, score in scores.items())
860
-
861
- # 加入品種加分的影響
862
- # breed_bonus 的影響應該要在加權總分之後,但在最終放大之前
863
- adjusted_score = weighted_score * (1 + breed_bonus) # breed_bonus 作為乘數效果
864
 
865
  def amplify_score(score):
866
  """
867
- 優化分數放大函數,加入更強的差異化效果
868
  """
869
- # 基礎調整 - 降低基準點使差異更明顯
870
- adjusted = (score - 0.40) * 2.0 # 從 0.35 降至 0.40,乘數從 1.8 提高到 2.0
871
 
872
- # 使用更高的指數使曲線更陡峭
873
- amplified = pow(adjusted, 3.5) / 6.2 + score # 指數從 3.2 提高到 3.5
874
 
875
- # 更嚴格的高分處理
876
- if amplified > 0.85: # 從 0.90 降至 0.85
877
- amplified = 0.85 + (amplified - 0.85) * 0.4 # 係數從 0.5 降至 0.4
878
 
879
- # 調整分數範圍
880
- final_score = max(0.60, min(0.95, amplified)) # 最低分從 0.55 提高到 0.60
881
 
882
  return round(final_score, 3)
883
 
884
- # 計算最終分數
885
- final_score = amplify_score(adjusted_score)
886
 
887
  # 四捨五入所有分數並回傳
888
  scores = {k: round(v, 4) for k, v in scores.items()}
 
838
 
839
  # 調整權重配置
840
  base_weights = {
841
+ 'space': 0.25,
842
+ 'exercise': 0.15,
843
+ 'grooming': 0.10,
844
+ 'experience': 0.20,
845
+ 'health': 0.10,
846
+ 'noise': 0.05
847
  }
848
 
 
849
  if user_prefs.has_children:
850
+ # 不直接加入 family_safety 到權重中
851
+ # 而是作為一個獨立的修正因子
852
+ family_safety_score = calculate_family_safety_score(breed_info, user_prefs.children_age)
853
+
854
+ # 計算基礎加權分數
855
+ weighted_score = sum(score * base_weights[category] for category, score in scores.items())
856
+
857
+ # 將 family_safety_score 作為調整因子
858
+ # 使用較溫和的影響方式
859
+ safety_adjustment = (family_safety_score * 0.7) + 0.3 # 確保即使最低的安全分數也只會降低 70%
860
+ adjusted_score = weighted_score * safety_adjustment
861
  else:
862
+ weighted_score = sum(score * base_weights[category] for category, score in scores.items())
863
+ adjusted_score = weighted_score
864
 
865
+ # 再加入品種加分的影響
866
+ breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
867
+ final_weighted_score = adjusted_score * (1 + breed_bonus)
 
 
 
868
 
869
  def amplify_score(score):
870
  """
871
+ 修改放大函數,讓分數差異更明顯
872
  """
873
+ # 基礎調整
874
+ adjusted = (score - 0.3) * 1.5
875
 
876
+ # 使用較溫和的指數
877
+ amplified = pow(adjusted, 2.8) / 4.5 + score
878
 
879
+ # 高分區間的處理
880
+ if amplified > 0.90:
881
+ amplified = 0.90 + (amplified - 0.90) * 0.3
882
 
883
+ # 擴大分數範圍(0.45-0.95)
884
+ final_score = max(0.45, min(0.95, amplified))
885
 
886
  return round(final_score, 3)
887
 
888
+ final_score = amplify_score(final_weighted_score)
 
889
 
890
  # 四捨五入所有分數並回傳
891
  scores = {k: round(v, 4) for k, v in scores.items()}