]> git.mxchange.org Git - fba.git/blobdiff - api.py
Continued:
[fba.git] / api.py
diff --git a/api.py b/api.py
index 052b3836e49b06e15c0ad677705f007b9b3d459b..41e0589e13f8915607047ecab1993ab6f2325284 100644 (file)
--- 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")