mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
fix: change quota notify threshold semantics to "remaining quota"
Threshold now represents remaining quota instead of usage amount: - Fixed ($): threshold=400, limit=1000 → alert when remaining drops to $400 (i.e., usage reaches $600) - Percentage (%): threshold=30%, limit=1000 → alert when remaining drops to 30% (i.e., usage reaches $700) Also: - Rename 告警阈值 → 提醒阈值 in i18n - Widen type dropdown to w-16 for proper $ / % display
This commit is contained in:
@@ -1 +1 @@
|
||||
0.1.110.33
|
||||
0.1.110.34
|
||||
|
||||
@@ -137,13 +137,18 @@ type quotaDim struct {
|
||||
limit float64
|
||||
}
|
||||
|
||||
// resolvedThreshold returns the effective threshold value.
|
||||
// For percentage type, it computes threshold = limit * percentage / 100.
|
||||
// resolvedThreshold converts the user-facing "remaining" threshold into a usage-based trigger point.
|
||||
// The threshold represents how much quota REMAINS when the alert fires:
|
||||
// - Fixed ($): threshold=400, limit=1000 → fires when usage reaches 600 (remaining drops to 400)
|
||||
// - Percentage (%): threshold=30, limit=1000 → fires when usage reaches 700 (remaining drops to 30%)
|
||||
func (d quotaDim) resolvedThreshold() float64 {
|
||||
if d.thresholdType == thresholdTypePercentage && d.limit > 0 {
|
||||
return d.limit * d.threshold / 100
|
||||
if d.limit <= 0 {
|
||||
return 0
|
||||
}
|
||||
return d.threshold
|
||||
if d.thresholdType == thresholdTypePercentage {
|
||||
return d.limit * (1 - d.threshold/100)
|
||||
}
|
||||
return d.limit - d.threshold
|
||||
}
|
||||
|
||||
// buildQuotaDims returns the three quota dimensions for notification checking.
|
||||
|
||||
@@ -42,7 +42,7 @@ const emit = defineEmits<{
|
||||
<select
|
||||
:value="thresholdType || 'fixed'"
|
||||
@change="emit('update:thresholdType', ($event.target as HTMLSelectElement).value)"
|
||||
class="input py-1 text-xs w-14 flex-shrink-0 text-center appearance-auto"
|
||||
class="input py-1 text-xs w-16 flex-shrink-0 text-center"
|
||||
>
|
||||
<option value="fixed">$</option>
|
||||
<option value="percentage">%</option>
|
||||
|
||||
@@ -2243,7 +2243,7 @@ export default {
|
||||
quotaLimitAmount: 'Total Limit',
|
||||
quotaLimitAmountHint: 'Cumulative spending limit. Does not auto-reset.',
|
||||
quotaNotify: {
|
||||
alert: 'Alert Threshold',
|
||||
alert: 'Alert',
|
||||
enabled: 'Enable Alert',
|
||||
threshold: 'Alert Amount',
|
||||
thresholdPlaceholder: 'Enter percentage',
|
||||
|
||||
@@ -2249,7 +2249,7 @@ export default {
|
||||
quotaLimitAmount: '总限额',
|
||||
quotaLimitAmountHint: '累计消费上限,不会自动重置。',
|
||||
quotaNotify: {
|
||||
alert: '告警阈值',
|
||||
alert: '提醒阈值',
|
||||
enabled: '启用告警',
|
||||
threshold: '告警金额',
|
||||
thresholdPlaceholder: '输入百分比',
|
||||
|
||||
Reference in New Issue
Block a user