fix: use equal weight sharing for remaining 15% and quantize min_rate floor comparison to 2 decimal places
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user