From cdbe6f057410b0035aa1b0b52ce01809bcfa8150 Mon Sep 17 00:00:00 2001 From: elpatron Date: Wed, 23 Jul 2025 11:12:53 +0200 Subject: [PATCH] =?UTF-8?q?README:=20Anleitung=20f=C3=BCr=20STATS=5FPASSWO?= =?UTF-8?q?RD=20und=20Dashboard=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 40 +++++++++++++++++++++++++- templates/stats_dashboard.html | 52 ++++++++++++++++++++++++++++++++++ templates/stats_login.html | 25 ++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 templates/stats_dashboard.html create mode 100644 templates/stats_login.html diff --git a/app.py b/app.py index f1469a7..d906a47 100644 --- a/app.py +++ b/app.py @@ -1,9 +1,11 @@ -from flask import Flask, render_template, request +from flask import Flask, render_template, request, redirect, url_for, session, abort from datetime import datetime, timedelta import numpy as np from dateutil.relativedelta import relativedelta +import os app = Flask(__name__) +app.secret_key = os.environ.get('SECRET_KEY', 'dev-key') # HTML-Template wird jetzt aus templates/index.html geladen @@ -11,10 +13,20 @@ WOCHENTAGE = ["Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samsta @app.route('/', methods=['GET', 'POST']) def index(): + # Rudimentäres Logging für Page Impressions + log_dir = 'log' + os.makedirs(log_dir, exist_ok=True) + with open(os.path.join(log_dir, 'pageviews.log'), 'a', encoding='utf-8') as f: + from datetime import datetime as dt + f.write(f"{dt.now().isoformat()} PAGEVIEW\n") tage = werktage = wochentag = datumsrechnung = werktagsrechnung = kw_berechnen = kw_datum = wochen_monate = None active_idx = 0 if request.method == 'POST': action = request.form.get('action') + # Funktions-Logging + with open(os.path.join(log_dir, 'pageviews.log'), 'a', encoding='utf-8') as f: + from datetime import datetime as dt + f.write(f"{dt.now().isoformat()} FUNC: {action}\n") if action == 'tage': active_idx = 0 start = request.form.get('start1') @@ -120,5 +132,31 @@ def index(): return render_template('index.html', tage=tage, werktage=werktage, wochentag=wochentag, datumsrechnung=datumsrechnung, werktagsrechnung=werktagsrechnung, kw_berechnen=kw_berechnen, kw_datum=kw_datum, active_idx=active_idx, wochen_monate=wochen_monate) +@app.route('/stats', methods=['GET', 'POST']) +def stats(): + stats_password = os.environ.get('STATS_PASSWORD', 'changeme') + if 'stats_auth' not in session: + if request.method == 'POST': + if request.form.get('password') == stats_password: + session['stats_auth'] = True + return redirect(url_for('stats')) + else: + return render_template('stats_login.html', error='Falsches Passwort!') + return render_template('stats_login.html', error=None) + # Auswertung der Logdatei + log_path = os.path.join('log', 'pageviews.log') + pageviews = 0 + func_counts = {} + if os.path.exists(log_path): + with open(log_path, encoding='utf-8') as f: + for line in f: + if 'PAGEVIEW' in line: + pageviews += 1 + elif 'FUNC:' in line: + func = line.split('FUNC:')[1].strip() + func_counts[func] = func_counts.get(func, 0) + 1 + return render_template('stats_dashboard.html', pageviews=pageviews, func_counts=func_counts) + + if __name__ == '__main__': app.run(debug=True) \ No newline at end of file diff --git a/templates/stats_dashboard.html b/templates/stats_dashboard.html new file mode 100644 index 0000000..e759b5a --- /dev/null +++ b/templates/stats_dashboard.html @@ -0,0 +1,52 @@ + + + + + Dashboard – Elpatrons Datumsrechner + + + + + +
+

Statistik-Dashboard

+
+
Gesamt-Pageviews:
+
{{ pageviews }}
+
+
+ +
+ Zurück zur App +
+ + + \ No newline at end of file diff --git a/templates/stats_login.html b/templates/stats_login.html new file mode 100644 index 0000000..466df25 --- /dev/null +++ b/templates/stats_login.html @@ -0,0 +1,25 @@ + + + + + Dashboard Login + + + + +
+

Dashboard Login

+ {% if error %}
{{ error }}
{% endif %} +
+ + +
+
+ + \ No newline at end of file