From 71b3c3e8e5873b730f448114f80cde42a1557f4e Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Tue, 3 Sep 2024 13:23:04 +0200 Subject: [PATCH] modified: app.py modified: templates/index.html --- app.py | 29 ++++++++++++++++++++++++++++- templates/index.html | 7 ++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 48ccc34..42472eb 100644 --- a/app.py +++ b/app.py @@ -74,7 +74,8 @@ def get_db_connection(): @app.route("/") def index(): if "username" in session: - return render_template("index.html", bot_running=bot_status()) + bot_stats = get_bot_statistics() + return render_template("index.html", bot_running=bot_status(), **bot_stats) return redirect(url_for("login")) @app.route("/login", methods=["GET", "POST"]) @@ -160,6 +161,32 @@ def get_logs(): return jsonify({"logs": "Log file not found."}) return redirect(url_for("login")) +def get_bot_statistics(): + """Berechnet grundlegende Statistiken für den Bot.""" + connection = get_db_connection() + cursor = connection.cursor(dictionary=True) + + # Beispielabfragen, anpassen je nach Datenbankstruktur + cursor.execute("SELECT COUNT(*) AS total_messages FROM chat_history") + total_messages = cursor.fetchone()["total_messages"] + + cursor.execute(""" + SELECT command_name, COUNT(*) AS usage_count + FROM command_log + GROUP BY command_name + ORDER BY usage_count DESC + LIMIT 1 + """) + most_used_command = cursor.fetchone()["command_name"] + + cursor.close() + connection.close() + + return { + "total_messages": total_messages, + "most_used_command": most_used_command, + } + @app.route("/download_logs") def download_logs(): """Bietet die Log-Datei zum Download an.""" diff --git a/templates/index.html b/templates/index.html index fdb9d55..e2df428 100644 --- a/templates/index.html +++ b/templates/index.html @@ -24,12 +24,13 @@ Stop Bot Settings + Logs User Management Logout -
Total Messages Processed: {{ total_messages }}
-Most Used Command: {{ most_used_command }}
+Total Messages Processed: {{ total_messages }}
+Most Used Command: {{ most_used_command }}