Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +62 -47
scoring_calculation_system.py
CHANGED
|
@@ -1460,65 +1460,80 @@ def calculate_environmental_fit(breed_info: dict, user_prefs: UserPreferences) -
|
|
| 1460 |
|
| 1461 |
return min(0.2, adaptability_score)
|
| 1462 |
|
| 1463 |
-
def calculate_final_weighted_score(
|
| 1464 |
-
|
| 1465 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1466 |
base_weights = {
|
| 1467 |
-
'space': 0.30,
|
| 1468 |
-
'exercise': 0.25,
|
| 1469 |
'grooming': 0.15,
|
| 1470 |
-
'experience': 0.15,
|
| 1471 |
'health': 0.10,
|
| 1472 |
-
'noise': 0.05
|
| 1473 |
}
|
| 1474 |
|
| 1475 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1476 |
if user_prefs.living_space == 'apartment':
|
| 1477 |
-
|
| 1478 |
-
|
| 1479 |
-
|
| 1480 |
-
|
| 1481 |
-
|
| 1482 |
-
|
| 1483 |
-
|
| 1484 |
-
|
| 1485 |
-
|
| 1486 |
-
if user_prefs.
|
| 1487 |
-
|
| 1488 |
-
|
| 1489 |
-
elif user_prefs.
|
| 1490 |
-
|
| 1491 |
-
|
| 1492 |
-
|
| 1493 |
-
|
| 1494 |
-
|
| 1495 |
-
base_weights['space'] *= 1.3
|
| 1496 |
-
elif user_prefs.exercise_time < 45: # 低運動時間
|
| 1497 |
-
base_weights['exercise'] *= 0.7
|
| 1498 |
-
base_weights['health'] *= 1.2
|
| 1499 |
-
|
| 1500 |
-
# 有孩童時的特殊調整
|
| 1501 |
-
if user_prefs.has_children:
|
| 1502 |
-
base_weights['noise'] *= 1.3
|
| 1503 |
-
base_weights['health'] *= 1.2
|
| 1504 |
-
|
| 1505 |
-
# 重新正規化權重
|
| 1506 |
-
total_weight = sum(base_weights.values())
|
| 1507 |
-
weights = {k: v/total_weight for k, v in base_weights.items()}
|
| 1508 |
-
|
| 1509 |
-
# 計算基礎加權分數
|
| 1510 |
-
weighted_base = sum(score * weights[category] for category, score in scores.items())
|
| 1511 |
|
| 1512 |
# 品種特性加成
|
| 1513 |
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
| 1514 |
|
| 1515 |
-
#
|
| 1516 |
-
final_score = (weighted_base * 0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1517 |
|
| 1518 |
-
|
| 1519 |
-
amplified_score = amplify_score_range(final_score)
|
| 1520 |
|
| 1521 |
-
return round(amplified_score, 4)
|
| 1522 |
|
| 1523 |
def amplify_score_range(score: float) -> float:
|
| 1524 |
"""擴大分數範圍,使差異更明顯"""
|
|
|
|
| 1460 |
|
| 1461 |
return min(0.2, adaptability_score)
|
| 1462 |
|
| 1463 |
+
def calculate_final_weighted_score(
|
| 1464 |
+
scores: dict,
|
| 1465 |
+
user_prefs: UserPreferences,
|
| 1466 |
+
breed_info: dict,
|
| 1467 |
+
adaptability_bonus: float
|
| 1468 |
+
) -> float:
|
| 1469 |
+
"""
|
| 1470 |
+
計算最終加權分數,強化條件變化的影響力
|
| 1471 |
+
"""
|
| 1472 |
+
# 基礎權重設定 - 更極端化
|
| 1473 |
base_weights = {
|
| 1474 |
+
'space': 0.30, # 提高空間權重
|
| 1475 |
+
'exercise': 0.25, # 提高運動權重
|
| 1476 |
'grooming': 0.15,
|
| 1477 |
+
'experience': 0.15,
|
| 1478 |
'health': 0.10,
|
| 1479 |
+
'noise': 0.05
|
| 1480 |
}
|
| 1481 |
|
| 1482 |
+
# 條件特殊化加權
|
| 1483 |
+
special_conditions = 0.0
|
| 1484 |
+
|
| 1485 |
+
# 1. 極端條件加權
|
| 1486 |
+
if user_prefs.noise_tolerance == 'low':
|
| 1487 |
+
if scores['noise'] < 0.7: # 對低噪音容忍度更嚴格
|
| 1488 |
+
special_conditions -= 0.15
|
| 1489 |
+
|
| 1490 |
+
if user_prefs.grooming_commitment == 'high':
|
| 1491 |
+
if breed_info.get('Grooming Needs', '').upper() == 'HIGH':
|
| 1492 |
+
special_conditions += 0.12 # 獎勵高美容需求品種
|
| 1493 |
+
|
| 1494 |
+
# 2. 專業度差異化
|
| 1495 |
+
if user_prefs.experience_level == 'advanced':
|
| 1496 |
+
if breed_info.get('Care Level', '').upper() == 'HIGH':
|
| 1497 |
+
special_conditions += 0.15 # 資深者配高難度品種加分
|
| 1498 |
+
elif breed_info.get('Care Level', '').upper() == 'LOW':
|
| 1499 |
+
special_conditions -= 0.10 # 資深者配低難度品種扣分
|
| 1500 |
+
|
| 1501 |
+
# 3. 居住環境極端匹配
|
| 1502 |
if user_prefs.living_space == 'apartment':
|
| 1503 |
+
if breed_info.get('Size', '') == 'Large':
|
| 1504 |
+
special_conditions -= 0.20 # 大型犬在公寓嚴重扣分
|
| 1505 |
+
elif breed_info.get('Size', '') == 'Small':
|
| 1506 |
+
special_conditions += 0.10 # 小型犬在公寓額外加分
|
| 1507 |
+
|
| 1508 |
+
# 4. 品種特色加權
|
| 1509 |
+
breed_traits = breed_info.get('Temperament', '').lower()
|
| 1510 |
+
description = breed_info.get('Description', '').lower()
|
| 1511 |
+
|
| 1512 |
+
if user_prefs.exercise_time > 120: # 高運動量使用者
|
| 1513 |
+
if 'athletic' in breed_traits or 'energetic' in breed_traits:
|
| 1514 |
+
special_conditions += 0.15
|
| 1515 |
+
elif user_prefs.exercise_time < 45: # 低運動量使用者
|
| 1516 |
+
if 'calm' in breed_traits or 'lazy' in breed_traits:
|
| 1517 |
+
special_conditions += 0.12
|
| 1518 |
+
|
| 1519 |
+
# 重新計算加權總分
|
| 1520 |
+
weighted_base = sum(score * base_weights[category] for category, score in scores.items())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1521 |
|
| 1522 |
# 品種特性加成
|
| 1523 |
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
| 1524 |
|
| 1525 |
+
# 最終分數計算 - 加大特殊條件的影響
|
| 1526 |
+
final_score = (weighted_base * 0.65) + (breed_bonus * 0.15) +
|
| 1527 |
+
(adaptability_bonus * 0.10) + (special_conditions * 0.10)
|
| 1528 |
+
|
| 1529 |
+
# 分數放大,使差異更明顯
|
| 1530 |
+
if final_score > 0.8:
|
| 1531 |
+
final_score = 0.8 + (final_score - 0.8) * 1.5
|
| 1532 |
+
elif final_score < 0.6:
|
| 1533 |
+
final_score = 0.6 - (0.6 - final_score) * 1.5
|
| 1534 |
|
| 1535 |
+
return round(min(0.95, max(0.45, final_score)), 4)
|
|
|
|
| 1536 |
|
|
|
|
| 1537 |
|
| 1538 |
def amplify_score_range(score: float) -> float:
|
| 1539 |
"""擴大分數範圍,使差異更明顯"""
|