From 1822fc20cb56d76146b833c5efdee122eaab3e0f Mon Sep 17 00:00:00 2001 From: lelo Date: Sat, 12 Apr 2025 19:49:53 +0000 Subject: [PATCH] improve song analytics --- analytics.py | 24 +++- templates/connections.html | 17 +-- templates/dashboard.html | 5 +- templates/mylinks.html | 3 +- templates/songs_dashboard.html | 218 ++++++++++++++++++++++++++------- 5 files changed, 203 insertions(+), 64 deletions(-) diff --git a/analytics.py b/analytics.py index 145d7b1..49a8a71 100644 --- a/analytics.py +++ b/analytics.py @@ -141,22 +141,34 @@ def return_file_access(): return [] def songs_dashboard(): - days_param = request.args.get("days", "30") - site = str(request.args.get("site", "Speyer")) + if 'songs_dashboard_timeframe' not in session: + session['songs_dashboard_timeframe'] = "30" + timeframe_param = request.args.get("timeframe", session['songs_dashboard_timeframe']) + session['songs_dashboard_timeframe'] = timeframe_param + + if 'songs_dashboard_category' not in session: + session['songs_dashboard_category'] = "Gemeinsamer Gesang" + category = request.args.get("category", session['songs_dashboard_category']) + session['songs_dashboard_category'] = category + + if 'songs_dashboard_site' not in session: + session['songs_dashboard_site'] = "Speyer" + site = request.args.get("site", session['songs_dashboard_site']) + session['songs_dashboard_site'] = site # Determine cutoff_date based on the days parameter - if days_param == "all": + if timeframe_param == "all": cutoff_date = None # No date filtering when analyzing all time timeframe = "all" # Pass the string to the template if needed else: - timeframe = int(days_param) + timeframe = int(timeframe_param) now = datetime.now() cutoff_date = now - timedelta(days=timeframe) cursor = search_db.cursor() # Query rows with category "Gemeinsamer Gesang" query = "SELECT titel, performance_date FROM files WHERE category = ? and site = ?" - cursor.execute(query, ('Gemeinsamer Gesang', site)) + cursor.execute(query, (category, site)) rows = cursor.fetchall() # Group and count performances per titel (only if performance_date is within the timeframe, @@ -177,7 +189,7 @@ def songs_dashboard(): performance_data = [(count, titel) for titel, count in performance_counts.items()] performance_data.sort(reverse=True, key=lambda x: x[0]) - return render_template('songs_dashboard.html', timeframe=timeframe, performance_data=performance_data, site=site) + return render_template('songs_dashboard.html', timeframe=timeframe_param, performance_data=performance_data, site=site, category=category) @require_secret def connections(): diff --git a/templates/connections.html b/templates/connections.html index ad0e15d..be84e10 100644 --- a/templates/connections.html +++ b/templates/connections.html @@ -67,18 +67,11 @@ Downloads der letzten 10 Minuten diff --git a/templates/dashboard.html b/templates/dashboard.html index e22f2a5..edfa580 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -31,7 +31,8 @@ - + + @@ -272,8 +273,8 @@ - +