Architecture: - index.ui: title + RefreshWidget(cards) + ChartBar with refresh_period - RefreshWidget wraps dashboard_cards.dspy → returns full card widget tree with live data (cnt, amount, total_users, concurrent_users) - ChartBar handles its own auto-refresh via refresh_period: 10 - No more JS polling file needed .dspy import fixes: - get_today_usage.dspy: remove import json, from datetime import date - get_user_stats.dspy: remove from datetime import datetime, timedelta - get_top_models.dspy: remove from datetime import date - All use pre-loaded datetime module (datetime.date.today(), etc.) - dashboard_cards.dspy: same pattern, no imports Permission: - load_path.py: add dashboard_cards.dspy logined
23 lines
587 B
Plaintext
23 lines
587 B
Plaintext
"""获取当天llmusage笔数和交易金额"""
|
|
# datetime, json, DBPools 由 ahserver 预加载,无需 import
|
|
|
|
today = datetime.date.today().isoformat()
|
|
|
|
sql = """
|
|
SELECT
|
|
COUNT(*) as cnt,
|
|
COALESCE(SUM(amount), 0) as total_amount
|
|
FROM llmusage
|
|
WHERE use_date = ${today}$
|
|
"""
|
|
|
|
db = DBPools()
|
|
async with db.sqlorContext('sage') as sor:
|
|
recs = await sor.sqlExe(sql, {'today': today})
|
|
if recs:
|
|
return {
|
|
'cnt': int(recs[0].get('cnt', 0)),
|
|
'total_amount': float(recs[0].get('total_amount', 0))
|
|
}
|
|
return {'cnt': 0, 'total_amount': 0}
|