From f5ed562ea9bc1f885db0cc7d0455c3ac65890cbd Mon Sep 17 00:00:00 2001 From: lelo Date: Tue, 1 Apr 2025 22:03:52 +0200 Subject: [PATCH] replace today with last 24 hours --- analytics.py | 12 ++++++------ templates/dashboard.html | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/analytics.py b/analytics.py index 24981fe..51f3ab4 100644 --- a/analytics.py +++ b/analytics.py @@ -95,7 +95,7 @@ def connections(): @require_secret def dashboard(): filetype_arg = request.args.get('filetype', 'audio') - timeframe = request.args.get('timeframe', 'today') + timeframe = request.args.get('timeframe', 'last24hours') now = datetime.now() # Determine which file type we're filtering by. @@ -114,8 +114,8 @@ def dashboard(): filetype = 'video/' # Determine start time based on timeframe - if timeframe == 'today': - start_dt = now.replace(hour=0, minute=0, second=0, microsecond=0) + if timeframe == 'last24hours': + start_dt = now - timedelta(hours=24) elif timeframe == '7days': start_dt = now - timedelta(days=7) elif timeframe == '30days': @@ -123,7 +123,7 @@ def dashboard(): elif timeframe == '365days': start_dt = now - timedelta(days=365) else: - start_dt = now.replace(hour=0, minute=0, second=0, microsecond=0) + start_dt = now - timedelta(hours=24) # We'll compare the textual timestamp (ISO 8601). start_str = start_dt.isoformat() @@ -157,7 +157,7 @@ def dashboard(): # 2. Distinct device trend # We'll group by hour if "today", by day if "7days"/"30days", by month if "365days" - if timeframe == 'today': + if timeframe == 'last24hours': # Group by hour: substr(timestamp, 12, 2) -> HH query = f''' SELECT substr(timestamp, 12, 2) AS bucket, COUNT(DISTINCT device_id) AS count @@ -202,7 +202,7 @@ def dashboard(): # 3. Timeframe-based aggregation # We'll group by hour if "today", by day if "7days"/"30days", by month if "365days". - if timeframe == 'today': + if timeframe == 'last24hours': # Hour: substr(timestamp, 12, 2) -> HH query = f''' SELECT substr(timestamp, 12, 2) AS bucket, COUNT(*) AS count diff --git a/templates/dashboard.html b/templates/dashboard.html index 7dee0bd..933caca 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -30,7 +30,7 @@ Auswertung
- Today + Last 24 Hours Last 7 Days Last 30 Days Last 365 Days @@ -177,10 +177,10 @@ const folderData = {{ folder_data|tojson }}; // shift the labels to local time zone - const timeframe = "{{ timeframe }}"; // e.g., 'today', '7days', '30days', or '365days' + const timeframe = "{{ timeframe }}"; // e.g., 'last24hours', '7days', '30days', or '365days' const shiftedLabels = timeframeData.map(item => { - if (timeframe === 'today') { - // For "today", the bucket is an hour in UTC (e.g., "14") + if (timeframe === 'last24hours') { + // For 'last24hours', the bucket is an hour in UTC (e.g., "14") const utcHour = parseInt(item.bucket, 10); const now = new Date(); // Create Date objects for the start and end of the hour in UTC @@ -234,7 +234,7 @@ } }); - // Timeframe Breakdown Chart - Bar Chart (for "today" timeframe) + // Timeframe Breakdown Chart - Bar Chart (for 'last24hours' timeframe) const ctxTimeframe = document.getElementById('downloadTimeframeChart').getContext('2d'); new Chart(ctxTimeframe, { type: 'bar',