Spaces:
Running
Running
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +26 -43
scoring_calculation_system.py
CHANGED
@@ -2089,23 +2089,23 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2089 |
處理特殊情況的分數調整,著重:
|
2090 |
1. 條件組合的協同效應
|
2091 |
2. 品種特性的特殊要求
|
2092 |
-
3.
|
2093 |
"""
|
2094 |
severity_multiplier = 1.0
|
2095 |
|
2096 |
def evaluate_spatial_exercise_combination():
|
2097 |
-
"""
|
|
|
|
|
|
|
2098 |
multiplier = 1.0
|
2099 |
|
2100 |
if user_prefs.living_space == 'apartment':
|
2101 |
-
|
2102 |
-
multiplier *= 0.5
|
2103 |
-
elif breed_info.get('Exercise Needs') == 'HIGH':
|
2104 |
-
multiplier *= 0.6
|
2105 |
|
2106 |
-
#
|
2107 |
if breed_info['Size'] in ['Large', 'Giant']:
|
2108 |
-
multiplier *= 0.5
|
2109 |
|
2110 |
return multiplier
|
2111 |
|
@@ -2185,15 +2185,14 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2185 |
|
2186 |
def calculate_base_score(scores: dict, weights: dict) -> float:
|
2187 |
"""
|
2188 |
-
|
2189 |
-
就像學校的評分系統,某些科目不及格會嚴重影響總成績。
|
2190 |
"""
|
2191 |
-
#
|
2192 |
critical_thresholds = {
|
2193 |
-
'space': 0.7
|
2194 |
-
'exercise': 0.7
|
2195 |
-
'experience': 0.7
|
2196 |
-
'noise': 0.65
|
2197 |
}
|
2198 |
|
2199 |
critical_failures = []
|
@@ -2204,59 +2203,43 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2204 |
# 計算基礎加權分數
|
2205 |
base_score = sum(scores[k] * weights[k] for k in scores.keys())
|
2206 |
|
2207 |
-
#
|
2208 |
if critical_failures:
|
2209 |
-
#
|
2210 |
worst_failure = min(score for _, score in critical_failures)
|
2211 |
-
penalty = (critical_thresholds['space'] - worst_failure) * 0.6
|
2212 |
base_score *= (1 - penalty)
|
2213 |
|
2214 |
-
#
|
2215 |
if len(critical_failures) > 1:
|
2216 |
-
base_score *= (0.
|
2217 |
|
2218 |
return base_score
|
2219 |
|
2220 |
|
2221 |
def evaluate_condition_interactions(scores: dict) -> float:
|
2222 |
"""
|
2223 |
-
|
2224 |
-
就像運動訓練中,不同因素之間的配合度會影響整體效果。
|
2225 |
"""
|
2226 |
interaction_penalty = 1.0
|
2227 |
|
2228 |
-
# 居住空間與運動需求的互動
|
2229 |
-
if user_prefs.living_space == 'house_small':
|
2230 |
-
if user_prefs.exercise_time > 120:
|
2231 |
-
interaction_penalty *= 0.85
|
2232 |
-
elif user_prefs.exercise_time > 90:
|
2233 |
-
interaction_penalty *= 0.9
|
2234 |
-
|
2235 |
# 經驗等級與其他因素的互動
|
2236 |
if user_prefs.experience_level == 'beginner':
|
2237 |
if breed_info.get('Care Level') == 'HIGH':
|
2238 |
-
interaction_penalty *= 0.
|
2239 |
-
if user_prefs.exercise_time > 150:
|
2240 |
-
interaction_penalty *= 0.85
|
2241 |
if breed_info.get('Exercise Needs', 'MODERATE').upper() == 'VERY HIGH':
|
2242 |
-
interaction_penalty *= 0.
|
2243 |
-
|
2244 |
-
#
|
2245 |
-
if user_prefs.living_space != 'house_large':
|
2246 |
-
if breed_info['Size'] in ['Large', 'Giant']:
|
2247 |
-
interaction_penalty *= 0.8
|
2248 |
-
|
2249 |
-
# 運動時間與類型的互動
|
2250 |
exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
|
2251 |
if exercise_needs == 'VERY HIGH' and user_prefs.exercise_type == 'light_walks':
|
2252 |
-
interaction_penalty *= 0.
|
2253 |
-
|
2254 |
return interaction_penalty
|
2255 |
|
2256 |
def calculate_adjusted_perfect_bonus(perfect_conditions: dict) -> float:
|
2257 |
"""
|
2258 |
計算完美匹配獎勵,但更注重條件的整體表現。
|
2259 |
-
就像全能運動員的評分,需要在各個項目都表現出色。
|
2260 |
"""
|
2261 |
bonus = 1.0
|
2262 |
|
|
|
2089 |
處理特殊情況的分數調整,著重:
|
2090 |
1. 條件組合的協同效應
|
2091 |
2. 品種特性的特殊要求
|
2092 |
+
3. 極端情況的處理
|
2093 |
"""
|
2094 |
severity_multiplier = 1.0
|
2095 |
|
2096 |
def evaluate_spatial_exercise_combination():
|
2097 |
+
"""
|
2098 |
+
評估空間與運動需求的組合影響
|
2099 |
+
修改重點:移除對高運動需求的懲罰,只保留體型相關評估
|
2100 |
+
"""
|
2101 |
multiplier = 1.0
|
2102 |
|
2103 |
if user_prefs.living_space == 'apartment':
|
2104 |
+
# 移除運動需求相關的懲罰
|
|
|
|
|
|
|
2105 |
|
2106 |
+
# 只保留體型的基本評估,但降低懲罰程度
|
2107 |
if breed_info['Size'] in ['Large', 'Giant']:
|
2108 |
+
multiplier *= 0.7 # 從0.5提升到0.7,因為大型犬確實需要考慮空間限制
|
2109 |
|
2110 |
return multiplier
|
2111 |
|
|
|
2185 |
|
2186 |
def calculate_base_score(scores: dict, weights: dict) -> float:
|
2187 |
"""
|
2188 |
+
計算基礎分數,降低懲罰力度,允許某些維度有較低分數
|
|
|
2189 |
"""
|
2190 |
+
# 調整關鍵指標閾值,降低要求
|
2191 |
critical_thresholds = {
|
2192 |
+
'space': 0.6, # 從0.7降低到0.6
|
2193 |
+
'exercise': 0.6, # 從0.7降低到0.6
|
2194 |
+
'experience': 0.6,# 從0.7降低到0.6
|
2195 |
+
'noise': 0.6 # 從0.65降低到0.6
|
2196 |
}
|
2197 |
|
2198 |
critical_failures = []
|
|
|
2203 |
# 計算基礎加權分數
|
2204 |
base_score = sum(scores[k] * weights[k] for k in scores.keys())
|
2205 |
|
2206 |
+
# 降低懲罰程度
|
2207 |
if critical_failures:
|
2208 |
+
# 降低最嚴重不足的懲罰影響
|
2209 |
worst_failure = min(score for _, score in critical_failures)
|
2210 |
+
penalty = (critical_thresholds['space'] - worst_failure) * 0.4 # 從0.6降到0.4
|
2211 |
base_score *= (1 - penalty)
|
2212 |
|
2213 |
+
# 降低多重失敗的懲罰
|
2214 |
if len(critical_failures) > 1:
|
2215 |
+
base_score *= (0.95 ** (len(critical_failures) - 1)) # 從0.9提升到0.95
|
2216 |
|
2217 |
return base_score
|
2218 |
|
2219 |
|
2220 |
def evaluate_condition_interactions(scores: dict) -> float:
|
2221 |
"""
|
2222 |
+
評估不同條件間的相互影響,移除對空間與運動組合的懲罰
|
|
|
2223 |
"""
|
2224 |
interaction_penalty = 1.0
|
2225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2226 |
# 經驗等級與其他因素的互動
|
2227 |
if user_prefs.experience_level == 'beginner':
|
2228 |
if breed_info.get('Care Level') == 'HIGH':
|
2229 |
+
interaction_penalty *= 0.9
|
|
|
|
|
2230 |
if breed_info.get('Exercise Needs', 'MODERATE').upper() == 'VERY HIGH':
|
2231 |
+
interaction_penalty *= 0.9
|
2232 |
+
|
2233 |
+
# 運動時間與類型的基本互動
|
|
|
|
|
|
|
|
|
|
|
2234 |
exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
|
2235 |
if exercise_needs == 'VERY HIGH' and user_prefs.exercise_type == 'light_walks':
|
2236 |
+
interaction_penalty *= 0.9
|
2237 |
+
|
2238 |
return interaction_penalty
|
2239 |
|
2240 |
def calculate_adjusted_perfect_bonus(perfect_conditions: dict) -> float:
|
2241 |
"""
|
2242 |
計算完美匹配獎勵,但更注重條件的整體表現。
|
|
|
2243 |
"""
|
2244 |
bonus = 1.0
|
2245 |
|