Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +31 -30
scoring_calculation_system.py
CHANGED
@@ -929,52 +929,53 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
929 |
'noise': calculate_noise_score(breed_info.get('Breed', ''), user_prefs.noise_tolerance)
|
930 |
}
|
931 |
|
932 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
933 |
if user_prefs.has_children:
|
934 |
family_safety = calculate_family_safety_score(breed_info, user_prefs.children_age)
|
935 |
-
|
936 |
-
#
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
weights = {
|
949 |
-
'space': 0.28,
|
950 |
-
'exercise': 0.18,
|
951 |
-
'grooming': 0.12,
|
952 |
-
'experience': 0.22,
|
953 |
-
'health': 0.12,
|
954 |
-
'noise': 0.08
|
955 |
-
}
|
956 |
|
957 |
-
#
|
958 |
weighted_score = sum(score * weights[category] for category, score in scores.items())
|
959 |
|
960 |
-
#
|
961 |
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
962 |
-
|
|
|
|
|
|
|
963 |
|
964 |
-
# 保持原有的 amplify_score 函數
|
965 |
def amplify_score(score):
|
966 |
adjusted = (score - 0.25) * 1.8
|
967 |
amplified = pow(adjusted, 2.2) / 3.5 + score
|
968 |
-
|
969 |
if amplified > 0.85:
|
970 |
amplified = 0.85 + (amplified - 0.85) * 0.6
|
971 |
-
|
972 |
final_score = max(0.45, min(0.95, amplified))
|
973 |
return round(final_score, 3)
|
974 |
|
975 |
final_score = amplify_score(weighted_score)
|
976 |
-
|
977 |
-
# 準備回傳結果
|
978 |
scores = {k: round(v, 4) for k, v in scores.items()}
|
979 |
scores['overall'] = round(final_score, 4)
|
980 |
|
|
|
929 |
'noise': calculate_noise_score(breed_info.get('Breed', ''), user_prefs.noise_tolerance)
|
930 |
}
|
931 |
|
932 |
+
# 基本權重設定
|
933 |
+
weights = {
|
934 |
+
'space': 0.28,
|
935 |
+
'exercise': 0.18,
|
936 |
+
'grooming': 0.12,
|
937 |
+
'experience': 0.22,
|
938 |
+
'health': 0.12,
|
939 |
+
'noise': 0.08
|
940 |
+
}
|
941 |
+
|
942 |
+
# 如果有孩童,我們需要調整各個分數,而不是增加新的分數項目
|
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):
|
970 |
adjusted = (score - 0.25) * 1.8
|
971 |
amplified = pow(adjusted, 2.2) / 3.5 + score
|
|
|
972 |
if amplified > 0.85:
|
973 |
amplified = 0.85 + (amplified - 0.85) * 0.6
|
|
|
974 |
final_score = max(0.45, min(0.95, amplified))
|
975 |
return round(final_score, 3)
|
976 |
|
977 |
final_score = amplify_score(weighted_score)
|
978 |
+
|
|
|
979 |
scores = {k: round(v, 4) for k, v in scores.items()}
|
980 |
scores['overall'] = round(final_score, 4)
|
981 |
|