Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +31 -11
scoring_calculation_system.py
CHANGED
|
@@ -2,7 +2,6 @@ from dataclasses import dataclass
|
|
| 2 |
from breed_health_info import breed_health_info
|
| 3 |
from breed_noise_info import breed_noise_info
|
| 4 |
import traceback
|
| 5 |
-
import math
|
| 6 |
|
| 7 |
@dataclass
|
| 8 |
class UserPreferences:
|
|
@@ -2328,33 +2327,54 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
| 2328 |
|
| 2329 |
def amplify_score_extreme(score: float) -> float:
|
| 2330 |
"""
|
| 2331 |
-
|
| 2332 |
-
|
| 2333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2334 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2335 |
if score >= 0.9:
|
| 2336 |
-
#
|
| 2337 |
-
|
| 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)
|
|
|
|
| 2 |
from breed_health_info import breed_health_info
|
| 3 |
from breed_noise_info import breed_noise_info
|
| 4 |
import traceback
|
|
|
|
| 5 |
|
| 6 |
@dataclass
|
| 7 |
class UserPreferences:
|
|
|
|
| 2327 |
|
| 2328 |
def amplify_score_extreme(score: float) -> float:
|
| 2329 |
"""
|
| 2330 |
+
優化分數分布,使結果更具區別性並維持合理範圍
|
| 2331 |
+
|
| 2332 |
+
透過分段函數來調整分數:
|
| 2333 |
+
- 90-100的原始分數會被映射到92-99%
|
| 2334 |
+
- 80-90的原始分數會被映射到85-92%
|
| 2335 |
+
- 70-80的原始分數會被映射到78-85%
|
| 2336 |
+
- 50-70的原始分數會被映射到70-78%
|
| 2337 |
+
- 50以下的原始分數會被映射到60-70%
|
| 2338 |
+
|
| 2339 |
+
使用sigmoid曲線來平滑較低分數的轉換,避免突兀的分數跳變
|
| 2340 |
"""
|
| 2341 |
+
def smooth_curve(x: float, steepness: float = 12) -> float:
|
| 2342 |
+
"""
|
| 2343 |
+
使用sigmoid曲線來平滑分數轉換
|
| 2344 |
+
|
| 2345 |
+
參數:
|
| 2346 |
+
x: 0-1之間的位置值
|
| 2347 |
+
steepness: 曲線的陡峭程度,較大的值會使轉換更加陡峭
|
| 2348 |
+
|
| 2349 |
+
返回:
|
| 2350 |
+
0-1之間的平滑轉換值
|
| 2351 |
+
"""
|
| 2352 |
+
import math
|
| 2353 |
+
return 1 / (1 + math.exp(-steepness * (x - 0.5)))
|
| 2354 |
+
|
| 2355 |
+
# 處理最高分數範圍:90-100 -> 92-99
|
| 2356 |
if score >= 0.9:
|
| 2357 |
+
position = (score - 0.9) / 0.1 # 計算在這個區間內的相對位置
|
| 2358 |
+
return 0.92 + (position * 0.07) # 線性映射到92-99
|
|
|
|
| 2359 |
|
| 2360 |
+
# 處理優秀分數範圍:80-90 -> 85-92
|
| 2361 |
elif score >= 0.8:
|
|
|
|
| 2362 |
position = (score - 0.8) / 0.1
|
| 2363 |
return 0.85 + (position * 0.07)
|
| 2364 |
|
| 2365 |
+
# 處理良好分數範圍:70-80 -> 78-85
|
| 2366 |
elif score >= 0.7:
|
|
|
|
| 2367 |
position = (score - 0.7) / 0.1
|
| 2368 |
return 0.78 + (position * 0.07)
|
| 2369 |
|
| 2370 |
+
# 處理一般分數範圍:50-70 -> 70-78
|
| 2371 |
elif score >= 0.5:
|
|
|
|
| 2372 |
position = (score - 0.5) / 0.2
|
| 2373 |
base = 0.70
|
| 2374 |
return base + (smooth_curve(position) * 0.08)
|
| 2375 |
|
| 2376 |
+
# 處理較低分數範圍:0-50 -> 60-70
|
| 2377 |
else:
|
|
|
|
| 2378 |
position = score / 0.5
|
| 2379 |
base = 0.60
|
| 2380 |
return base + (smooth_curve(position) * 0.10)
|