Spaces:
Sleeping
Sleeping
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +64 -69
scoring_calculation_system.py
CHANGED
@@ -1066,81 +1066,76 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
1066 |
final_score = base_score + barking_penalty + special_adjustments + trainability_bonus
|
1067 |
return max(0.1, min(1.0, final_score))
|
1068 |
|
|
|
|
|
1069 |
print("\n=== 開始計算品種相容性分數 ===")
|
1070 |
print(f"處理品種: {breed_info.get('Breed', 'Unknown')}")
|
1071 |
print(f"品種信息: {breed_info}")
|
1072 |
print(f"使用者偏好: {vars(user_prefs)}")
|
1073 |
|
1074 |
-
#
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
1083 |
-
'
|
1084 |
-
|
1085 |
-
|
1086 |
-
|
1087 |
-
|
1088 |
-
),
|
1089 |
-
'
|
1090 |
-
|
1091 |
-
|
1092 |
-
),
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
),
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
|
1103 |
-
'health': calculate_health_score(
|
1104 |
-
breed_info.get('Breed', ''),
|
1105 |
-
user_prefs
|
1106 |
-
),
|
1107 |
-
'noise': calculate_noise_score(
|
1108 |
-
breed_info.get('Breed', ''),
|
1109 |
-
user_prefs
|
1110 |
-
)
|
1111 |
-
}
|
1112 |
-
|
1113 |
-
# 檢查關鍵不適配情況
|
1114 |
-
critical_issues = check_critical_matches(scores, user_prefs)
|
1115 |
-
if critical_issues['has_critical']:
|
1116 |
-
return apply_critical_penalty(scores, critical_issues)
|
1117 |
-
|
1118 |
-
# 計算環境適應性加成
|
1119 |
-
adaptability_bonus = calculate_environmental_fit(breed_info, user_prefs)
|
1120 |
-
|
1121 |
-
# 計算最終加權分數
|
1122 |
-
final_score = calculate_final_weighted_score(
|
1123 |
-
scores=scores,
|
1124 |
-
user_prefs=user_prefs,
|
1125 |
-
breed_info=breed_info,
|
1126 |
-
adaptability_bonus=adaptability_bonus
|
1127 |
)
|
1128 |
-
|
1129 |
-
|
1130 |
-
|
1131 |
-
|
1132 |
-
|
1133 |
-
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1144 |
|
1145 |
def check_critical_matches(scores: dict, user_prefs: UserPreferences) -> dict:
|
1146 |
"""評估是否存在極端不適配的情況"""
|
|
|
1066 |
final_score = base_score + barking_penalty + special_adjustments + trainability_bonus
|
1067 |
return max(0.1, min(1.0, final_score))
|
1068 |
|
1069 |
+
|
1070 |
+
# 1. 計算基礎分數
|
1071 |
print("\n=== 開始計算品種相容性分數 ===")
|
1072 |
print(f"處理品種: {breed_info.get('Breed', 'Unknown')}")
|
1073 |
print(f"品種信息: {breed_info}")
|
1074 |
print(f"使用者偏好: {vars(user_prefs)}")
|
1075 |
|
1076 |
+
# 計算所有基礎分數並整合到字典中
|
1077 |
+
scores = {
|
1078 |
+
'space': calculate_space_score(
|
1079 |
+
breed_info['Size'],
|
1080 |
+
user_prefs.living_space,
|
1081 |
+
user_prefs.yard_access != 'no_yard',
|
1082 |
+
breed_info.get('Exercise Needs', 'Moderate')
|
1083 |
+
),
|
1084 |
+
'exercise': calculate_exercise_score(
|
1085 |
+
breed_info.get('Exercise Needs', 'Moderate'),
|
1086 |
+
user_prefs.exercise_time
|
1087 |
+
),
|
1088 |
+
'grooming': calculate_grooming_score(
|
1089 |
+
breed_info.get('Grooming Needs', 'Moderate'),
|
1090 |
+
user_prefs.grooming_commitment.lower(),
|
1091 |
+
breed_info['Size']
|
1092 |
+
),
|
1093 |
+
'experience': calculate_experience_score(
|
1094 |
+
breed_info.get('Care Level', 'Moderate'),
|
1095 |
+
user_prefs.experience_level,
|
1096 |
+
breed_info.get('Temperament', '')
|
1097 |
+
),
|
1098 |
+
'health': calculate_health_score(
|
1099 |
+
breed_info.get('Breed', ''),
|
1100 |
+
user_prefs
|
1101 |
+
),
|
1102 |
+
'noise': calculate_noise_score(
|
1103 |
+
breed_info.get('Breed', ''),
|
1104 |
+
user_prefs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1105 |
)
|
1106 |
+
}
|
1107 |
+
|
1108 |
+
# 檢查關鍵不適配情況
|
1109 |
+
critical_issues = check_critical_matches(scores, user_prefs)
|
1110 |
+
if critical_issues['has_critical']:
|
1111 |
+
return apply_critical_penalty(scores, critical_issues)
|
1112 |
+
|
1113 |
+
# 計算環境適應性加成
|
1114 |
+
adaptability_bonus = calculate_environmental_fit(breed_info, user_prefs)
|
1115 |
+
|
1116 |
+
# 計算最終加權分數
|
1117 |
+
final_score = calculate_final_weighted_score(
|
1118 |
+
scores=scores,
|
1119 |
+
user_prefs=user_prefs,
|
1120 |
+
breed_info=breed_info,
|
1121 |
+
adaptability_bonus=adaptability_bonus
|
1122 |
+
)
|
1123 |
+
|
1124 |
+
# 更新最終結果
|
1125 |
+
scores.update({
|
1126 |
+
'overall': final_score,
|
1127 |
+
'adaptability_bonus': adaptability_bonus
|
1128 |
+
})
|
1129 |
+
|
1130 |
+
return scores
|
1131 |
+
|
1132 |
+
except Exception as e:
|
1133 |
+
print(f"\n!!!!! 發生嚴重錯誤 !!!!!")
|
1134 |
+
print(f"錯誤類型: {type(e).__name__}")
|
1135 |
+
print(f"錯誤訊息: {str(e)}")
|
1136 |
+
print(f"完整錯誤追蹤:")
|
1137 |
+
print(traceback.format_exc())
|
1138 |
+
return {k: 0.6 for k in ['space', 'exercise', 'grooming', 'experience', 'health', 'noise', 'overall']}
|
1139 |
|
1140 |
def check_critical_matches(scores: dict, user_prefs: UserPreferences) -> dict:
|
1141 |
"""評估是否存在極端不適配的情況"""
|