Compare commits
3 Commits
15c2bd6a1b
...
7c39b54215
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c39b54215 | |||
| 9971671688 | |||
| bdb4710f0c |
103
analytics.py
103
analytics.py
@ -12,11 +12,8 @@ file_access_temp = []
|
||||
|
||||
app_config = auth.return_app_config()
|
||||
|
||||
# Example database name; you can change to whatever you want:
|
||||
DB_NAME = 'access_log.db'
|
||||
|
||||
# Create a single global connection to SQLite
|
||||
log_db = sqlite3.connect(DB_NAME, check_same_thread=False)
|
||||
log_db = sqlite3.connect("access_log.db", check_same_thread=False)
|
||||
search_db = sqlite3.connect("search.db", check_same_thread=False)
|
||||
|
||||
# geo location
|
||||
@ -144,6 +141,7 @@ def return_file_access():
|
||||
return []
|
||||
|
||||
def songs_dashboard():
|
||||
# — SESSION & PARAM HANDLING (unchanged) —
|
||||
if 'songs_dashboard_timeframe' not in session:
|
||||
session['songs_dashboard_timeframe'] = "30"
|
||||
timeframe_param = request.args.get("timeframe", session['songs_dashboard_timeframe'])
|
||||
@ -159,50 +157,73 @@ def songs_dashboard():
|
||||
site = request.args.get("site", session['songs_dashboard_site'])
|
||||
session['songs_dashboard_site'] = site
|
||||
|
||||
# Determine cutoff_date based on the days parameter
|
||||
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(timeframe_param)
|
||||
now = datetime.now()
|
||||
cutoff_date = now - timedelta(days=timeframe)
|
||||
# — DETERMINE CUTOFF + TODAY STRINGS —
|
||||
now = datetime.now()
|
||||
params = [category, site]
|
||||
date_clauses = []
|
||||
if timeframe_param != "all":
|
||||
cutoff = now - timedelta(days=int(timeframe_param))
|
||||
date_clauses.append("performance_date >= ?")
|
||||
params.append(cutoff.strftime("%Y-%m-%d"))
|
||||
# filter out any future-dated rows at the DB level
|
||||
date_clauses.append("performance_date <= ?")
|
||||
params.append(now.strftime("%Y-%m-%d"))
|
||||
|
||||
where_sql = " AND ".join(["category = ?", "site = ?"] + date_clauses)
|
||||
|
||||
cursor = search_db.cursor()
|
||||
# Query rows with category "Gemeinsamer Gesang"
|
||||
query = "SELECT titel, performance_date FROM files WHERE category = ? and site = ?"
|
||||
cursor.execute(query, (category, site))
|
||||
cursor.execute(
|
||||
f"SELECT titel, performance_date FROM files WHERE {where_sql}",
|
||||
params
|
||||
)
|
||||
rows = cursor.fetchall()
|
||||
|
||||
# Group and count performances per titel (only if performance_date is within the timeframe,
|
||||
# or count all if cutoff_date is None)
|
||||
performance_counts = defaultdict(int)
|
||||
for titel, performance_date in rows:
|
||||
if performance_date:
|
||||
try:
|
||||
# Convert date from "dd.mm.yyyy" format
|
||||
date_obj = datetime.strptime(performance_date, "%d.%m.%Y")
|
||||
except ValueError:
|
||||
continue
|
||||
# If cutoff_date is None, count all dates; otherwise, filter by cutoff_date.
|
||||
if cutoff_date is None or date_obj >= cutoff_date:
|
||||
performance_counts[titel] += 1
|
||||
# — AGGREGATE COUNTS + LAST-PERFORMED, WITH ERROR LOGGING —
|
||||
performance_counts = defaultdict(int)
|
||||
last_performed_dates = {}
|
||||
|
||||
# Create a list of tuples: (count, titel), sorted in descending order by count.
|
||||
performance_data = [(count, titel) for titel, count in performance_counts.items()]
|
||||
performance_data.sort(reverse=True, key=lambda x: x[0])
|
||||
for titel, perf_date_str in rows:
|
||||
if not perf_date_str:
|
||||
continue
|
||||
|
||||
perf_date_str = perf_date_str.strip()
|
||||
try:
|
||||
perf_date = datetime.strptime(perf_date_str, "%Y-%m-%d")
|
||||
except ValueError:
|
||||
print(f"[songs_dashboard] bad date format for “{titel}”: “{perf_date_str}”")
|
||||
continue
|
||||
|
||||
performance_counts[titel] += 1
|
||||
|
||||
prev = last_performed_dates.get(titel)
|
||||
if prev is None or perf_date > prev:
|
||||
last_performed_dates[titel] = perf_date
|
||||
|
||||
# — BUILD LIST FOR TEMPLATE —
|
||||
performance_data = []
|
||||
for titel, count in performance_counts.items():
|
||||
last_str = last_performed_dates[titel].strftime("%d.%m.%Y")
|
||||
performance_data.append({
|
||||
"titel": titel,
|
||||
"count": count,
|
||||
"last_performed": last_str
|
||||
})
|
||||
|
||||
performance_data.sort(key=lambda x: x["count"], reverse=True)
|
||||
|
||||
# — RENDER —
|
||||
return render_template(
|
||||
'songs_dashboard.html',
|
||||
timeframe=timeframe_param,
|
||||
performance_data=performance_data,
|
||||
site=site,
|
||||
category=category,
|
||||
admin_enabled=auth.is_admin(),
|
||||
title_short=app_config.get('TITLE_SHORT', 'Default Title'),
|
||||
title_long= app_config.get('TITLE_LONG', 'Default Title'),
|
||||
)
|
||||
|
||||
title_short = app_config.get('TITLE_SHORT', 'Default Title')
|
||||
title_long = app_config.get('TITLE_LONG' , 'Default Title')
|
||||
|
||||
return render_template('songs_dashboard.html',
|
||||
timeframe=timeframe_param,
|
||||
performance_data=performance_data,
|
||||
site=site,
|
||||
category=category,
|
||||
admin_enabled=auth.is_admin(),
|
||||
title_short=title_short,
|
||||
title_long=title_long)
|
||||
|
||||
@require_secret
|
||||
def connections():
|
||||
|
||||
@ -41,9 +41,9 @@
|
||||
<span> | </span>
|
||||
<a href="{{ url_for('connections') }}">Verbindungen</a>
|
||||
<span> | </span>
|
||||
<a href="{{ url_for('dashboard') }}">Auswertung-Downloads</a>
|
||||
<a href="{{ url_for('dashboard') }}">Dashbord</a>
|
||||
<span> | </span>
|
||||
<a href="{{ url_for('songs_dashboard') }}">Auswertung-Wiederholungen</a>
|
||||
<a href="{{ url_for('songs_dashboard') }}">Wiederholungen</a>
|
||||
{% if admin_enabled %}
|
||||
<span> | </span>
|
||||
<a href="{{ url_for('folder_secret_config_editor') }}" id="edit-folder-config">Ordnerkonfiguration</a>
|
||||
|
||||
@ -6,8 +6,10 @@
|
||||
|
||||
{# page‐specific content #}
|
||||
{% block content %}
|
||||
|
||||
<!-- Main Container -->
|
||||
<div class="container">
|
||||
<h2>Übersicht deiner gültigen Links</h2>
|
||||
<h2>Übersicht deiner Links</h2>
|
||||
<div class="row">
|
||||
{% if valid_secrets %}
|
||||
{% for secret in valid_secrets %}
|
||||
@ -17,7 +19,7 @@
|
||||
class="card-img-top qr-code p-3"
|
||||
alt="QR Code for secret">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Geheimnis: {{ secret }}</h5>
|
||||
<h5 class="card-title">Secret Link:</h5>
|
||||
<p class="card-text">
|
||||
<small class="text-muted">Gültig bis: {{ secret_valid_to[secret] }}</small>
|
||||
</p>
|
||||
@ -29,16 +31,14 @@
|
||||
<button type="submit" class="btn btn-danger btn-sm">Link entfernen</button>
|
||||
</form>
|
||||
{% if secret_folders[secret] %}
|
||||
<h6 class="mt-3">Ordner</h6>
|
||||
<ul class="list-group list-group-flush">
|
||||
<h5 class="mt-3">Ordner:</h5>
|
||||
<div class="list-group">
|
||||
{% for folder in secret_folders[secret] %}
|
||||
<li class="list-group-item">
|
||||
<strong>{{ folder.foldername }}</strong>
|
||||
</li>
|
||||
<a class="btn btn-outline-secondary" style="margin: 5px;" href="/path/{{ folder.foldername }}">{{ folder.foldername }}</a>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted">Keine Ordner für dieses Gemeimnis hinterlegt.</p>
|
||||
<p class="text-muted">Keine Ordner für dieses Secret hinterlegt.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@ -66,16 +66,14 @@
|
||||
<button type="submit" class="btn btn-danger btn-sm">Link entfernen</button>
|
||||
</form>
|
||||
{% if token_folders[token] %}
|
||||
<h6 class="mt-3">Ordner</h6>
|
||||
<ul class="list-group list-group-flush">
|
||||
<h5 class="mt-3">Ordner:</h5>
|
||||
<div class="list-group">
|
||||
{% for folder in token_folders[token] %}
|
||||
<li class="list-group-item">
|
||||
<strong>{{ folder.foldername }}</strong>
|
||||
</li>
|
||||
<a class="btn btn-outline-secondary" style="margin: 5px;" href="/path/{{ folder.foldername }}">{{ folder.foldername }}</a>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted">Keine Ordner für dieses Gemeimnis hinterlegt.</p>
|
||||
<p class="text-muted">Keine Ordner für diesen Token hinterlegt.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -7,147 +7,146 @@
|
||||
{# page content #}
|
||||
{% block content %}
|
||||
|
||||
<!-- Main Container -->
|
||||
<div class="container-fluid px-4">
|
||||
<h2>Analyse Wiederholungen</h2>
|
||||
<!-- Dropdown Controls -->
|
||||
<div class="mb-4 d-flex flex-wrap gap-2">
|
||||
<!-- Main Container -->
|
||||
<div class="container-fluid px-4">
|
||||
<h2>Analyse Wiederholungen</h2>
|
||||
<!-- Dropdown Controls -->
|
||||
<div class="mb-4 d-flex flex-wrap gap-2">
|
||||
<!-- Site Dropdown -->
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle"
|
||||
type="button" id="siteDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{% if session['songs_dashboard_site'] == 'Speyer' %}
|
||||
Speyer
|
||||
{% elif session['songs_dashboard_site'] == 'Schwegenheim' %}
|
||||
Schwegenheim
|
||||
{% else %}
|
||||
Select Site
|
||||
{% endif %}
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="siteDropdown">
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_site'] == 'Speyer' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', site='Speyer') }}">
|
||||
Speyer
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_site'] == 'Schwegenheim' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', site='Schwegenheim') }}">
|
||||
Schwegenheim
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Site Dropdown -->
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle"
|
||||
type="button" id="siteDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{% if session['songs_dashboard_site'] == 'Speyer' %}
|
||||
Speyer
|
||||
{% elif session['songs_dashboard_site'] == 'Schwegenheim' %}
|
||||
Schwegenheim
|
||||
{% else %}
|
||||
Select Site
|
||||
{% endif %}
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="siteDropdown">
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_site'] == 'Speyer' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', site='Speyer') }}">
|
||||
Speyer
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_site'] == 'Schwegenheim' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', site='Schwegenheim') }}">
|
||||
Schwegenheim
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- Timeframe Dropdown -->
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle"
|
||||
type="button" id="timeframeDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{% if session['songs_dashboard_timeframe'] == '7' %}
|
||||
Last 7 Days
|
||||
{% elif session['songs_dashboard_timeframe'] == '30' %}
|
||||
Last 30 Days
|
||||
{% elif session['songs_dashboard_timeframe'] == '90' %}
|
||||
Last 90 Days
|
||||
{% elif session['songs_dashboard_timeframe'] == '365' %}
|
||||
Last 365 Days
|
||||
{% elif session['songs_dashboard_timeframe'] == 'all' %}
|
||||
All Data
|
||||
{% else %}
|
||||
Select Timeframe
|
||||
{% endif %}
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="timeframeDropdown">
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == '7' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='7') }}">
|
||||
Last 7 Days
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == '30' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='30') }}">
|
||||
Last 30 Days
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == '90' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='90') }}">
|
||||
Last 90 Days
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == '365' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='365') }}">
|
||||
Last 365 Days
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == 'all' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='all') }}">
|
||||
All Data
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Timeframe Dropdown -->
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle"
|
||||
type="button" id="timeframeDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{% if session['songs_dashboard_timeframe'] == '7' %}
|
||||
Last 7 Days
|
||||
{% elif session['songs_dashboard_timeframe'] == '30' %}
|
||||
Last 30 Days
|
||||
{% elif session['songs_dashboard_timeframe'] == '90' %}
|
||||
Last 90 Days
|
||||
{% elif session['songs_dashboard_timeframe'] == '365' %}
|
||||
Last 365 Days
|
||||
{% elif session['songs_dashboard_timeframe'] == 'all' %}
|
||||
All Data
|
||||
{% else %}
|
||||
Select Timeframe
|
||||
{% endif %}
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="timeframeDropdown">
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == '7' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='7') }}">
|
||||
Last 7 Days
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == '30' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='30') }}">
|
||||
Last 30 Days
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == '90' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='90') }}">
|
||||
Last 90 Days
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == '365' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='365') }}">
|
||||
Last 365 Days
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_timeframe'] == 'all' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', timeframe='all') }}">
|
||||
All Data
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- category Dropdown -->
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="categoryDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{% if session['songs_dashboard_category'] == 'Gemeinsamer Gesang' %}
|
||||
<!-- category Dropdown -->
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="categoryDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{% if session['songs_dashboard_category'] == 'Gemeinsamer Gesang' %}
|
||||
Gemeinsamer Gesang
|
||||
{% elif session['songs_dashboard_category'] == 'Chor' %}
|
||||
Chor
|
||||
{% elif session['songs_dashboard_category'] == 'Gruppenlied' %}
|
||||
Gruppenlied
|
||||
{% else %}
|
||||
Select Category
|
||||
{% endif %}
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="categoryDropdown">
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_category'] == 'Gemeinsamer Gesang' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', category='Gemeinsamer Gesang') }}">
|
||||
Gemeinsamer Gesang
|
||||
{% elif session['songs_dashboard_category'] == 'Chor' %}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_category'] == 'Chor' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', category='Chor') }}">
|
||||
Chor
|
||||
{% elif session['songs_dashboard_category'] == 'Gruppenlied' %}
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_category'] == 'Gruppenlied' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', category='Gruppenlied') }}">
|
||||
Gruppenlied
|
||||
{% else %}
|
||||
Select Category
|
||||
{% endif %}
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="categoryDropdown">
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_category'] == 'Gemeinsamer Gesang' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', category='Gemeinsamer Gesang') }}">
|
||||
Gemeinsamer Gesang
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_category'] == 'Chor' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', category='Chor') }}">
|
||||
Chor
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="dropdown-item {% if session['songs_dashboard_category'] == 'Gruppenlied' %}active{% endif %}"
|
||||
href="{{ url_for('songs_dashboard', category='Gruppenlied') }}">
|
||||
Gruppenlied
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Table Output -->
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Anzahl</th>
|
||||
<th>Titel</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for count, titel in performance_data %}
|
||||
<tr>
|
||||
<td>{{ count }}</td>
|
||||
<td>{{ titel }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<!-- Table Output -->
|
||||
<table class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Anzahl</th>
|
||||
<th>Titel</th>
|
||||
<th>Zuletzt gesungen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for item in performance_data %}
|
||||
<tr>
|
||||
<td>{{ item['count'] }}</td>
|
||||
<td>{{ item['titel'] }}</td>
|
||||
<td>{{ item['last_performed'] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
Loading…
x
Reference in New Issue
Block a user