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
32 lines
778 B
Plaintext
32 lines
778 B
Plaintext
"""获取当天排名前三的模型数量和金额"""
|
|
# datetime, json, DBPools 由 ahserver 预加载,无需 import
|
|
|
|
today = datetime.date.today().isoformat()
|
|
|
|
sql = """
|
|
SELECT
|
|
b.name as model_name,
|
|
COUNT(*) as cnt,
|
|
COALESCE(SUM(a.amount), 0) as total_amount
|
|
FROM llmusage a
|
|
LEFT JOIN llm b ON a.llmid = b.id
|
|
WHERE a.use_date = ${today}$
|
|
GROUP BY a.llmid, b.name
|
|
ORDER BY cnt DESC
|
|
LIMIT 3
|
|
"""
|
|
|
|
db = DBPools()
|
|
async with db.sqlorContext('sage') as sor:
|
|
recs = await sor.sqlExe(sql, {'today': today})
|
|
result = []
|
|
for r in recs:
|
|
result.append({
|
|
'model_name': r.get('model_name', 'Unknown'),
|
|
'cnt': int(r.get('cnt', 0)),
|
|
'total_amount': float(r.get('total_amount', 0))
|
|
})
|
|
return result
|
|
|
|
return []
|