feat: Enhance activity listing and statistics retrieval with pagination and quality filter options
- Added pagination support to the activity listing endpoint with `limit` and `offset` parameters. - Introduced a `skip_quality_filter` option to allow retrieval of all entries without applying the quality filter. - Updated the frontend to implement dynamic loading of activity entries and statistics without the quality filter. - Improved user experience with a "Load More" button for fetching additional entries on the ActivityPage.
This commit is contained in:
1 parent
766b64cd64
commit
1f51c32521
3 files changed
+108
-22
No files matched your search
+29
-12
@@ -35,7 +35,12 @@ except Exception as e:
|
||||
@router.get("")
|
||||
def list_activity(
|
||||
limit: int = Query(200, ge=1, le=50_000),
|
||||
offset: int = Query(0, ge=0, le=100_000, description="SQL OFFSET für Pagination"),
|
||||
days: Optional[int] = Query(None, ge=1, le=4000, description="Nur Einträge mit date >= HEUTE − days (Kalendertage)"),
|
||||
skip_quality_filter: bool = Query(
|
||||
False,
|
||||
description="True = alle Einträge des Profils (ohne quality_label-Filter). Für /activity Erfassung.",
|
||||
),
|
||||
session: dict = Depends(require_auth),
|
||||
):
|
||||
"""Get activity entries for current profile. Optional *days* filter by calendar window (not the same as *limit*)."""
|
||||
@@ -44,10 +49,13 @@ def list_activity(
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
|
||||
# Issue #31: Apply global quality filter (profile from DB = saved level)
|
||||
cur.execute("SELECT * FROM profiles WHERE id=%s", (pid,))
|
||||
profile = r2d(cur.fetchone())
|
||||
quality_filter = get_quality_filter_sql(profile or {})
|
||||
# Issue #31: Qualitätsfilter — auf der Erfassungsseite /activity abschaltbar (skip_quality_filter)
|
||||
if skip_quality_filter:
|
||||
quality_filter = ""
|
||||
else:
|
||||
cur.execute("SELECT * FROM profiles WHERE id=%s", (pid,))
|
||||
profile = r2d(cur.fetchone())
|
||||
quality_filter = get_quality_filter_sql(profile or {})
|
||||
|
||||
if days is not None:
|
||||
cur.execute(
|
||||
@@ -57,9 +65,9 @@ def list_activity(
|
||||
{quality_filter}
|
||||
AND date >= (CURRENT_DATE - %s::integer)
|
||||
ORDER BY date DESC, start_time DESC
|
||||
LIMIT %s
|
||||
LIMIT %s OFFSET %s
|
||||
""",
|
||||
(pid, days, limit),
|
||||
(pid, days, limit, offset),
|
||||
)
|
||||
else:
|
||||
cur.execute(
|
||||
@@ -68,9 +76,9 @@ def list_activity(
|
||||
WHERE profile_id=%s
|
||||
{quality_filter}
|
||||
ORDER BY date DESC, start_time DESC
|
||||
LIMIT %s
|
||||
LIMIT %s OFFSET %s
|
||||
""",
|
||||
(pid, limit),
|
||||
(pid, limit, offset),
|
||||
)
|
||||
return [r2d(r) for r in cur.fetchall()]
|
||||
|
||||
@@ -167,14 +175,23 @@ def create_activity(e: ActivityEntry, x_profile_id: Optional[str]=Header(default
|
||||
|
||||
|
||||
@router.get("/stats")
|
||||
def activity_stats(session: dict = Depends(require_auth)):
|
||||
def activity_stats(
|
||||
skip_quality_filter: bool = Query(
|
||||
False,
|
||||
description="True = Statistik-Kacheln ohne Profil-Qualitätsfilter (passend zur /activity-Liste).",
|
||||
),
|
||||
session: dict = Depends(require_auth),
|
||||
):
|
||||
"""Get activity statistics (last 30 entries)."""
|
||||
pid = str(session["profile_id"])
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("SELECT * FROM profiles WHERE id=%s", (pid,))
|
||||
profile = r2d(cur.fetchone())
|
||||
quality_filter = get_quality_filter_sql(profile or {})
|
||||
if skip_quality_filter:
|
||||
quality_filter = ""
|
||||
else:
|
||||
cur.execute("SELECT * FROM profiles WHERE id=%s", (pid,))
|
||||
profile = r2d(cur.fetchone())
|
||||
quality_filter = get_quality_filter_sql(profile or {})
|
||||
cur.execute(
|
||||
f"""
|
||||
SELECT * FROM activity_log
|
||||
|
||||
Reference in new issue
Block a user