Feature: KI-Nutzung im Admin mit 30-Tage-Sparkline + Top-Nutzer-Tabelle — SW by-v486, APP_VER 463
This commit is contained in:
parent
392359df45
commit
dc737d0c48
4 changed files with 109 additions and 32 deletions
|
|
@ -534,6 +534,40 @@ async def scheduler_trigger(job_id: str, user=Depends(require_admin)):
|
|||
return {"ok": True, "job_id": job_id}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /api/admin/ki/history — 30-Tage-Verlauf + Top-User (all-time)
|
||||
# ------------------------------------------------------------------
|
||||
@router.get("/ki/history")
|
||||
async def ki_history(user=Depends(require_mod)):
|
||||
with db() as conn:
|
||||
daily = conn.execute("""
|
||||
SELECT date,
|
||||
SUM(count) AS total,
|
||||
SUM(CASE WHEN source='cloud' THEN count ELSE 0 END) AS cloud,
|
||||
SUM(CASE WHEN source='local' THEN count ELSE 0 END) AS local,
|
||||
SUM(CASE WHEN source='luna' THEN count ELSE 0 END) AS luna
|
||||
FROM ki_daily_calls
|
||||
WHERE date >= DATE('now', '-29 days')
|
||||
GROUP BY date ORDER BY date ASC
|
||||
""").fetchall()
|
||||
top_users = conn.execute("""
|
||||
SELECT u.name, u.email,
|
||||
SUM(k.count) AS total,
|
||||
SUM(CASE WHEN k.source='cloud' THEN k.count ELSE 0 END) AS cloud,
|
||||
MAX(k.date) AS last_date
|
||||
FROM ki_daily_calls k JOIN users u ON u.id = k.user_id
|
||||
GROUP BY k.user_id ORDER BY total DESC LIMIT 15
|
||||
""").fetchall()
|
||||
return {
|
||||
"daily_history": [{"date": r["date"], "total": r["total"],
|
||||
"cloud": r["cloud"], "local": r["local"], "luna": r["luna"]}
|
||||
for r in daily],
|
||||
"top_users": [{"name": r["name"], "email": r["email"],
|
||||
"total": r["total"], "cloud": r["cloud"], "last_date": r["last_date"]}
|
||||
for r in top_users],
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# GET /api/admin/ki/status — lokale LLM-Erreichbarkeit prüfen
|
||||
# ------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue