From fabd127e6fe8e1a7897e9d8899f66ede2860ee27 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 24 May 2026 17:27:23 +0800 Subject: [PATCH] add accounting errors monitoring card (accounting_status='failed') --- dashboard_for_sage/load_dashboard.py | 12 +++++++++++ wwwroot/accounting_errors.ui | 32 ++++++++++++++++++++++++++++ wwwroot/index.ui | 8 +++++++ 3 files changed, 52 insertions(+) create mode 100644 wwwroot/accounting_errors.ui diff --git a/dashboard_for_sage/load_dashboard.py b/dashboard_for_sage/load_dashboard.py index e95f302..83aecc3 100644 --- a/dashboard_for_sage/load_dashboard.py +++ b/dashboard_for_sage/load_dashboard.py @@ -82,6 +82,17 @@ async def get_top_models(request): return result +async def get_accounting_errors(request): + """获取当天记账错误笔数(accounting_status='failed')""" + today = date.today().isoformat() + env = request._run_ns + async with get_sor_context(env, 'sage') as sor: + sql = "SELECT COUNT(*) as cnt FROM llmusage WHERE use_date = ${today}$ AND accounting_status = 'failed'" + recs = await sor.sqlExe(sql, {'today': today}) + cnt = int(recs[0].get('cnt', 0)) if recs else 0 + return cnt + + def load_dashboard(): """Register dashboard functions on ServerEnv""" g = ServerEnv() @@ -90,3 +101,4 @@ def load_dashboard(): g.get_total_users = get_total_users g.get_concurrent_users = get_concurrent_users g.get_top_models = get_top_models + g.get_accounting_errors = get_accounting_errors diff --git a/wwwroot/accounting_errors.ui b/wwwroot/accounting_errors.ui new file mode 100644 index 0000000..0f8f788 --- /dev/null +++ b/wwwroot/accounting_errors.ui @@ -0,0 +1,32 @@ +{ + "widgettype": "VBox", + "options": { + "bgcolor": "#FFFFFF", + "padding": "24px", + "borderRadius": "8px", + "flex": "1", + "minHeight": "120px", + "boxShadow": "0 2px 8px rgba(0,0,0,0.1)" + }, + "subwidgets": [ + { + "widgettype": "Text", + "options": { + "text": "记账错误笔数", + "fontSize": "14px", + "color": "#888", + "marginBottom": "8px" + } + }, + { + "widgettype": "Text", + "id": "accounting_errors_value", + "options": { + "text": "{{get_accounting_errors(request)}}", + "fontSize": "32px", + "fontWeight": "bold", + "color": "#ff4d4f" + } + } + ] +} diff --git a/wwwroot/index.ui b/wwwroot/index.ui index d1c7093..0bcd771 100644 --- a/wwwroot/index.ui +++ b/wwwroot/index.ui @@ -55,6 +55,14 @@ "period_seconds": 10, "url": "{{entire_url('concurrent_users.ui')}}" } + }, + { + "widgettype": "RefreshWidget", + "id": "refresh_accounting_errors", + "options": { + "period_seconds": 10, + "url": "{{entire_url('accounting_errors.ui')}}" + } } ] },