fix: use equal weight sharing for remaining 15% and quantize min_rate floor comparison to 2 decimal places

This commit is contained in:
SmartUp Developer
2026-07-02 20:45:40 +08:00
parent 8746068cd4
commit 9011c68b9d
2 changed files with 17 additions and 14 deletions
+6 -12
View File
@@ -71,15 +71,9 @@ def calculate_target_rate(values: list[Any], percent: Any = 0, algorithm: str =
if N == 1:
base = rates_sorted[0]
else:
base = Decimal("0")
remaining = Decimal("1.0")
for i in range(N):
if i == N - 1:
weight = remaining
else:
weight = remaining * Decimal("0.85")
remaining -= weight
base += rates_sorted[i] * weight
w1 = Decimal("0.85")
w_others = Decimal("0.15") / Decimal(N - 1)
base = rates_sorted[0] * w1 + sum(rates_sorted[1:], Decimal("0")) * w_others
else:
raise WebsiteError(f"不支持的算法:{algorithm}")
pct = Decimal(str(percent or 0))
@@ -87,9 +81,9 @@ def calculate_target_rate(values: list[Any], percent: Any = 0, algorithm: str =
raise WebsiteError("百分比不能为负数")
target_rate = (base * (Decimal("1") + pct / Decimal("100"))).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
if algorithm == "priority_weighted_plus_percent":
min_rate = min(rates)
if target_rate < min_rate:
target_rate = min_rate
min_rate_2d = min(rates).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)
if target_rate < min_rate_2d:
target_rate = min_rate_2d
return target_rate