replace today with last 24 hours
This commit is contained in:
parent
7daf2eea6e
commit
f5ed562ea9
12
analytics.py
12
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
|
||||
|
||||
@ -30,7 +30,7 @@
|
||||
<a href="{{ url_for('dashboard') }}" class="btn btn-primary mt-1">Auswertung</a>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<a href="{{ url_for('dashboard', timeframe='today') }}" class="btn btn-secondary btn-sm mt-1">Today</a>
|
||||
<a href="{{ url_for('dashboard', timeframe='last24hours') }}" class="btn btn-secondary btn-sm mt-1">Last 24 Hours</a>
|
||||
<a href="{{ url_for('dashboard', timeframe='7days') }}" class="btn btn-secondary btn-sm mt-1">Last 7 Days</a>
|
||||
<a href="{{ url_for('dashboard', timeframe='30days') }}" class="btn btn-secondary btn-sm mt-1">Last 30 Days</a>
|
||||
<a href="{{ url_for('dashboard', timeframe='365days') }}" class="btn btn-secondary btn-sm mt-1">Last 365 Days</a>
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user