Spaces:
Running
on
Zero
Running
on
Zero
Update scoring_calculation_system.py
Browse files- scoring_calculation_system.py +31 -38
scoring_calculation_system.py
CHANGED
@@ -1607,59 +1607,52 @@ def calculate_breed_compatibility_score(scores: dict, user_prefs: UserPreference
|
|
1607 |
|
1608 |
def amplify_score_extreme(score: float) -> float:
|
1609 |
"""
|
1610 |
-
|
1611 |
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
1615 |
-
|
|
|
|
|
|
|
1616 |
"""
|
|
|
1617 |
ranges = {
|
1618 |
'poor': {
|
1619 |
-
'range': (0, 0.
|
1620 |
-
'out_min':
|
1621 |
-
'out_max':
|
1622 |
-
'amplification': 1.3 # 加強懲罰效果
|
1623 |
},
|
1624 |
'mediocre': {
|
1625 |
-
'range': (0.
|
1626 |
-
'out_min':
|
1627 |
-
'out_max':
|
1628 |
-
'amplification': 0.9 # 略微抑制中等分數
|
1629 |
},
|
1630 |
'good': {
|
1631 |
-
'range': (0.
|
1632 |
-
'out_min':
|
1633 |
-
'out_max':
|
1634 |
-
'amplification': 1.1
|
1635 |
},
|
1636 |
'excellent': {
|
1637 |
-
'range': (0.
|
1638 |
-
'out_min':
|
1639 |
-
'out_max':
|
1640 |
-
'amplification': 1.4 # 加強獎勵效果
|
1641 |
}
|
1642 |
}
|
1643 |
|
1644 |
-
#
|
1645 |
-
for
|
1646 |
range_min, range_max = config['range']
|
1647 |
if range_min <= score <= range_max:
|
1648 |
-
#
|
1649 |
-
|
1650 |
-
|
1651 |
-
# 應用非線性調整
|
1652 |
-
range_position = min(1.0, range_position * config['amplification'])
|
1653 |
-
|
1654 |
-
# 轉換到目標範圍
|
1655 |
-
amplified = config['out_min'] + (config['out_max'] - config['out_min']) * range_position
|
1656 |
|
1657 |
-
#
|
1658 |
-
|
1659 |
-
variation = random.uniform(-0.5, 0.5)
|
1660 |
-
amplified += variation
|
1661 |
|
1662 |
-
|
|
|
1663 |
|
1664 |
-
#
|
1665 |
-
return
|
|
|
1607 |
|
1608 |
def amplify_score_extreme(score: float) -> float:
|
1609 |
"""
|
1610 |
+
將原始分數(0-1範圍)映射到最終評分範圍(60-95%)
|
1611 |
|
1612 |
+
分數映射邏輯:
|
1613 |
+
- 0-0.3: 60-70% (較差匹配)
|
1614 |
+
- 0.3-0.6: 70-80% (中等匹配)
|
1615 |
+
- 0.6-0.8: 80-90% (良好匹配)
|
1616 |
+
- 0.8-1.0: 90-95% (優秀匹配)
|
1617 |
+
|
1618 |
+
每個區間使用線性映射,確保相同輸入產生相同輸出
|
1619 |
"""
|
1620 |
+
# 定義分數區間和對應的輸出範圍
|
1621 |
ranges = {
|
1622 |
'poor': {
|
1623 |
+
'range': (0.0, 0.3),
|
1624 |
+
'out_min': 60.0,
|
1625 |
+
'out_max': 70.0
|
|
|
1626 |
},
|
1627 |
'mediocre': {
|
1628 |
+
'range': (0.3, 0.6),
|
1629 |
+
'out_min': 70.0,
|
1630 |
+
'out_max': 80.0
|
|
|
1631 |
},
|
1632 |
'good': {
|
1633 |
+
'range': (0.6, 0.8),
|
1634 |
+
'out_min': 80.0,
|
1635 |
+
'out_max': 90.0
|
|
|
1636 |
},
|
1637 |
'excellent': {
|
1638 |
+
'range': (0.8, 1.0),
|
1639 |
+
'out_min': 90.0,
|
1640 |
+
'out_max': 95.0
|
|
|
1641 |
}
|
1642 |
}
|
1643 |
|
1644 |
+
# 找出分數所屬區間並進行映射
|
1645 |
+
for config in ranges.values():
|
1646 |
range_min, range_max = config['range']
|
1647 |
if range_min <= score <= range_max:
|
1648 |
+
# 計算在當前區間的相對位置(0-1)
|
1649 |
+
position = (score - range_min) / (range_max - range_min)
|
|
|
|
|
|
|
|
|
|
|
|
|
1650 |
|
1651 |
+
# 線性映射到目標範圍
|
1652 |
+
result = config['out_min'] + (config['out_max'] - config['out_min']) * position
|
|
|
|
|
1653 |
|
1654 |
+
# 返回固定精度的分數
|
1655 |
+
return round(result, 1)
|
1656 |
|
1657 |
+
# 處理超出範圍的情況
|
1658 |
+
return 60.0 if score < 0.0 else 95.0
|