Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +46 -45
scoring_calculation_system.py
CHANGED
@@ -1316,56 +1316,57 @@ def calculate_compatibility_score(breed_info: dict, user_prefs: UserPreferences)
|
|
1316 |
'noise': calculate_noise_score(breed_info.get('Breed', ''), user_prefs.noise_tolerance)
|
1317 |
}
|
1318 |
|
1319 |
-
# 2.
|
1320 |
-
|
1321 |
-
|
1322 |
-
|
1323 |
-
|
1324 |
-
'
|
1325 |
-
|
1326 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1327 |
}
|
1328 |
|
1329 |
-
#
|
1330 |
-
|
1331 |
-
|
|
|
|
|
1332 |
|
1333 |
-
|
1334 |
-
|
1335 |
-
|
1336 |
-
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
adjusted = score # 中間分數保持不變
|
1341 |
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
# 計算基礎加權分數
|
1346 |
-
base_score = sum(weighted_components)
|
1347 |
-
|
1348 |
-
# 關鍵條件檢查和調整
|
1349 |
-
size = breed_info['Size']
|
1350 |
-
temperament = breed_info.get('Temperament', '').lower()
|
1351 |
-
|
1352 |
-
# 應用條件調整
|
1353 |
-
if user_prefs.living_space == 'apartment':
|
1354 |
-
if size in ['Large', 'Giant']:
|
1355 |
-
base_score *= 0.8
|
1356 |
-
elif 'high energy' in temperament:
|
1357 |
-
base_score *= 0.85
|
1358 |
-
|
1359 |
-
if user_prefs.experience_level == 'beginner':
|
1360 |
-
if any(trait in temperament for trait in ['stubborn', 'dominant']):
|
1361 |
-
base_score *= 0.85
|
1362 |
-
|
1363 |
-
# 最終分數映射到合理範圍
|
1364 |
-
final_score = 0.6 + (base_score - 0.5) * 1.5
|
1365 |
-
return max(0.55, min(0.95, final_score))
|
1366 |
-
|
1367 |
# 4. 計算最終分數
|
1368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1369 |
|
1370 |
# 5. 準備返回結果
|
1371 |
scores['overall'] = round(final_score, 4)
|
|
|
1316 |
'noise': calculate_noise_score(breed_info.get('Breed', ''), user_prefs.noise_tolerance)
|
1317 |
}
|
1318 |
|
1319 |
+
# 2. 直接識別關鍵問題
|
1320 |
+
penalties = []
|
1321 |
+
|
1322 |
+
# 檢查重要的不適配情況
|
1323 |
+
if user_prefs.living_space == 'apartment':
|
1324 |
+
if breed_info['Size'] == 'Large':
|
1325 |
+
penalties.append(0.75) # 大型犬在公寓
|
1326 |
+
elif breed_info['Size'] == 'Giant':
|
1327 |
+
penalties.append(0.65) # 超大型犬在公寓
|
1328 |
+
|
1329 |
+
if user_prefs.experience_level == 'beginner':
|
1330 |
+
temperament = breed_info.get('Temperament', '').lower()
|
1331 |
+
if 'stubborn' in temperament or 'dominant' in temperament:
|
1332 |
+
penalties.append(0.80) # 新手配到難訓練的犬種
|
1333 |
+
|
1334 |
+
# 3. 計算基礎分數
|
1335 |
+
importance_factors = {
|
1336 |
+
'space': 3.0, # 空間評分的重要性提高
|
1337 |
+
'exercise': 2.0, # 運動需求次之
|
1338 |
+
'experience': 2.5, # 經驗要求很重要
|
1339 |
+
'health': 1.5, # 健康因素適中
|
1340 |
+
'grooming': 1.2, # 美容需求較次要
|
1341 |
+
'noise': 1.8 # 噪音也要考慮
|
1342 |
}
|
1343 |
|
1344 |
+
# 調整後的分數計算
|
1345 |
+
adjusted_scores = []
|
1346 |
+
for category, score in scores.items():
|
1347 |
+
# 根據重要性調整分數
|
1348 |
+
factor = importance_factors[category]
|
1349 |
|
1350 |
+
# 分數調整:保持差異性
|
1351 |
+
if score < 0.4:
|
1352 |
+
adjusted = score * 0.7 # 低分更低
|
1353 |
+
elif score > 0.8:
|
1354 |
+
adjusted = score * 1.1 # 高分更高
|
1355 |
+
else:
|
1356 |
+
adjusted = score
|
|
|
1357 |
|
1358 |
+
adjusted_scores.append(adjusted * factor)
|
1359 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1360 |
# 4. 計算最終分數
|
1361 |
+
base_score = sum(adjusted_scores) / sum(importance_factors.values())
|
1362 |
+
|
1363 |
+
# 應用懲罰(如果有)
|
1364 |
+
final_score = base_score
|
1365 |
+
if penalties:
|
1366 |
+
final_score *= min(penalties) # 使用最嚴重的懲罰
|
1367 |
+
|
1368 |
+
# 確保分數在合理範圍內
|
1369 |
+
final_score = max(0.55, min(0.95, final_score))
|
1370 |
|
1371 |
# 5. 準備返回結果
|
1372 |
scores['overall'] = round(final_score, 4)
|