Spaces:
Running
Running
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +74 -47
scoring_calculation_system.py
CHANGED
@@ -1646,69 +1646,96 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
1646 |
exercise_time = user_prefs.exercise_time
|
1647 |
exercise_type = user_prefs.exercise_type
|
1648 |
temperament = breed_info.get('Temperament', '').lower()
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
'
|
1655 |
-
'
|
1656 |
-
|
1657 |
-
'
|
1658 |
-
'
|
|
|
|
|
|
|
|
|
1659 |
}
|
1660 |
},
|
1661 |
-
'endurance_type': { #
|
1662 |
-
'
|
1663 |
-
'
|
1664 |
-
|
1665 |
-
|
1666 |
-
'
|
1667 |
-
|
|
|
|
|
|
|
1668 |
}
|
1669 |
},
|
1670 |
-
'moderate_type': { #
|
1671 |
-
'
|
1672 |
-
'
|
1673 |
-
|
1674 |
-
|
1675 |
-
'
|
1676 |
-
|
|
|
|
|
|
|
1677 |
}
|
1678 |
}
|
1679 |
}
|
1680 |
|
1681 |
# 判斷品種的運動類型
|
1682 |
-
|
1683 |
-
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
|
|
1687 |
|
1688 |
-
|
1689 |
-
|
1690 |
|
1691 |
# 計算時間匹配度
|
1692 |
-
|
1693 |
-
|
1694 |
-
|
1695 |
-
|
1696 |
-
|
1697 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1698 |
|
1699 |
-
#
|
1700 |
-
|
1701 |
-
'light_walks': 0.7,
|
1702 |
-
'moderate_activity': 0.9,
|
1703 |
-
'active_training': 1.0
|
1704 |
-
}
|
1705 |
-
type_score = type_scores.get(exercise_type, 0.7)
|
1706 |
|
1707 |
# 特殊情況處理
|
1708 |
-
|
1709 |
-
if
|
1710 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1711 |
|
|
|
1712 |
return (time_score * 0.6) + (type_score * 0.4)
|
1713 |
|
1714 |
# 第二部分:專業技能需求評估
|
|
|
1646 |
exercise_time = user_prefs.exercise_time
|
1647 |
exercise_type = user_prefs.exercise_type
|
1648 |
temperament = breed_info.get('Temperament', '').lower()
|
1649 |
+
description = breed_info.get('Description', '').lower()
|
1650 |
+
|
1651 |
+
# 定義更細緻的品種運動特性
|
1652 |
+
breed_exercise_patterns = {
|
1653 |
+
'sprint_type': { # 如 Whippet, Saluki
|
1654 |
+
'identifiers': ['fast', 'speed', 'sprint', 'racing', 'coursing'],
|
1655 |
+
'ideal_exercise': {
|
1656 |
+
'active_training': 1.0, # 適合高強度訓練
|
1657 |
+
'moderate_activity': 0.6, # 不太適合持續運動
|
1658 |
+
'light_walks': 0.4 # 不適合純散步
|
1659 |
+
},
|
1660 |
+
'time_ranges': {
|
1661 |
+
'ideal': (30, 90), # 理想運動時間
|
1662 |
+
'acceptable': (20, 120) # 可接受範圍
|
1663 |
}
|
1664 |
},
|
1665 |
+
'endurance_type': { # 如 Border Collie, German Shepherd
|
1666 |
+
'identifiers': ['herding', 'working', 'tireless', 'energetic', 'stamina'],
|
1667 |
+
'ideal_exercise': {
|
1668 |
+
'active_training': 0.9, # 適合高強度訓練
|
1669 |
+
'moderate_activity': 1.0, # 最適合持續運動
|
1670 |
+
'light_walks': 0.5 # 不適合純散步
|
1671 |
+
},
|
1672 |
+
'time_ranges': {
|
1673 |
+
'ideal': (90, 180), # 理想運動時間
|
1674 |
+
'acceptable': (60, 240) # 可接受範圍
|
1675 |
}
|
1676 |
},
|
1677 |
+
'moderate_type': { # 如 Labrador, Golden Retriever
|
1678 |
+
'identifiers': ['friendly', 'playful', 'adaptable', 'versatile'],
|
1679 |
+
'ideal_exercise': {
|
1680 |
+
'active_training': 0.8,
|
1681 |
+
'moderate_activity': 1.0,
|
1682 |
+
'light_walks': 0.7
|
1683 |
+
},
|
1684 |
+
'time_ranges': {
|
1685 |
+
'ideal': (60, 120),
|
1686 |
+
'acceptable': (45, 180)
|
1687 |
}
|
1688 |
}
|
1689 |
}
|
1690 |
|
1691 |
# 判斷品種的運動類型
|
1692 |
+
def determine_breed_type():
|
1693 |
+
for breed_type, pattern in breed_exercise_patterns.items():
|
1694 |
+
if any(identifier in temperament or identifier in description
|
1695 |
+
for identifier in pattern['identifiers']):
|
1696 |
+
return breed_type
|
1697 |
+
return 'moderate_type' # 預設類型
|
1698 |
|
1699 |
+
breed_type = determine_breed_type()
|
1700 |
+
pattern = breed_exercise_patterns[breed_type]
|
1701 |
|
1702 |
# 計算時間匹配度
|
1703 |
+
def calculate_time_match():
|
1704 |
+
ideal_min, ideal_max = pattern['time_ranges']['ideal']
|
1705 |
+
accept_min, accept_max = pattern['time_ranges']['acceptable']
|
1706 |
+
|
1707 |
+
if ideal_min <= exercise_time <= ideal_max:
|
1708 |
+
return 1.0
|
1709 |
+
elif exercise_time < accept_min:
|
1710 |
+
return max(0.3, 1 - ((accept_min - exercise_time) / accept_min))
|
1711 |
+
elif exercise_time > accept_max:
|
1712 |
+
return max(0.3, 1 - ((exercise_time - accept_max) / accept_max))
|
1713 |
+
else:
|
1714 |
+
# 在可接受範圍內,但不在理想範圍
|
1715 |
+
if exercise_time < ideal_min:
|
1716 |
+
return 0.7 + (0.3 * (exercise_time - accept_min) / (ideal_min - accept_min))
|
1717 |
+
else:
|
1718 |
+
return 0.7 + (0.3 * (accept_max - exercise_time) / (accept_max - ideal_max))
|
1719 |
|
1720 |
+
# 計算運動類型匹配度
|
1721 |
+
type_score = pattern['ideal_exercise'].get(exercise_type, 0.5)
|
|
|
|
|
|
|
|
|
|
|
1722 |
|
1723 |
# 特殊情況處理
|
1724 |
+
def apply_special_adjustments(time_score, type_score):
|
1725 |
+
if breed_type == 'sprint_type':
|
1726 |
+
if exercise_time > pattern['time_ranges']['acceptable'][1]:
|
1727 |
+
return (time_score * 0.5, type_score * 0.6)
|
1728 |
+
|
1729 |
+
if breed_type == 'endurance_type':
|
1730 |
+
if exercise_time < pattern['time_ranges']['ideal'][0]:
|
1731 |
+
return (time_score * 0.6, type_score * 0.7)
|
1732 |
+
|
1733 |
+
return (time_score, type_score)
|
1734 |
+
|
1735 |
+
time_score = calculate_time_match()
|
1736 |
+
time_score, type_score = apply_special_adjustments(time_score, type_score)
|
1737 |
|
1738 |
+
# 最終運動匹配度計算
|
1739 |
return (time_score * 0.6) + (type_score * 0.4)
|
1740 |
|
1741 |
# 第二部分:專業技能需求評估
|