Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +93 -50
scoring_calculation_system.py
CHANGED
@@ -2185,14 +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 |
critical_thresholds = {
|
2192 |
-
'space': 0.
|
2193 |
-
'exercise': 0.
|
2194 |
-
'experience': 0.6,#
|
2195 |
-
'noise': 0.6
|
2196 |
}
|
2197 |
|
2198 |
critical_failures = []
|
@@ -2203,37 +2203,46 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2203 |
# 計算基礎加權分數
|
2204 |
base_score = sum(scores[k] * weights[k] for k in scores.keys())
|
2205 |
|
2206 |
-
#
|
2207 |
if critical_failures:
|
2208 |
-
#
|
2209 |
-
|
2210 |
-
|
2211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2212 |
|
2213 |
-
#
|
2214 |
if len(critical_failures) > 1:
|
2215 |
-
base_score *= (0.
|
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.
|
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.
|
2237 |
|
2238 |
return interaction_penalty
|
2239 |
|
@@ -2315,51 +2324,85 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
2315 |
min_possible_score = 0.3
|
2316 |
|
2317 |
return min(max_possible_score, max(min_possible_score, final_score))
|
2318 |
-
|
2319 |
|
2320 |
def amplify_score_extreme(score: float) -> float:
|
2321 |
"""
|
2322 |
-
|
2323 |
-
-
|
2324 |
-
-
|
2325 |
-
- 一般匹配在75-85%
|
2326 |
-
- 較差匹配在65-75%
|
2327 |
-
- 極差匹配在50-65%
|
2328 |
"""
|
2329 |
-
def smooth_curve(x: float, steepness: float = 12) -> float:
|
2330 |
-
"""使用sigmoid curve"""
|
2331 |
-
import math
|
2332 |
-
return 1 / (1 + math.exp(-steepness * (x - 0.5)))
|
2333 |
-
|
2334 |
if score >= 0.9:
|
2335 |
-
# 完美匹配:
|
2336 |
position = (score - 0.9) / 0.1
|
2337 |
-
return 0.
|
2338 |
|
2339 |
elif score >= 0.8:
|
2340 |
-
# 優秀匹配:
|
2341 |
position = (score - 0.8) / 0.1
|
2342 |
-
return 0.
|
2343 |
|
2344 |
elif score >= 0.7:
|
2345 |
-
# 良好匹配:85
|
2346 |
position = (score - 0.7) / 0.1
|
2347 |
-
return 0.
|
2348 |
|
2349 |
elif score >= 0.5:
|
2350 |
-
# 一般匹配:
|
2351 |
position = (score - 0.5) / 0.2
|
2352 |
-
base = 0.
|
2353 |
-
return base + (smooth_curve(position) * 0.
|
2354 |
|
2355 |
-
|
2356 |
-
# 較差匹配:
|
2357 |
-
position =
|
2358 |
-
base = 0.
|
2359 |
return base + (smooth_curve(position) * 0.10)
|
2360 |
|
2361 |
-
|
2362 |
-
|
2363 |
-
|
2364 |
-
|
2365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2185 |
|
2186 |
def calculate_base_score(scores: dict, weights: dict) -> float:
|
2187 |
"""
|
2188 |
+
計算基礎分數,更寬容地處理極端組合
|
2189 |
"""
|
2190 |
+
# 進一步降低關鍵指標閾值,使系統更包容極端組合
|
2191 |
critical_thresholds = {
|
2192 |
+
'space': 0.5,
|
2193 |
+
'exercise': 0.5,
|
2194 |
+
'experience': 0.6,# 重要的安全考量
|
2195 |
+
'noise': 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 |
+
space_exercise_penalty = 0
|
2210 |
+
other_penalty = 0
|
2211 |
+
|
2212 |
+
for metric, score in critical_failures:
|
2213 |
+
if metric in ['space', 'exercise']:
|
2214 |
+
# 空間和運動相關的失敗給予更溫和的懲罰
|
2215 |
+
space_exercise_penalty += (critical_thresholds[metric] - score) * 0.2
|
2216 |
+
else:
|
2217 |
+
# 其他失敗維持原有懲罰程度
|
2218 |
+
other_penalty += (critical_thresholds[metric] - score) * 0.4
|
2219 |
+
|
2220 |
+
# 應用懲罰時更有彈性
|
2221 |
+
total_penalty = (space_exercise_penalty + other_penalty) / 2
|
2222 |
+
base_score *= (1 - total_penalty)
|
2223 |
|
2224 |
+
# 進一步降低多重失敗的懲罰
|
2225 |
if len(critical_failures) > 1:
|
2226 |
+
base_score *= (0.97 ** (len(critical_failures) - 1))
|
2227 |
|
2228 |
return base_score
|
2229 |
|
2230 |
|
2231 |
def evaluate_condition_interactions(scores: dict) -> float:
|
2232 |
"""
|
2233 |
+
評估不同條件間的相互影響,更寬容地處理極端組合
|
2234 |
"""
|
2235 |
interaction_penalty = 1.0
|
2236 |
|
2237 |
+
# 只保留最基本的經驗相關評估
|
2238 |
if user_prefs.experience_level == 'beginner':
|
2239 |
if breed_info.get('Care Level') == 'HIGH':
|
2240 |
+
interaction_penalty *= 0.95
|
|
|
|
|
2241 |
|
2242 |
+
# 運動時間與類型的基本互動也降低懲罰程度
|
2243 |
exercise_needs = breed_info.get('Exercise Needs', 'MODERATE').upper()
|
2244 |
if exercise_needs == 'VERY HIGH' and user_prefs.exercise_type == 'light_walks':
|
2245 |
+
interaction_penalty *= 0.95
|
2246 |
|
2247 |
return interaction_penalty
|
2248 |
|
|
|
2324 |
min_possible_score = 0.3
|
2325 |
|
2326 |
return min(max_possible_score, max(min_possible_score, final_score))
|
2327 |
+
|
2328 |
|
2329 |
def amplify_score_extreme(score: float) -> float:
|
2330 |
"""
|
2331 |
+
優化分數分布:
|
2332 |
+
- 提高高分的區別度
|
2333 |
+
- 維持低分的合理性
|
|
|
|
|
|
|
2334 |
"""
|
|
|
|
|
|
|
|
|
|
|
2335 |
if score >= 0.9:
|
2336 |
+
# 完美匹配:92-99%
|
2337 |
position = (score - 0.9) / 0.1
|
2338 |
+
return 0.92 + (position * 0.07)
|
2339 |
|
2340 |
elif score >= 0.8:
|
2341 |
+
# 優秀匹配:85-92%
|
2342 |
position = (score - 0.8) / 0.1
|
2343 |
+
return 0.85 + (position * 0.07)
|
2344 |
|
2345 |
elif score >= 0.7:
|
2346 |
+
# 良好匹配:78-85%
|
2347 |
position = (score - 0.7) / 0.1
|
2348 |
+
return 0.78 + (position * 0.07)
|
2349 |
|
2350 |
elif score >= 0.5:
|
2351 |
+
# 一般匹配:70-78%
|
2352 |
position = (score - 0.5) / 0.2
|
2353 |
+
base = 0.70
|
2354 |
+
return base + (smooth_curve(position) * 0.08)
|
2355 |
|
2356 |
+
else:
|
2357 |
+
# 較差匹配:60-70%
|
2358 |
+
position = score / 0.5
|
2359 |
+
base = 0.60
|
2360 |
return base + (smooth_curve(position) * 0.10)
|
2361 |
|
2362 |
+
|
2363 |
+
# def amplify_score_extreme(score: float) -> float:
|
2364 |
+
# """
|
2365 |
+
# - 完美匹配可達到95-99%
|
2366 |
+
# - 優秀匹配在90-95%
|
2367 |
+
# - 良好匹配在85-90%
|
2368 |
+
# - 一般匹配在75-85%
|
2369 |
+
# - 較差匹配在65-75%
|
2370 |
+
# - 極差匹配在50-65%
|
2371 |
+
# """
|
2372 |
+
# def smooth_curve(x: float, steepness: float = 12) -> float:
|
2373 |
+
# """使用sigmoid curve"""
|
2374 |
+
# import math
|
2375 |
+
# return 1 / (1 + math.exp(-steepness * (x - 0.5)))
|
2376 |
+
|
2377 |
+
# if score >= 0.9:
|
2378 |
+
# # 完美匹配:95-99%
|
2379 |
+
# position = (score - 0.9) / 0.1
|
2380 |
+
# return 0.95 + (position * 0.04)
|
2381 |
+
|
2382 |
+
# elif score >= 0.8:
|
2383 |
+
# # 優秀匹配:90-95%
|
2384 |
+
# position = (score - 0.8) / 0.1
|
2385 |
+
# return 0.90 + (position * 0.05)
|
2386 |
+
|
2387 |
+
# elif score >= 0.7:
|
2388 |
+
# # 良好匹配:85-90%
|
2389 |
+
# position = (score - 0.7) / 0.1
|
2390 |
+
# return 0.85 + (position * 0.05)
|
2391 |
+
|
2392 |
+
# elif score >= 0.5:
|
2393 |
+
# # 一般匹配:75-85%
|
2394 |
+
# position = (score - 0.5) / 0.2
|
2395 |
+
# base = 0.75
|
2396 |
+
# return base + (smooth_curve(position) * 0.10)
|
2397 |
+
|
2398 |
+
# elif score >= 0.3:
|
2399 |
+
# # 較差匹配:65-75%
|
2400 |
+
# position = (score - 0.3) / 0.2
|
2401 |
+
# base = 0.65
|
2402 |
+
# return base + (smooth_curve(position) * 0.10)
|
2403 |
+
|
2404 |
+
# else:
|
2405 |
+
# # 極差匹配:50-65%
|
2406 |
+
# position = score / 0.3
|
2407 |
+
# base = 0.50
|
2408 |
+
# return base + (smooth_curve(position) * 0.15)
|