Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +18 -17
scoring_calculation_system.py
CHANGED
|
@@ -1202,31 +1202,32 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
| 1202 |
|
| 1203 |
def calculate_weighted_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
|
| 1204 |
"""
|
| 1205 |
-
|
| 1206 |
|
| 1207 |
-
|
| 1208 |
-
|
| 1209 |
-
|
| 1210 |
-
|
|
|
|
|
|
|
|
|
|
| 1211 |
"""
|
| 1212 |
# 基礎權重設定
|
| 1213 |
base_weights = {
|
| 1214 |
-
'space': 0.25,
|
| 1215 |
-
'exercise': 0.20,
|
| 1216 |
-
'grooming': 0.15,
|
| 1217 |
-
'experience': 0.18,
|
| 1218 |
'health': 0.12,
|
| 1219 |
-
'noise': 0.10
|
| 1220 |
}
|
| 1221 |
|
| 1222 |
# 根據使用者經驗調整權重
|
| 1223 |
if user_prefs.experience_level == 'beginner':
|
| 1224 |
-
# 新手更注重易照顧程度
|
| 1225 |
base_weights['experience'] *= 1.2
|
| 1226 |
base_weights['health'] *= 1.1
|
| 1227 |
base_weights['grooming'] *= 0.9
|
| 1228 |
elif user_prefs.experience_level == 'advanced':
|
| 1229 |
-
# 專家更注重運動和訓練潛力
|
| 1230 |
base_weights['exercise'] *= 1.2
|
| 1231 |
base_weights['experience'] *= 0.8
|
| 1232 |
|
|
@@ -1247,16 +1248,16 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
| 1247 |
total_weight = sum(base_weights.values())
|
| 1248 |
weights = {k: v/total_weight for k, v in base_weights.items()}
|
| 1249 |
|
| 1250 |
-
#
|
| 1251 |
-
|
| 1252 |
|
| 1253 |
# 計算品種特性加成
|
| 1254 |
breed_bonus = calculate_breed_characteristic_bonus(breed_info, user_prefs)
|
| 1255 |
|
| 1256 |
# 混合基礎分數和特性加成
|
| 1257 |
-
final_score = (
|
| 1258 |
|
| 1259 |
-
return final_score
|
| 1260 |
|
| 1261 |
def calculate_breed_characteristic_bonus(breed_info: dict, user_prefs: UserPreferences) -> float:
|
| 1262 |
"""
|
|
@@ -1311,7 +1312,7 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
| 1311 |
|
| 1312 |
# 執行計算流程
|
| 1313 |
penalty = check_critical_issues(scores, breed_info)
|
| 1314 |
-
weighted_score = calculate_weighted_score(scores)
|
| 1315 |
final_score = calculate_final_score(weighted_score, penalty)
|
| 1316 |
|
| 1317 |
# 準備返回結果
|
|
|
|
| 1202 |
|
| 1203 |
def calculate_weighted_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
|
| 1204 |
"""
|
| 1205 |
+
計算加權分數的函數
|
| 1206 |
|
| 1207 |
+
Parameters:
|
| 1208 |
+
scores: dict - 包含各項評分的字典
|
| 1209 |
+
user_prefs: UserPreferences - 使用者偏好設定
|
| 1210 |
+
breed_info: dict - 品種資訊
|
| 1211 |
+
|
| 1212 |
+
Returns:
|
| 1213 |
+
float: 加權後的最終分數
|
| 1214 |
"""
|
| 1215 |
# 基礎權重設定
|
| 1216 |
base_weights = {
|
| 1217 |
+
'space': 0.25,
|
| 1218 |
+
'exercise': 0.20,
|
| 1219 |
+
'grooming': 0.15,
|
| 1220 |
+
'experience': 0.18,
|
| 1221 |
'health': 0.12,
|
| 1222 |
+
'noise': 0.10
|
| 1223 |
}
|
| 1224 |
|
| 1225 |
# 根據使用者經驗調整權重
|
| 1226 |
if user_prefs.experience_level == 'beginner':
|
|
|
|
| 1227 |
base_weights['experience'] *= 1.2
|
| 1228 |
base_weights['health'] *= 1.1
|
| 1229 |
base_weights['grooming'] *= 0.9
|
| 1230 |
elif user_prefs.experience_level == 'advanced':
|
|
|
|
| 1231 |
base_weights['exercise'] *= 1.2
|
| 1232 |
base_weights['experience'] *= 0.8
|
| 1233 |
|
|
|
|
| 1248 |
total_weight = sum(base_weights.values())
|
| 1249 |
weights = {k: v/total_weight for k, v in base_weights.items()}
|
| 1250 |
|
| 1251 |
+
# 計算加權分數
|
| 1252 |
+
weighted_score = sum(score * weights[category] for category, score in scores.items())
|
| 1253 |
|
| 1254 |
# 計算品種特性加成
|
| 1255 |
breed_bonus = calculate_breed_characteristic_bonus(breed_info, user_prefs)
|
| 1256 |
|
| 1257 |
# 混合基礎分數和特性加成
|
| 1258 |
+
final_score = (weighted_score * 0.85) + (breed_bonus * 0.15)
|
| 1259 |
|
| 1260 |
+
return min(0.95, max(0.55, final_score))
|
| 1261 |
|
| 1262 |
def calculate_breed_characteristic_bonus(breed_info: dict, user_prefs: UserPreferences) -> float:
|
| 1263 |
"""
|
|
|
|
| 1312 |
|
| 1313 |
# 執行計算流程
|
| 1314 |
penalty = check_critical_issues(scores, breed_info)
|
| 1315 |
+
weighted_score = calculate_weighted_score(scores, user_prefs, breed_info)
|
| 1316 |
final_score = calculate_final_score(weighted_score, penalty)
|
| 1317 |
|
| 1318 |
# 準備返回結果
|