statsu maybe
This commit is contained in:
15
app.py
15
app.py
@@ -39,6 +39,7 @@ def log_request(repo, arch, protocol):
|
|||||||
request_stats[day][(repo, arch, protocol)] += 1
|
request_stats[day][(repo, arch, protocol)] += 1
|
||||||
request_stats[week][(repo, arch, protocol)] += 1
|
request_stats[week][(repo, arch, protocol)] += 1
|
||||||
request_stats[month][(repo, arch, protocol)] += 1
|
request_stats[month][(repo, arch, protocol)] += 1
|
||||||
|
|
||||||
@app.route('/metalink')
|
@app.route('/metalink')
|
||||||
def get_metalink():
|
def get_metalink():
|
||||||
# Get query parameters from the request
|
# Get query parameters from the request
|
||||||
@@ -49,6 +50,9 @@ def get_metalink():
|
|||||||
if not repo or not arch:
|
if not repo or not arch:
|
||||||
return "Error: Missing 'repo' or 'arch' parameter", 400
|
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
|
# Construct the metalink URL using the provided parameters
|
||||||
metalink_url = f'https://mirrors.fedoraproject.org/metalink?repo={repo}&arch={arch}'
|
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():
|
def stats():
|
||||||
# Generate some statistics
|
# Generate some statistics
|
||||||
stats_data = {
|
stats_data = {
|
||||||
'hourly': request_stats.get(time.strftime('%Y-%m-%d %H', time.localtime()), {}),
|
'hourly': dict(request_stats.get(time.strftime('%Y-%m-%d %H', time.localtime()), {})),
|
||||||
'daily': request_stats.get(time.strftime('%Y-%m-%d', time.localtime()), {}),
|
'daily': dict(request_stats.get(time.strftime('%Y-%m-%d', time.localtime()), {})),
|
||||||
'weekly': request_stats.get(time.strftime('%Y-%U', time.localtime()), {}),
|
'weekly': dict(request_stats.get(time.strftime('%Y-%U', time.localtime()), {})),
|
||||||
'monthly': request_stats.get(time.strftime('%Y-%m', time.localtime()), {})
|
'monthly': dict(request_stats.get(time.strftime('%Y-%m', time.localtime()), {}))
|
||||||
}
|
}
|
||||||
|
|
||||||
# Convert stats data to a DataFrame for easier manipulation
|
# Convert stats data to a DataFrame for easier manipulation
|
||||||
df = pd.DataFrame.from_dict(stats_data, orient='index').fillna(0)
|
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
|
# Generate a simple plot
|
||||||
plt.figure(figsize=(10, 6))
|
plt.figure(figsize=(10, 6))
|
||||||
df.sum(axis=1).plot(kind='bar')
|
df.sum(axis=1).plot(kind='bar')
|
||||||
|
|||||||
Reference in New Issue
Block a user