DawnC commited on
Commit
5720b16
1 Parent(s): 2deb489

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +33 -17
scoring_calculation_system.py CHANGED
@@ -943,27 +943,43 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
943
  if user_prefs.has_children:
944
  family_safety = calculate_family_safety_score(breed_info, user_prefs.children_age)
945
 
946
- # 根據家庭安全分數調整其他分數
947
- # 空間適應性調整:大型犬在有幼童時需要更多考慮
948
- scores['space'] *= (0.7 + (family_safety * 0.3))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
949
 
950
- # 經驗需求調整:有孩童時經驗要求提高
951
- scores['experience'] *= (0.6 + (family_safety * 0.4))
952
 
953
- # 運動需求調整:過於活潑的品種需要更謹慎
954
- scores['exercise'] *= (0.8 + (family_safety * 0.2))
 
955
 
956
- # 噪音容忍度調整:對幼童更敏感
957
- scores['noise'] *= (0.7 + (family_safety * 0.3))
958
-
959
- # 計算加權總分
 
 
 
 
960
  weighted_score = sum(score * weights[category] for category, score in scores.items())
961
-
962
- # 加入品種額外加分的影響
963
- breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
964
- # 如果有孩童,品種加分的影響要考慮家庭因素
965
- if user_prefs.has_children:
966
- breed_bonus *= family_safety
967
  weighted_score *= (1 + breed_bonus * 0.2)
968
 
969
  def amplify_score(score):
 
943
  if user_prefs.has_children:
944
  family_safety = calculate_family_safety_score(breed_info, user_prefs.children_age)
945
 
946
+ # 根據孩童年齡設定不同的調整強度
947
+ age_adjustments = {
948
+ 'toddler': {
949
+ 'space': (0.5, 0.5), # (基礎係數, 安全係數權重)
950
+ 'experience': (0.4, 0.6), # 幼童需要更嚴格的經驗要求
951
+ 'exercise': (0.6, 0.4),
952
+ 'noise': (0.5, 0.5)
953
+ },
954
+ 'school_age': {
955
+ 'space': (0.6, 0.4),
956
+ 'experience': (0.5, 0.5),
957
+ 'exercise': (0.7, 0.3),
958
+ 'noise': (0.6, 0.4)
959
+ },
960
+ 'teenager': {
961
+ 'space': (0.7, 0.3),
962
+ 'experience': (0.6, 0.4),
963
+ 'exercise': (0.8, 0.2),
964
+ 'noise': (0.7, 0.3)
965
+ }
966
+ }
967
 
968
+ adjustments = age_adjustments[user_prefs.children_age]
 
969
 
970
+ # 應用更嚴格的調整
971
+ for category, (base_coef, safety_weight) in adjustments.items():
972
+ scores[category] *= (base_coef + (family_safety * safety_weight))
973
 
974
+ # 品種加分也需要根據年齡組進行調整
975
+ breed_bonus_adjustments = {
976
+ 'toddler': 0.4, # 幼童情況下品種加分影響最小
977
+ 'school_age': 0.6,
978
+ 'teenager': 0.8
979
+ }
980
+ breed_bonus *= (breed_bonus_adjustments[user_prefs.children_age] * family_safety)
981
+
982
  weighted_score = sum(score * weights[category] for category, score in scores.items())
 
 
 
 
 
 
983
  weighted_score *= (1 + breed_bonus * 0.2)
984
 
985
  def amplify_score(score):