Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +50 -32
scoring_calculation_system.py
CHANGED
|
@@ -1508,27 +1508,24 @@ def calculate_environmental_fit(breed_info: dict, user_prefs: UserPreferences) -
|
|
| 1508 |
return min(0.2, adaptability_score)
|
| 1509 |
|
| 1510 |
|
| 1511 |
-
def calculate_breed_compatibility_score(
|
| 1512 |
-
scores: dict,
|
| 1513 |
-
user_prefs: UserPreferences,
|
| 1514 |
-
breed_info: dict
|
| 1515 |
-
) -> float:
|
| 1516 |
"""
|
| 1517 |
-
|
| 1518 |
-
|
| 1519 |
-
|
| 1520 |
-
|
| 1521 |
-
|
| 1522 |
-
|
| 1523 |
-
|
| 1524 |
-
|
|
|
|
| 1525 |
"""
|
| 1526 |
-
# 1.
|
| 1527 |
critical_params = {
|
| 1528 |
'space': {
|
| 1529 |
'threshold': 0.3,
|
| 1530 |
-
'conditions': lambda: True,
|
| 1531 |
-
'penalty': 0.3
|
| 1532 |
},
|
| 1533 |
'noise': {
|
| 1534 |
'threshold': 0.3,
|
|
@@ -1542,12 +1539,12 @@ def calculate_breed_compatibility_score(
|
|
| 1542 |
}
|
| 1543 |
}
|
| 1544 |
|
| 1545 |
-
#
|
| 1546 |
for param, config in critical_params.items():
|
| 1547 |
if scores[param] < config['threshold'] and config['conditions'](user_prefs):
|
| 1548 |
return config['penalty']
|
| 1549 |
|
| 1550 |
-
# 2.
|
| 1551 |
base_weights = {
|
| 1552 |
'space': 0.35,
|
| 1553 |
'exercise': 0.30,
|
|
@@ -1562,42 +1559,63 @@ def calculate_breed_compatibility_score(
|
|
| 1562 |
for param, weight in base_weights.items():
|
| 1563 |
multiplier = 1.0
|
| 1564 |
|
| 1565 |
-
#
|
| 1566 |
-
if param == 'space'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1567 |
multiplier *= 1.2
|
| 1568 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1569 |
multiplier *= 1.4
|
| 1570 |
-
|
| 1571 |
-
|
| 1572 |
adjusted_weights[param] = weight * multiplier
|
| 1573 |
|
| 1574 |
# 重新正規化權重
|
| 1575 |
total_weight = sum(adjusted_weights.values())
|
| 1576 |
normalized_weights = {k: v/total_weight for k, v in adjusted_weights.items()}
|
| 1577 |
|
| 1578 |
-
# 4.
|
| 1579 |
base_score = 0
|
| 1580 |
for param, weight in normalized_weights.items():
|
| 1581 |
score = scores[param]
|
| 1582 |
|
| 1583 |
-
#
|
| 1584 |
if score > 0.8:
|
| 1585 |
-
score = min(1.0, score * 1.2)
|
| 1586 |
elif score < 0.6:
|
| 1587 |
-
score = score * 0.8
|
| 1588 |
|
| 1589 |
base_score += score * weight
|
| 1590 |
|
| 1591 |
-
# 5.
|
| 1592 |
adaptability_bonus = calculate_environmental_fit(breed_info, user_prefs)
|
| 1593 |
-
|
| 1594 |
-
# 6. 計算品種特性加成
|
| 1595 |
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
| 1596 |
|
| 1597 |
-
#
|
| 1598 |
final_score = (base_score * 0.70) + (breed_bonus * 0.20) + (adaptability_bonus * 0.10)
|
| 1599 |
|
| 1600 |
-
#
|
| 1601 |
return amplify_score_extreme(final_score)
|
| 1602 |
|
| 1603 |
|
|
|
|
| 1508 |
return min(0.2, adaptability_score)
|
| 1509 |
|
| 1510 |
|
| 1511 |
+
def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreferences, breed_info: dict) -> float:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1512 |
"""
|
| 1513 |
+
計算品種與使用者的整體相容性分數
|
| 1514 |
+
|
| 1515 |
+
Args:
|
| 1516 |
+
scores: 基礎分項分數字典
|
| 1517 |
+
user_prefs: 使用者偏好
|
| 1518 |
+
breed_info: 品種資訊
|
| 1519 |
+
|
| 1520 |
+
Returns:
|
| 1521 |
+
最終相容性分數 (0.3-0.95)
|
| 1522 |
"""
|
| 1523 |
+
# 1. 檢查關鍵不適配參數
|
| 1524 |
critical_params = {
|
| 1525 |
'space': {
|
| 1526 |
'threshold': 0.3,
|
| 1527 |
+
'conditions': lambda p: True,
|
| 1528 |
+
'penalty': 0.3
|
| 1529 |
},
|
| 1530 |
'noise': {
|
| 1531 |
'threshold': 0.3,
|
|
|
|
| 1539 |
}
|
| 1540 |
}
|
| 1541 |
|
| 1542 |
+
# 檢查並處理關鍵不適配情況
|
| 1543 |
for param, config in critical_params.items():
|
| 1544 |
if scores[param] < config['threshold'] and config['conditions'](user_prefs):
|
| 1545 |
return config['penalty']
|
| 1546 |
|
| 1547 |
+
# 2. 基礎權重設定
|
| 1548 |
base_weights = {
|
| 1549 |
'space': 0.35,
|
| 1550 |
'exercise': 0.30,
|
|
|
|
| 1559 |
for param, weight in base_weights.items():
|
| 1560 |
multiplier = 1.0
|
| 1561 |
|
| 1562 |
+
# 居住空間相關調整
|
| 1563 |
+
if param == 'space':
|
| 1564 |
+
if user_prefs.living_space == 'apartment':
|
| 1565 |
+
multiplier *= 1.2
|
| 1566 |
+
elif breed_info['Size'] in ['Large', 'Giant']:
|
| 1567 |
+
multiplier *= 1.3
|
| 1568 |
+
|
| 1569 |
+
# 運動需求相關調整
|
| 1570 |
+
elif param == 'exercise':
|
| 1571 |
+
if user_prefs.exercise_time > 150:
|
| 1572 |
+
multiplier *= 1.4
|
| 1573 |
+
elif user_prefs.exercise_time < 60:
|
| 1574 |
+
multiplier *= 1.2
|
| 1575 |
+
|
| 1576 |
+
# 經驗相關調整
|
| 1577 |
+
elif param == 'experience' and user_prefs.experience_level == 'beginner':
|
| 1578 |
+
multiplier *= 1.3
|
| 1579 |
+
|
| 1580 |
+
# 美容需求調整
|
| 1581 |
+
elif param == 'grooming' and breed_info.get('Grooming Needs') == 'High':
|
| 1582 |
multiplier *= 1.2
|
| 1583 |
+
|
| 1584 |
+
# 健康相關調整
|
| 1585 |
+
elif param == 'health' and user_prefs.health_sensitivity == 'high':
|
| 1586 |
+
multiplier *= 1.3
|
| 1587 |
+
|
| 1588 |
+
# 噪音相關調整
|
| 1589 |
+
elif param == 'noise' and user_prefs.living_space == 'apartment':
|
| 1590 |
multiplier *= 1.4
|
| 1591 |
+
|
|
|
|
| 1592 |
adjusted_weights[param] = weight * multiplier
|
| 1593 |
|
| 1594 |
# 重新正規化權重
|
| 1595 |
total_weight = sum(adjusted_weights.values())
|
| 1596 |
normalized_weights = {k: v/total_weight for k, v in adjusted_weights.items()}
|
| 1597 |
|
| 1598 |
+
# 4. 計算基礎加權分數
|
| 1599 |
base_score = 0
|
| 1600 |
for param, weight in normalized_weights.items():
|
| 1601 |
score = scores[param]
|
| 1602 |
|
| 1603 |
+
# 非線性分數調整
|
| 1604 |
if score > 0.8:
|
| 1605 |
+
score = min(1.0, score * 1.2) # 高分獎勵
|
| 1606 |
elif score < 0.6:
|
| 1607 |
+
score = score * 0.8 # 低分懲罰
|
| 1608 |
|
| 1609 |
base_score += score * weight
|
| 1610 |
|
| 1611 |
+
# 5. 整合特性加成
|
| 1612 |
adaptability_bonus = calculate_environmental_fit(breed_info, user_prefs)
|
|
|
|
|
|
|
| 1613 |
breed_bonus = calculate_breed_bonus(breed_info, user_prefs)
|
| 1614 |
|
| 1615 |
+
# 6. 計算最終分數
|
| 1616 |
final_score = (base_score * 0.70) + (breed_bonus * 0.20) + (adaptability_bonus * 0.10)
|
| 1617 |
|
| 1618 |
+
# 7. 轉換並限制分數範圍
|
| 1619 |
return amplify_score_extreme(final_score)
|
| 1620 |
|
| 1621 |
|