Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +46 -47
scoring_calculation_system.py
CHANGED
@@ -929,69 +929,68 @@ 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 |
-
|
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 |
-
'toddler':
|
949 |
-
|
950 |
-
|
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 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
973 |
|
974 |
-
#
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
979 |
}
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
|
|
|
985 |
def amplify_score(score):
|
986 |
adjusted = (score - 0.25) * 1.8
|
987 |
amplified = pow(adjusted, 2.2) / 3.5 + score
|
988 |
if amplified > 0.85:
|
989 |
amplified = 0.85 + (amplified - 0.85) * 0.6
|
990 |
-
|
991 |
-
return round(final_score, 3)
|
992 |
|
993 |
-
final_score = amplify_score(
|
994 |
|
|
|
995 |
scores = {k: round(v, 4) for k, v in scores.items()}
|
996 |
scores['overall'] = round(final_score, 4)
|
997 |
|
|
|
929 |
'noise': calculate_noise_score(breed_info.get('Breed', ''), user_prefs.noise_tolerance)
|
930 |
}
|
931 |
|
932 |
+
# 2. 計算品種加分
|
933 |
+
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
934 |
|
935 |
+
# 3. 如果有孩童,計算安全分數,但不直接修改基礎分數
|
936 |
if user_prefs.has_children:
|
937 |
family_safety = calculate_family_safety_score(breed_info, user_prefs.children_age)
|
938 |
|
939 |
+
# 創建安全性調整係數
|
940 |
+
safety_adjustments = {
|
941 |
+
'toddler': 0.6, # 對幼童最嚴格
|
942 |
+
'school_age': 0.75, # 學齡兒童較寬鬆
|
943 |
+
'teenager': 0.85 # 青少年最寬鬆
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
944 |
}
|
945 |
|
946 |
+
# 調整權重而不是直接修改分數
|
947 |
+
safety_weight = safety_adjustments[user_prefs.children_age]
|
948 |
+
|
949 |
+
# 修改最終加權計算方式
|
950 |
+
weights = {
|
951 |
+
'space': 0.22,
|
952 |
+
'exercise': 0.15,
|
953 |
+
'grooming': 0.10,
|
954 |
+
'experience': 0.18,
|
955 |
+
'health': 0.10,
|
956 |
+
'noise': 0.05
|
957 |
+
}
|
958 |
|
959 |
+
# 加入安全性權重
|
960 |
+
final_score = (
|
961 |
+
sum(score * weights[category] for category, score in scores.items()) * safety_weight +
|
962 |
+
family_safety * (1 - safety_weight)
|
963 |
+
)
|
964 |
+
|
965 |
+
# 品種加分也要考慮安全性
|
966 |
+
breed_bonus *= family_safety
|
967 |
+
|
968 |
+
else:
|
969 |
+
# 原有的權重
|
970 |
+
weights = {
|
971 |
+
'space': 0.28,
|
972 |
+
'exercise': 0.18,
|
973 |
+
'grooming': 0.12,
|
974 |
+
'experience': 0.22,
|
975 |
+
'health': 0.12,
|
976 |
+
'noise': 0.08
|
977 |
}
|
978 |
+
final_score = sum(score * weights[category] for category, score in scores.items())
|
979 |
+
|
980 |
+
# 4. 應用品種加分
|
981 |
+
final_score *= (1 + breed_bonus * 0.2)
|
982 |
|
983 |
+
# 5. 最終分數調整
|
984 |
def amplify_score(score):
|
985 |
adjusted = (score - 0.25) * 1.8
|
986 |
amplified = pow(adjusted, 2.2) / 3.5 + score
|
987 |
if amplified > 0.85:
|
988 |
amplified = 0.85 + (amplified - 0.85) * 0.6
|
989 |
+
return max(0.45, min(0.95, amplified))
|
|
|
990 |
|
991 |
+
final_score = amplify_score(final_score)
|
992 |
|
993 |
+
# 6. 回傳結果
|
994 |
scores = {k: round(v, 4) for k, v in scores.items()}
|
995 |
scores['overall'] = round(final_score, 4)
|
996 |
|