From cbaa07676c1b8bdbe9c67ef0af3dd718013d9156 Mon Sep 17 00:00:00 2001 From: ra_ma Date: Fri, 20 Jun 2025 19:49:05 +0100 Subject: [PATCH] statsu maybe --- app.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 1fb769d..c2d24c7 100644 --- a/app.py +++ b/app.py @@ -39,6 +39,7 @@ def log_request(repo, arch, protocol): request_stats[day][(repo, arch, protocol)] += 1 request_stats[week][(repo, arch, protocol)] += 1 request_stats[month][(repo, arch, protocol)] += 1 + @app.route('/metalink') def get_metalink(): # Get query parameters from the request @@ -49,6 +50,9 @@ def get_metalink(): if not repo or not arch: return "Error: Missing 'repo' or 'arch' parameter", 400 + # Log the request + log_request(repo, arch, 'http') # Assuming HTTP for simplicity + # Construct the metalink URL using the provided parameters metalink_url = f'https://mirrors.fedoraproject.org/metalink?repo={repo}&arch={arch}' @@ -100,15 +104,18 @@ def filter_urls(content, excluded_countries, preferred_protocols, preferred_type def stats(): # Generate some statistics stats_data = { - 'hourly': request_stats.get(time.strftime('%Y-%m-%d %H', time.localtime()), {}), - 'daily': request_stats.get(time.strftime('%Y-%m-%d', time.localtime()), {}), - 'weekly': request_stats.get(time.strftime('%Y-%U', time.localtime()), {}), - 'monthly': request_stats.get(time.strftime('%Y-%m', time.localtime()), {}) + 'hourly': dict(request_stats.get(time.strftime('%Y-%m-%d %H', time.localtime()), {})), + 'daily': dict(request_stats.get(time.strftime('%Y-%m-%d', time.localtime()), {})), + 'weekly': dict(request_stats.get(time.strftime('%Y-%U', time.localtime()), {})), + 'monthly': dict(request_stats.get(time.strftime('%Y-%m', time.localtime()), {})) } # Convert stats data to a DataFrame for easier manipulation df = pd.DataFrame.from_dict(stats_data, orient='index').fillna(0) + if df.empty: + return render_template('stats.html', plot_url=None, message="No data available.") + # Generate a simple plot plt.figure(figsize=(10, 6)) df.sum(axis=1).plot(kind='bar')