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 -
Bot Statistics
-

Total Messages Processed: {{ total_messages }}

-

Most Used Command: {{ most_used_command }}

+
Bot Statistics
+

Total Messages Processed: {{ total_messages }}

+

Most Used Command: {{ most_used_command }}