DawnC commited on
Commit
ce1b7d5
1 Parent(s): 2f935ba

Update scoring_calculation_system.py

Browse files
Files changed (1) hide show
  1. scoring_calculation_system.py +38 -134
scoring_calculation_system.py CHANGED
@@ -1813,93 +1813,33 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
1813
 
1814
  return multiplier
1815
 
1816
- # def evaluate_breed_specific_requirements():
1817
- # """評估品種特定的要求,加強運動需求的判斷"""
1818
- # multiplier = 1.0
1819
- # exercise_time = user_prefs.exercise_time
1820
- # exercise_type = user_prefs.exercise_type
1821
-
1822
- # # 檢查品種的基本特性
1823
- # temperament = breed_info.get('Temperament', '').lower()
1824
- # description = breed_info.get('Description', '').lower()
1825
- # exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
1826
-
1827
- # # 加強運動需求的匹配判斷
1828
- # if exercise_needs == 'LOW':
1829
- # if exercise_time > 90: # 如果用戶運動時間過長
1830
- # multiplier *= 0.5 # 給予更強的懲罰
1831
- # elif exercise_needs == 'VERY HIGH':
1832
- # if exercise_time < 60: # 如果用戶運動時間過短
1833
- # multiplier *= 0.5
1834
-
1835
- # if 'sprint' in temperament:
1836
- # if exercise_time > 120 and exercise_type != 'active_training':
1837
- # multiplier *= 0.7
1838
-
1839
- # if any(trait in temperament for trait in ['working', 'herding']):
1840
- # if exercise_time < 90 or exercise_type == 'light_walks':
1841
- # multiplier *= 0.7
1842
-
1843
- # return multiplier
1844
-
1845
  def evaluate_breed_specific_requirements():
1846
- """
1847
- 1. 嚴格的運動需求匹配
1848
- 2. 細緻的品種特性評估
1849
- 3. 強化經驗要求的判斷
1850
- """
1851
  multiplier = 1.0
1852
  exercise_time = user_prefs.exercise_time
1853
  exercise_type = user_prefs.exercise_type
1854
 
1855
- # 獲取品種的關鍵特性
1856
  temperament = breed_info.get('Temperament', '').lower()
1857
  description = breed_info.get('Description', '').lower()
1858
  exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
1859
- care_level = breed_info.get('Care Level', 'MODERATE').upper()
1860
-
1861
- # 運動需求匹配評估
1862
- exercise_mismatch = {
1863
- 'VERY HIGH': {
1864
- 'min_time': 60,
1865
- 'penalty_rate': 0.4 if exercise_time < 60 else 0.0
1866
- },
1867
- 'HIGH': {
1868
- 'min_time': 45,
1869
- 'penalty_rate': 0.35 if exercise_time < 45 else 0.0
1870
- },
1871
- 'LOW': {
1872
- 'max_time': 90,
1873
- 'penalty_rate': 0.4 if exercise_time > 90 else 0.0
1874
- }
1875
- }
1876
-
1877
- if exercise_needs in exercise_mismatch:
1878
- match_info = exercise_mismatch[exercise_needs]
1879
- if 'min_time' in match_info and exercise_time < match_info['min_time']:
1880
- multiplier *= (1 - match_info['penalty_rate'])
1881
- elif 'max_time' in match_info and exercise_time > match_info['max_time']:
1882
- multiplier *= (1 - match_info['penalty_rate'])
1883
-
1884
- # 品種特性專門評估
1885
- breed_traits = {
1886
- 'working_dog': ['working', 'herding', 'intelligent', 'active'],
1887
- 'family_dog': ['gentle', 'friendly', 'good with children', 'patient'],
1888
- 'guard_dog': ['protective', 'territorial', 'alert', 'watchdog']
1889
- }
1890
-
1891
- # 根據用戶條件評估特殊特性
1892
- for trait_type, traits in breed_traits.items():
1893
- if any(trait in temperament for trait in traits):
1894
- if trait_type == 'working_dog':
1895
- if user_prefs.experience_level == 'beginner':
1896
- multiplier *= 0.7
1897
- if exercise_time < 90:
1898
- multiplier *= 0.75
1899
- elif trait_type == 'guard_dog':
1900
- if user_prefs.has_children and user_prefs.experience_level != 'advanced':
1901
- multiplier *= 0.8
1902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1903
  return multiplier
1904
 
1905
  def evaluate_environmental_impact():
@@ -1929,76 +1869,40 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
1929
  final_score = score * severity_multiplier
1930
  return max(0.2, min(1.0, final_score))
1931
 
1932
- # def calculate_base_score(scores: dict, weights: dict) -> float:
1933
- # """
1934
- # 計算基礎分數,更寬容地處理極端組合
1935
- # """
1936
- # # 進一步降低關鍵指標閾值,使系統更包容極端組合
1937
- # critical_thresholds = {
1938
- # 'space': 0.45, # 進一步降低閾值
1939
- # 'exercise': 0.45,
1940
- # 'experience': 0.55,
1941
- # 'noise': 0.55
1942
- # }
1943
-
1944
- # critical_failures = []
1945
- # for metric, threshold in critical_thresholds.items():
1946
- # if scores[metric] < threshold:
1947
- # critical_failures.append((metric, scores[metric]))
1948
-
1949
- # base_score = sum(scores[k] * weights[k] for k in scores.keys())
1950
-
1951
- # if critical_failures:
1952
- # space_exercise_penalty = 0
1953
- # other_penalty = 0
1954
-
1955
- # for metric, score in critical_failures:
1956
- # if metric in ['space', 'exercise']:
1957
- # space_exercise_penalty += (critical_thresholds[metric] - score) * 0.15 # 降低懲罰
1958
- # else:
1959
- # other_penalty += (critical_thresholds[metric] - score) * 0.3
1960
-
1961
- # total_penalty = (space_exercise_penalty + other_penalty) / 2
1962
- # base_score *= (1 - total_penalty)
1963
-
1964
- # if len(critical_failures) > 1:
1965
- # base_score *= (0.98 ** (len(critical_failures) - 1)) # 進一步降低多重失敗懲罰
1966
-
1967
- # return base_score
1968
-
1969
  def calculate_base_score(scores: dict, weights: dict) -> float:
