DawnC commited on
Commit
2660823
1 Parent(s): 34259a4

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +53 -35
scoring_calculation_system.py CHANGED
@@ -1754,28 +1754,40 @@ 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
  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,10 +1982,18 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
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
@@ -1984,46 +2004,44 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
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']:
 
1754
  return 0.6 + (0.4 * remaining)
1755
 
1756
  def apply_special_adjustments(time_score, type_score, breed_type, pattern):
1757
+ """
1758
+ 處理特殊情況,確保運動方式真正符合品種需求。
1759
+ 特別加強:
1760
+ 1. 短跑型犬種的長時間運動懲罰
1761
+ 2. 耐力型犬種的獎勵機制
1762
+ 3. 運動類型匹配的重要性
1763
+ """
1764
+ # 短跑型品種的特殊處理
1765
  if breed_type == 'sprint_type':
1766
  if exercise_time > pattern['time_ranges']['penalty_start']:
1767
+ # 加重長時間運動的懲罰
1768
+ penalty_factor = min(0.8, (exercise_time - pattern['time_ranges']['penalty_start']) / 60)
1769
+ time_score *= max(0.3, 1 - penalty_factor) # 最低降到0.3
1770
+ # 運動類型不適合時的額外懲罰
1771
  if exercise_type != 'active_training':
1772
+ type_score *= 0.3 # 更嚴重的懲罰
1773
+
1774
+ # 耐力型品種的特殊處理
1775
  elif breed_type == 'endurance_type':
1776
  if exercise_time < pattern['time_ranges']['penalty_start']:
1777
+ time_score *= 0.5 # 維持運動不足的懲罰
1778
+ elif exercise_time >= 150: # 新增:高運動量獎勵
1779
+ if exercise_type in ['active_training', 'moderate_activity']:
1780
+ time_bonus = min(0.3, (exercise_time - 150) / 150)
1781
+ time_score = min(1.0, time_score * (1 + time_bonus))
1782
+ type_score = min(1.0, type_score * 1.2)
1783
+
1784
+ # 運動強度不足的懲罰
1785
  if exercise_type == 'light_walks':
1786
  if exercise_time > 90:
1787
+ type_score *= 0.4 # 加重懲罰
1788
+ else:
1789
+ type_score *= 0.5
1790
+
 
 
 
 
1791
  return time_score, type_score
1792
 
1793
  # 執行評估流程
 
1982
  return extremities
1983
 
1984
  def calculate_weight_adjustments(extremities):
1985
+ """
1986
+ 根據條件極端度計算權重調整,特別強化:
1987
+ 1. 高運動量時對耐力型犬種的偏好
1988
+ 2. 專家級別對工作犬種的偏好
1989
+ 3. 條件組合的整體評估
1990
+ """
1991
  adjustments = {}
1992
+ temperament = breed_info.get('Temperament', '').lower()
1993
+ is_working_dog = any(trait in temperament
1994
+ for trait in ['herding', 'working', 'intelligent', 'tireless'])
1995
 
1996
+ # 空間權重調整邏輯保持不變
1997
  if extremities['space'][0] == 'highly_restricted':
1998
  adjustments['space'] = 2.5
1999
  adjustments['noise'] = 2.0
 
2004
  adjustments['space'] = 0.8
2005
  adjustments['exercise'] = 1.4
2006
 
2007
+ # 改進運動需求權重調整
2008
  if extremities['exercise'][0] in ['extremely_low', 'extremely_high']:
2009
+ base_adjustment = 2.5
2010
+ if extremities['exercise'][0] == 'extremely_high':
2011
+ if is_working_dog:
2012
+ base_adjustment = 3.0 # 工作犬在高運動量時獲得更高權重
2013
+ adjustments['exercise'] = base_adjustment
 
2014
  elif extremities['exercise'][0] in ['low', 'high']:
2015
  adjustments['exercise'] = 1.8
2016
 
2017
+ # 改進經驗需求權重調整
2018
  if extremities['experience'][0] == 'low':
2019
  adjustments['experience'] = 2.2
2020
  if breed_info.get('Care Level') == 'HIGH':
2021
  adjustments['experience'] = 2.5
2022
  elif extremities['experience'][0] == 'high':
2023
+ if is_working_dog:
2024
+ adjustments['experience'] = 2.5 # 提高專家對工作犬的權重
2025
+ if extremities['exercise'][0] in ['high', 'extremely_high']:
2026
+ adjustments['experience'] = 2.8 # 特別強化高運動量工作犬
2027
  else:
2028
  adjustments['experience'] = 1.8
2029
 
2030
  # 綜合條件影響
2031
  def adjust_for_combinations():
2032
+ # 保持原有的基礎邏輯
2033
  if (extremities['space'][0] == 'highly_restricted' and
2034
  extremities['exercise'][0] in ['high', 'extremely_high']):
2035
  adjustments['space'] = adjustments.get('space', 1.0) * 1.3
2036
  adjustments['exercise'] = adjustments.get('exercise', 1.0) * 1.3
2037
 
2038
+ # 新增:專家 + 大空間 + 高運動量 + 工作犬的組合
2039
  if (extremities['experience'][0] == 'high' and
2040
  extremities['space'][0] == 'spacious' and
2041
  extremities['exercise'][0] in ['high', 'extremely_high'] and
2042
+ is_working_dog):
2043
+ adjustments['exercise'] = adjustments.get('exercise', 1.0) * 1.4
2044
+ adjustments['experience'] = adjustments.get('experience', 1.0) * 1.4
 
2045
 
2046
  if extremities['space'][0] == 'spacious':
2047
  for key in ['grooming', 'health', 'noise']: