From 7e26af5476cb56e819dbfaebee50b1710ef4d28d Mon Sep 17 00:00:00 2001 From: fawney19 Date: Mon, 29 Dec 2025 18:12:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=BB=AA=E8=A1=A8?= =?UTF-8?q?=E7=9B=98=E7=BC=93=E5=AD=98=E5=91=BD=E4=B8=AD=E7=8E=87=E5=92=8C?= =?UTF-8?q?=E9=85=8D=E9=A2=9D=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 本月缓存命中率改为使用本月数据计算(monthly_input_tokens + cache_read_tokens),而非全时数据 - 修复配额显示:有配额时显示实际金额,无配额时显示为 /bin/zsh 并标记为高警告状态 --- src/api/dashboard/routes.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/api/dashboard/routes.py b/src/api/dashboard/routes.py index 30af02d..006cb1d 100644 --- a/src/api/dashboard/routes.py +++ b/src/api/dashboard/routes.py @@ -541,13 +541,14 @@ class UserDashboardStatsAdapter(DashboardAdapter): ) cache_creation_tokens = int(cache_stats.cache_creation_tokens or 0) if cache_stats else 0 cache_read_tokens = int(cache_stats.cache_read_tokens or 0) if cache_stats else 0 + monthly_input_tokens = int(cache_stats.total_input_tokens or 0) if cache_stats else 0 - # 计算缓存命中率:cache_read / (input_tokens + cache_read) + # 计算本月缓存命中率:cache_read / (input_tokens + cache_read) # input_tokens 是实际发送给模型的输入(不含缓存读取),cache_read 是从缓存读取的 # 总输入 = input_tokens + cache_read,缓存命中率 = cache_read / 总输入 - total_input_with_cache = all_time_input_tokens + all_time_cache_read + total_input_with_cache = monthly_input_tokens + cache_read_tokens cache_hit_rate = ( - round((all_time_cache_read / total_input_with_cache) * 100, 1) + round((cache_read_tokens / total_input_with_cache) * 100, 1) if total_input_with_cache > 0 else 0 ) @@ -573,15 +574,15 @@ class UserDashboardStatsAdapter(DashboardAdapter): quota_value = "无限制" quota_change = f"已用 ${user.used_usd:.2f}" quota_high = False - elif user.quota_usd and user.quota_usd > 0: + elif user.quota_usd > 0: percent = min(100, int((user.used_usd / user.quota_usd) * 100)) - quota_value = "无限制" + quota_value = f"${user.quota_usd:.0f}" quota_change = f"已用 ${user.used_usd:.2f}" quota_high = percent > 80 else: - quota_value = "0%" + quota_value = "$0" quota_change = f"已用 ${user.used_usd:.2f}" - quota_high = False + quota_high = True return { "stats": [