Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +53 -40
scoring_calculation_system.py
CHANGED
|
@@ -1704,19 +1704,19 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
| 1704 |
}
|
| 1705 |
|
| 1706 |
def determine_breed_type():
|
| 1707 |
-
"""
|
| 1708 |
-
根據品種的描述和性格特徵判斷其運動類型。
|
| 1709 |
-
就像體育教練要先了解運動員的特點才能制定訓練計劃。
|
| 1710 |
-
"""
|
| 1711 |
# 優先檢查特殊運動類型的標識符
|
| 1712 |
for breed_type, pattern in breed_exercise_patterns.items():
|
| 1713 |
if any(identifier in temperament or identifier in description
|
| 1714 |
for identifier in pattern['identifiers']):
|
| 1715 |
return breed_type
|
| 1716 |
|
| 1717 |
-
#
|
| 1718 |
-
if exercise_needs in ['VERY HIGH', 'HIGH']
|
| 1719 |
-
|
|
|
|
|
|
|
|
|
|
| 1720 |
elif exercise_needs == 'LOW':
|
| 1721 |
return 'moderate_type'
|
| 1722 |
|
|
@@ -1754,27 +1754,28 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
| 1754 |
return 0.6 + (0.4 * remaining)
|
| 1755 |
|
| 1756 |
def apply_special_adjustments(time_score, type_score, breed_type, pattern):
|
| 1757 |
-
"""
|
| 1758 |
-
|
| 1759 |
-
就像確保訓練計劃不會違背運動員的特點。
|
| 1760 |
-
"""
|
| 1761 |
-
# 短跑型品種的特殊處理
|
| 1762 |
if breed_type == 'sprint_type':
|
| 1763 |
if exercise_time > pattern['time_ranges']['penalty_start']:
|
| 1764 |
-
# 時間過長的嚴重懲罰
|
| 1765 |
time_score *= 0.5
|
| 1766 |
-
# 如果同時運動類型不適合,更嚴重的懲罰
|
| 1767 |
if exercise_type != 'active_training':
|
| 1768 |
type_score *= 0.4
|
| 1769 |
-
|
| 1770 |
-
#
|
| 1771 |
elif breed_type == 'endurance_type':
|
| 1772 |
if exercise_time < pattern['time_ranges']['penalty_start']:
|
| 1773 |
-
time_score *= 0.
|
| 1774 |
-
|
| 1775 |
-
|
| 1776 |
-
|
| 1777 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1778 |
return time_score, type_score
|
| 1779 |
|
| 1780 |
# 執行評估流程
|
|
@@ -1969,10 +1970,10 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
| 1969 |
return extremities
|
| 1970 |
|
| 1971 |
def calculate_weight_adjustments(extremities):
|
| 1972 |
-
"""
|
| 1973 |
adjustments = {}
|
| 1974 |
|
| 1975 |
-
#
|
| 1976 |
if extremities['space'][0] == 'highly_restricted':
|
| 1977 |
adjustments['space'] = 2.5
|
| 1978 |
adjustments['noise'] = 2.0
|
|
@@ -1980,43 +1981,55 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
| 1980 |
adjustments['space'] = 1.8
|
| 1981 |
adjustments['noise'] = 1.5
|
| 1982 |
elif extremities['space'][0] == 'spacious':
|
| 1983 |
-
adjustments['space'] = 0.8
|
| 1984 |
-
adjustments['exercise'] = 1.4
|
| 1985 |
-
|
| 1986 |
-
#
|
| 1987 |
if extremities['exercise'][0] in ['extremely_low', 'extremely_high']:
|
| 1988 |
adjustments['exercise'] = 2.5
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1989 |
elif extremities['exercise'][0] in ['low', 'high']:
|
| 1990 |
adjustments['exercise'] = 1.8
|
| 1991 |
-
|
| 1992 |
-
#
|
| 1993 |
if extremities['experience'][0] == 'low':
|
| 1994 |
adjustments['experience'] = 2.2
|
| 1995 |
if breed_info.get('Care Level') == 'HIGH':
|
| 1996 |
adjustments['experience'] = 2.5
|
| 1997 |
elif extremities['experience'][0] == 'high':
|
| 1998 |
-
|
| 1999 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2000 |
# 綜合條件影響
|
| 2001 |
def adjust_for_combinations():
|
| 2002 |
-
#
|
| 2003 |
if (extremities['space'][0] == 'highly_restricted' and
|
| 2004 |
extremities['exercise'][0] in ['high', 'extremely_high']):
|
| 2005 |
adjustments['space'] = adjustments.get('space', 1.0) * 1.3
|
| 2006 |
adjustments['exercise'] = adjustments.get('exercise', 1.0) * 1.3
|
| 2007 |
-
|
| 2008 |
-
#
|
| 2009 |
-
if (extremities['experience'][0] == '
|
| 2010 |
extremities['space'][0] == 'spacious' and
|
| 2011 |
-
extremities['exercise'][0] in ['high', 'extremely_high']
|
| 2012 |
-
|
| 2013 |
-
|
| 2014 |
-
|
|
|
|
|
|
|
| 2015 |
if extremities['space'][0] == 'spacious':
|
| 2016 |
for key in ['grooming', 'health', 'noise']:
|
| 2017 |
if key not in adjustments:
|
| 2018 |
adjustments[key] = 1.2
|
| 2019 |
-
|
| 2020 |
adjust_for_combinations()
|
| 2021 |
return adjustments
|
| 2022 |
|
|
|
|
| 1704 |
}
|
| 1705 |
|
| 1706 |
def determine_breed_type():
|
| 1707 |
+
"""改進品種運動類型的判斷,更精確識別工作犬"""
|
|
|
|
|
|
|
|
|
|
| 1708 |
# 優先檢查特殊運動類型的標識符
|
| 1709 |
for breed_type, pattern in breed_exercise_patterns.items():
|
| 1710 |
if any(identifier in temperament or identifier in description
|
| 1711 |
for identifier in pattern['identifiers']):
|
| 1712 |
return breed_type
|
| 1713 |
|
| 1714 |
+
# 改進:根據運動需求和工作犬特徵進行更細緻的判斷
|
| 1715 |
+
if (exercise_needs in ['VERY HIGH', 'HIGH'] or
|
| 1716 |
+
any(trait in temperament.lower() for trait in
|
| 1717 |
+
['herding', 'working', 'intelligent', 'athletic', 'tireless'])):
|
| 1718 |
+
if user_prefs.experience_level == 'advanced':
|
| 1719 |
+
return 'endurance_type' # 優先判定為耐力型
|
| 1720 |
elif exercise_needs == 'LOW':
|
| 1721 |
return 'moderate_type'
|
| 1722 |
|
|
|
|
| 1754 |
return 0.6 + (0.4 * remaining)
|
| 1755 |
|
| 1756 |
def apply_special_adjustments(time_score, type_score, breed_type, pattern):
|
| 1757 |
+
"""處理特殊情況,加強工作犬的評估"""
|
| 1758 |
+
# 短跑型品種邏輯保持不變
|
|
|
|
|
|
|
|
|
|
| 1759 |
if breed_type == 'sprint_type':
|
| 1760 |
if exercise_time > pattern['time_ranges']['penalty_start']:
|
|
|
|
| 1761 |
time_score *= 0.5
|
|
|
|
| 1762 |
if exercise_type != 'active_training':
|
| 1763 |
type_score *= 0.4
|
| 1764 |
+
|
| 1765 |
+
# 改進耐力型品種的評估
|
| 1766 |
elif breed_type == 'endurance_type':
|
| 1767 |
if exercise_time < pattern['time_ranges']['penalty_start']:
|
| 1768 |
+
time_score *= 0.5 # 加重時間不足的懲罰
|
| 1769 |
+
if exercise_type == 'light_walks':
|
| 1770 |
+
if exercise_time > 90:
|
| 1771 |
+
type_score *= 0.4 # 加重強度不足的懲罰
|
| 1772 |
+
# 新增:進階飼主對工作犬的獎勵
|
| 1773 |
+
if (user_prefs.experience_level == 'advanced' and
|
| 1774 |
+
exercise_time >= 150 and
|
| 1775 |
+
exercise_type in ['active_training', 'moderate_activity']):
|
| 1776 |
+
time_score = min(1.0, time_score * 1.2)
|
| 1777 |
+
type_score = min(1.0, type_score * 1.2)
|
| 1778 |
+
|
| 1779 |
return time_score, type_score
|
| 1780 |
|
| 1781 |
# 執行評估流程
|
|
|
|
| 1970 |
return extremities
|
| 1971 |
|
| 1972 |
def calculate_weight_adjustments(extremities):
|
| 1973 |
+
"""根據條件極端度計算權重調整,特別加強對工作犬的評估"""
|
| 1974 |
adjustments = {}
|
| 1975 |
|
| 1976 |
+
# 空間權重調整邏輯保持原樣,因為邏輯合理
|
| 1977 |
if extremities['space'][0] == 'highly_restricted':
|
| 1978 |
adjustments['space'] = 2.5
|
| 1979 |
adjustments['noise'] = 2.0
|
|
|
|
| 1981 |
adjustments['space'] = 1.8
|
| 1982 |
adjustments['noise'] = 1.5
|
| 1983 |
elif extremities['space'][0] == 'spacious':
|
| 1984 |
+
adjustments['space'] = 0.8
|
| 1985 |
+
adjustments['exercise'] = 1.4
|
| 1986 |
+
|
| 1987 |
+
# 改進運動需求權重調整,考慮工作犬特性
|
| 1988 |
if extremities['exercise'][0] in ['extremely_low', 'extremely_high']:
|
| 1989 |
adjustments['exercise'] = 2.5
|
| 1990 |
+
# 檢查是否為工作犬且運動量高
|
| 1991 |
+
if (extremities['exercise'][0] == 'extremely_high' and
|
| 1992 |
+
any(trait in breed_info.get('Temperament', '').lower()
|
| 1993 |
+
for trait in ['herding', 'working', 'intelligent'])):
|
| 1994 |
+
adjustments['exercise'] = 3.0 # 提高工作犬的運動權重
|
| 1995 |
elif extremities['exercise'][0] in ['low', 'high']:
|
| 1996 |
adjustments['exercise'] = 1.8
|
| 1997 |
+
|
| 1998 |
+
# 改進經驗需求權重調整,強化專家對工作犬的評估
|
| 1999 |
if extremities['experience'][0] == 'low':
|
| 2000 |
adjustments['experience'] = 2.2
|
| 2001 |
if breed_info.get('Care Level') == 'HIGH':
|
| 2002 |
adjustments['experience'] = 2.5
|
| 2003 |
elif extremities['experience'][0] == 'high':
|
| 2004 |
+
# 提高進階飼主對工作犬的權重
|
| 2005 |
+
if any(trait in breed_info.get('Temperament', '').lower()
|
| 2006 |
+
for trait in ['herding', 'working', 'intelligent']):
|
| 2007 |
+
adjustments['experience'] = 2.2
|
| 2008 |
+
else:
|
| 2009 |
+
adjustments['experience'] = 1.8
|
| 2010 |
+
|
| 2011 |
# 綜合條件影響
|
| 2012 |
def adjust_for_combinations():
|
| 2013 |
+
# 保持原有邏輯
|
| 2014 |
if (extremities['space'][0] == 'highly_restricted' and
|
| 2015 |
extremities['exercise'][0] in ['high', 'extremely_high']):
|
| 2016 |
adjustments['space'] = adjustments.get('space', 1.0) * 1.3
|
| 2017 |
adjustments['exercise'] = adjustments.get('exercise', 1.0) * 1.3
|
| 2018 |
+
|
| 2019 |
+
# 新增:進階飼主 + 大空間 + 高運動量 + 工作犬
|
| 2020 |
+
if (extremities['experience'][0] == 'high' and
|
| 2021 |
extremities['space'][0] == 'spacious' and
|
| 2022 |
+
extremities['exercise'][0] in ['high', 'extremely_high'] and
|
| 2023 |
+
any(trait in breed_info.get('Temperament', '').lower()
|
| 2024 |
+
for trait in ['herding', 'working', 'intelligent'])):
|
| 2025 |
+
adjustments['exercise'] = adjustments.get('exercise', 1.0) * 1.5
|
| 2026 |
+
adjustments['experience'] = adjustments.get('experience', 1.0) * 1.5
|
| 2027 |
+
|
| 2028 |
if extremities['space'][0] == 'spacious':
|
| 2029 |
for key in ['grooming', 'health', 'noise']:
|
| 2030 |
if key not in adjustments:
|
| 2031 |
adjustments[key] = 1.2
|
| 2032 |
+
|
| 2033 |
adjust_for_combinations()
|
| 2034 |
return adjustments
|
| 2035 |
|