From ca9dd0d785407bc9b9573b80df9ae0496f4db4a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 20 Jun 2023 21:04:54 +0200 Subject: [PATCH] Continued: - another aliases for pleroma/misskey --- api.py | 6 +++++- fba/federation.py | 4 ++-- templates/views/index.html | 3 ++- templates/views/scoreboard.html | 8 ++++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/api.py b/api.py index 052b383..41e0589 100644 --- a/api.py +++ b/api.py @@ -68,6 +68,8 @@ def api_top(mode: str, amount: int): fba.cursor.execute("SELECT command, COUNT(domain) AS score FROM instances WHERE command IS NOT NULL GROUP BY command ORDER BY score DESC, command ASC LIMIT ?", [amount]) elif mode == "error_code": fba.cursor.execute("SELECT last_status_code, COUNT(domain) AS score FROM instances WHERE last_status_code IS NOT NULL AND last_status_code != '200' GROUP BY last_status_code ORDER BY score DESC LIMIT ?", [amount]) + elif mode == "avg_peers": + fba.cursor.execute("SELECT software, AVG(total_peers) AS sum FROM instances WHERE software IS NOT NULL GROUP BY software HAVING sum>0 ORDER BY sum DESC LIMIT ?", [amount]) else: raise HTTPException(status_code=400, detail="No filter specified") @@ -76,7 +78,7 @@ def api_top(mode: str, amount: int): for domain, score in fba.cursor.fetchall(): scores.append({ "domain": domain, - "score" : score + "score" : round(score) }) return scores @@ -172,6 +174,8 @@ def scoreboard(request: Request, mode: str, amount: int): response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=command&amount={amount}") elif mode == "error_code" and amount > 0: response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=error_code&amount={amount}") + elif mode == "avg_peers" and amount > 0: + response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode=avg_peers&amount={amount}") else: raise HTTPException(status_code=400, detail="No filter specified") diff --git a/fba/federation.py b/fba/federation.py index c9d9592..ec71617 100644 --- a/fba/federation.py +++ b/fba/federation.py @@ -495,13 +495,13 @@ def determine_software(domain: str, path: str = None) -> str: sofware = tidyup.domain(software) # DEBUG: print("DEBUG: sofware after tidyup.domain():", software) - if software in ["akkoma", "rebased"]: + if software in ["akkoma", "rebased", "akkounfucked", "ched"]: # DEBUG: print("DEBUG: Setting pleroma:", domain, software) software = "pleroma" elif software in ["hometown", "ecko"]: # DEBUG: print("DEBUG: Setting mastodon:", domain, software) software = "mastodon" - elif software in ["slipfox calckey", "calckey", "groundpolis", "foundkey", "cherrypick", "meisskey"]: + elif software in ["slipfox calckey", "calckey", "groundpolis", "foundkey", "cherrypick", "meisskey", "magnetar", "keybump"]: # DEBUG: print("DEBUG: Setting misskey:", domain, software) software = "misskey" elif software == "runtube.re": diff --git a/templates/views/index.html b/templates/views/index.html index 7e8849a..2cab610 100644 --- a/templates/views/index.html +++ b/templates/views/index.html @@ -30,7 +30,8 @@ referencing instances / used software / commands / - error codes + error codes / + average peers

{% endblock %} {% block footer %} diff --git a/templates/views/scoreboard.html b/templates/views/scoreboard.html index dbbba79..46d5807 100644 --- a/templates/views/scoreboard.html +++ b/templates/views/scoreboard.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block title %}Scoreboard - {% if mode == 'software' %}TOP {{amount}} used software{% elif mode == 'command' %}TOP {{amount}} commands{% elif mode == 'error_code' %}TOP {{amount}} error codes{% elif mode == 'reference' %}TOP {{amount}} referencing instances{% elif mode == 'blocked' %}TOP {{amount}} deferated instances{% elif mode == 'blocker' %}TOP {{amount}} deferating instances{% endif %}{% endblock %} +{% block title %}Scoreboard - {% if mode == 'software' %}TOP {{amount}} used software{% elif mode == 'avg_peers' %}TOP {{amount}} average peer count{% elif mode == 'command' %}TOP {{amount}} commands{% elif mode == 'error_code' %}TOP {{amount}} error codes{% elif mode == 'reference' %}TOP {{amount}} referencing instances{% elif mode == 'blocked' %}TOP {{amount}} deferated instances{% elif mode == 'blocker' %}TOP {{amount}} deferating instances{% endif %}{% endblock %} {% block header %} {% if mode == 'blocker' %} @@ -23,8 +23,8 @@ - - + + @@ -32,7 +32,7 @@
№{% if mode == 'software' %}Software{% elif mode == 'error_code' %}Error code{% else %}Instance{% endif %}{% if mode == 'reference' %}References{% elif mode in('software', 'error_code') %}Total{% else %}Blocks{% endif %}{% if mode in ('software', 'avg_peers') %}Software{% elif mode == 'error_code' %}Error code{% else %}Instance{% endif %}{% if mode == 'reference' %}References{% elif mode == 'avg_peers' %}Average{% elif mode in('software', 'error_code') %}Total{% else %}Blocks{% endif %}
{{loop.index}} - {% if mode in ('software', 'command', 'error_code') %} + {% if mode in ('software', 'command', 'error_code', 'avg_peers') %} {{entry['domain']}} {% elif entry['domain'] == None %} - -- 2.39.5