1970
  """
1971
- 計算基礎分數,加強訓練需求評估
1972
  """
1973
- # 基礎閾值保持不變
1974
  critical_thresholds = {
1975
- 'space': 0.5,
1976
- 'exercise': 0.5,
1977
- 'experience': 0.55,
1978
- 'noise': 0.55
1979
  }
1980
 
1981
- # 評估訓練需求
1982
- training_level = breed_info.get('Training', 'MODERATE').upper()
1983
- if training_level == 'HIGH' and user_prefs.experience_level == 'beginner':
1984
- # 對需要大量訓練的品種給予較低的基礎分數
1985
- base_score = sum(scores[k] * weights[k] for k in scores.keys()) * 0.85
1986
- else:
1987
- base_score = sum(scores[k] * weights[k] for k in scores.keys())
1988
-
1989
- # 其他評估邏輯保持不變...
1990
  critical_failures = []
1991
  for metric, threshold in critical_thresholds.items():
1992
  if scores[metric] < threshold:
1993
  critical_failures.append((metric, scores[metric]))
1994
 
 
 
1995
  if critical_failures:
1996
- penalty = sum((critical_thresholds[metric] - score) * 0.3
1997
- for metric, score in critical_failures) / len(critical_failures)
1998
- base_score *= (1 - penalty)
 
 
 
 
 
 
 
 
1999
 
2000
  if len(critical_failures) > 1:
2001
- base_score *= (0.98 ** (len(critical_failures) - 1))
2002
 
2003
  return base_score
2004
 
 
1813
 
1814
  return multiplier
1815
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1816
  def evaluate_breed_specific_requirements():
1817
+ """評估品種特定的要求,加強運動需求的判斷"""
 
 
 
 
1818
  multiplier = 1.0
1819
  exercise_time = user_prefs.exercise_time
1820
  exercise_type = user_prefs.exercise_type
1821
 
1822
+ # 檢查品種的基本特性
1823
  temperament = breed_info.get('Temperament', '').lower()
1824
  description = breed_info.get('Description', '').lower()
1825
  exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1826
 
1827
+ # 加強運動需求的匹配判斷
1828
+ if exercise_needs == 'LOW':
1829
+ if exercise_time > 90: # 如果用戶運動時間過長
1830
+ multiplier *= 0.5 # 給予更強的懲罰
1831
+ elif exercise_needs == 'VERY HIGH':
1832
+ if exercise_time < 60: # 如果用戶運動時間過短
1833
+ multiplier *= 0.5
1834
+
1835
+ if 'sprint' in temperament:
1836
+ if exercise_time > 120 and exercise_type != 'active_training':
1837
+ multiplier *= 0.7
1838
+
1839
+ if any(trait in temperament for trait in ['working', 'herding']):
1840
+ if exercise_time < 90 or exercise_type == 'light_walks':
1841
+ multiplier *= 0.7
1842
+
1843
  return multiplier
1844
 
1845
  def evaluate_environmental_impact():
 
1869
  final_score = score * severity_multiplier
1870
  return max(0.2, min(1.0, final_score))
1871
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1872
  def calculate_base_score(scores: dict, weights: dict) -> float:
1873
  """
1874
+ 計算基礎分數,更寬容地處理極端組合
1875
  """
1876
+ # 進一步降低關鍵指標閾值,使系統更包容極端組合
1877
  critical_thresholds = {
1878
+ 'space': 0.45, # 進一步降低閾值
1879
+ 'exercise': 0.45,
1880
+ 'experience': 0.55,
1881
+ 'noise': 0.55
1882
  }
1883
 
 
 
 
 
 
 
 
 
 
1884
  critical_failures = []
1885
  for metric, threshold in critical_thresholds.items():
1886
  if scores[metric] < threshold:
1887
  critical_failures.append((metric, scores[metric]))
1888
 
1889
+ base_score = sum(scores[k] * weights[k] for k in scores.keys())
1890
+
1891
  if critical_failures:
1892
+ space_exercise_penalty = 0
1893
+ other_penalty = 0
1894
+
1895
+ for metric, score in critical_failures:
1896
+ if metric in ['space', 'exercise']:
1897
+ space_exercise_penalty += (critical_thresholds[metric] - score) * 0.15 # 降低懲罰
1898
+ else:
1899
+ other_penalty += (critical_thresholds[metric] - score) * 0.3
1900
+
1901
+ total_penalty = (space_exercise_penalty + other_penalty) / 2
1902
+ base_score *= (1 - total_penalty)
1903
 
1904
  if len(critical_failures) > 1:
1905
+ base_score *= (0.98 ** (len(critical_failures) - 1)) # 進一步降低多重失敗懲罰
1906
 
1907
  return base_score
1908