diff --git a/analytics.py b/analytics.py index 203441d..9bd6475 100644 --- a/analytics.py +++ b/analytics.py @@ -123,16 +123,44 @@ def dashboard(): ''', (start.isoformat(),)) daily_access_data = [dict(date=row[0], count=row[1]) for row in cursor.fetchall()] - # Top files for bar chart - cursor.execute(''' - SELECT rel_path, COUNT(*) as access_count - FROM file_access_log - WHERE timestamp >= ? - GROUP BY rel_path - ORDER BY access_count DESC - LIMIT 10 - ''', (start.isoformat(),)) - top_files_data = [dict(rel_path=row[0], access_count=row[1]) for row in cursor.fetchall()] + # Aggregate download counts by time bucket according to the timeframe. + if timeframe == 'today': + # Group by hour (0-23) + cursor.execute(''' + SELECT strftime('%H', timestamp) as bucket, COUNT(*) as count + FROM file_access_log + WHERE timestamp >= ? + GROUP BY bucket + ORDER BY bucket + ''', (start.isoformat(),)) + elif timeframe in ('7days', '30days'): + # Group by day (YYYY-MM-DD) + cursor.execute(''' + SELECT date(timestamp) as bucket, COUNT(*) as count + FROM file_access_log + WHERE timestamp >= ? + GROUP BY bucket + ORDER BY bucket + ''', (start.isoformat(),)) + elif timeframe == '365days': + # Group by month (YYYY-MM) + cursor.execute(''' + SELECT strftime('%Y-%m', timestamp) as bucket, COUNT(*) as count + FROM file_access_log + WHERE timestamp >= ? + GROUP BY bucket + ORDER BY bucket + ''', (start.isoformat(),)) + else: + # Fallback: group by day + cursor.execute(''' + SELECT date(timestamp) as bucket, COUNT(*) as count + FROM file_access_log + WHERE timestamp >= ? + GROUP BY bucket + ORDER BY bucket + ''', (start.isoformat(),)) + timeframe_data = [dict(bucket=row[0], count=row[1]) for row in cursor.fetchall()] # User agent distribution (aggregate by device type) cursor.execute(''' @@ -224,10 +252,10 @@ def dashboard(): timeframe=timeframe, rows=rows, daily_access_data=daily_access_data, - top_files_data=top_files_data, user_agent_data=user_agent_data, folder_data=folder_data, location_data=location_data, total_accesses=total_accesses, unique_files=unique_files, - unique_user=unique_user) \ No newline at end of file + unique_user=unique_user, + timeframe_data=timeframe_data) \ No newline at end of file diff --git a/templates/dashboard.html b/templates/dashboard.html index eb7b7ec..2aa2175 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -75,12 +75,12 @@ - +
-
Häufig geladene Dateien
- +
Downloads nach Zeit
+
@@ -171,11 +171,41 @@