Feature: ORS-Stats im Admin-Panel — Tagesverbrauch/2000, 30-Tage-Sparkline, Top-Nutzer — SW by-v485, APP_VER 462
This commit is contained in:
parent
69140a261e
commit
392359df45
6 changed files with 170 additions and 3 deletions
|
|
@ -853,6 +853,54 @@ async def admin_delete_zuchter(zuchter_id: int, user=Depends(require_mod)):
|
|||
# ------------------------------------------------------------------
|
||||
# POST /api/admin/media/generate-previews — Previews für Bestandsmedien
|
||||
# ------------------------------------------------------------------
|
||||
@router.get("/ors/stats")
|
||||
async def ors_stats(user=Depends(require_mod)):
|
||||
"""ORS-Routenvorschlag Statistiken für Admin-Panel."""
|
||||
with db() as conn:
|
||||
# Heute
|
||||
today = __import__('datetime').date.today().isoformat()
|
||||
today_row = conn.execute(
|
||||
"SELECT COALESCE(count,0) as count FROM ors_daily_total WHERE date=?", (today,)
|
||||
).fetchone()
|
||||
today_count = today_row["count"] if today_row else 0
|
||||
|
||||
# Letzte 30 Tage (Verlauf)
|
||||
daily_history = conn.execute("""
|
||||
SELECT date, count FROM ors_daily_total
|
||||
WHERE date >= DATE('now', '-29 days')
|
||||
ORDER BY date ASC
|
||||
""").fetchall()
|
||||
|
||||
# Letzte 8 Wochen (Wochensummen aus route_suggest_usage)
|
||||
weekly_totals = conn.execute("""
|
||||
SELECT week, SUM(count) as count
|
||||
FROM route_suggest_usage
|
||||
WHERE week >= DATE('now', '-56 days')
|
||||
GROUP BY week ORDER BY week ASC
|
||||
""").fetchall()
|
||||
|
||||
# Top-Nutzer (alle Zeiten)
|
||||
top_users = conn.execute("""
|
||||
SELECT u.name, u.email,
|
||||
SUM(r.count) as total,
|
||||
MAX(r.week) as last_week
|
||||
FROM route_suggest_usage r
|
||||
JOIN users u ON u.id = r.user_id
|
||||
GROUP BY r.user_id
|
||||
ORDER BY total DESC
|
||||
LIMIT 15
|
||||
""").fetchall()
|
||||
|
||||
return {
|
||||
"today_count": today_count,
|
||||
"today_limit": 2000,
|
||||
"daily_history": [{"date": r["date"], "count": r["count"]} for r in daily_history],
|
||||
"weekly_totals": [{"week": r["week"], "count": r["count"]} for r in weekly_totals],
|
||||
"top_users": [{"name": r["name"], "email": r["email"],
|
||||
"total": r["total"], "last_week": r["last_week"]} for r in top_users],
|
||||
}
|
||||
|
||||
|
||||
@router.post("/media/generate-previews")
|
||||
async def generate_media_previews(user=Depends(require_admin)):
|
||||
"""Generiert fehlende _preview.jpg für alle Bilder in /data/media."""
|
||||
|
|
|
|||
|
|
@ -283,6 +283,14 @@ async def suggest_route(data: SuggestRequest, user=Depends(get_current_user)):
|
|||
""", (user["id"], week_start))
|
||||
current_count += 1
|
||||
|
||||
# Täglichen Gesamtzähler hochzählen (für Admin-Stats)
|
||||
today_str = _dt.date.today().isoformat()
|
||||
with db() as conn:
|
||||
conn.execute("""
|
||||
INSERT INTO ors_daily_total (date, count) VALUES (?, 1)
|
||||
ON CONFLICT(date) DO UPDATE SET count = count + 1
|
||||
""", (today_str,))
|
||||
|
||||
weekly_remaining = None if is_privileged else max(0, WEEKLY_LIMIT - current_count)
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue