]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 8 Jun 2023 17:39:35 +0000 (19:39 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 8 Jun 2023 17:39:35 +0000 (19:39 +0200)
- added "TOP 30" of error codes (excluding 200)

api.py
templates/views/index.html
templates/views/scoreboard.html

diff --git a/api.py b/api.py
index 49a5c9583158a29ad60847803b4a19dc35d12c33..ec459f5987a95cb58e8f5f0f869457cbe8fbb3a4 100644 (file)
--- a/api.py
+++ b/api.py
@@ -46,7 +46,7 @@ def info():
     }
 
 @router.get(config.get("base_url") + "/api/top.json", response_class=JSONResponse)
-def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None, originator: int = None):
+def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None, originator: int = None, error_code: int = None):
     if blocked != None:
         if blocked > 500:
             raise HTTPException(status_code=400, detail="Too many results")
@@ -67,6 +67,10 @@ def top(blocked: int = None, blockers: int = None, reference: int = None, softwa
         if originator > 500:
             raise HTTPException(status_code=400, detail="Too many results")
         fba.cursor.execute("SELECT originator, COUNT(domain) FROM instances WHERE originator IS NOT NULL GROUP BY originator ORDER BY COUNT(domain) DESC, originator ASC LIMIT ?", [originator])
+    elif error_code != None:
+        if error_code > 500:
+            raise HTTPException(status_code=400, detail="Too many results")
+        fba.cursor.execute("SELECT last_status_code, COUNT(domain) AS cnt FROM instances WHERE last_status_code IS NOT NULL AND last_status_code != '200' GROUP BY last_status_code ORDER BY cnt DESC LIMIT ?", [error_code])
     else:
         raise HTTPException(status_code=400, detail="No filter specified")
 
@@ -145,9 +149,7 @@ def mutual(domains: list[str] = Query()):
     return JSONResponse(status_code=200, content={})
 
 @router.get(config.get("base_url") + "/scoreboard")
-def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None, originator: int = None):
-    scores = None
-
+def index(request: Request, blockers: int = None, blocked: int = None, reference: int = None, software: int = None, originator: int = None, error_code: int = None):
     if blockers != None and blockers > 0:
         response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?blockers={blockers}")
     elif blocked != None and blocked > 0:
@@ -158,6 +160,8 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference
         response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?software={software}")
     elif originator != None and originator > 0:
         response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?originator={originator}")
+    elif error_code != None and error_code > 0:
+        response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?error_code={error_code}")
     else:
         raise HTTPException(status_code=400, detail="No filter specified")
 
@@ -176,6 +180,7 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference
         "reference" : reference,
         "software"  : software,
         "originator": originator,
+        "error_code": error_code,
         "scores"    : fba.json_from_response(response)
     })
 
index 010ccd159ec4dd5d25c1c5ff9c44d451067a5eb2..8a4db26eb1a00673b7c54946c18e17a8db7aa359 100644 (file)
@@ -29,7 +29,8 @@
         <a href="{{base_url}}/scoreboard?blocked=50">defederated instances</a> /
         <a href="{{base_url}}/scoreboard?reference=50">referencing instances</a> /
         <a href="{{base_url}}/scoreboard?software=50">used software</a> /
-        <a href="{{base_url}}/scoreboard?originator=10">originators</a>
+        <a href="{{base_url}}/scoreboard?originator=10">originators</a> /
+        <a href="{{base_url}}/scoreboard?error_code=30">error codes</a>
     </p>
 {% endblock %}
 {% block footer %}
index de3453beb56fb942b285a01975904e82da7ebff5..451cc434b6667465fa046a6fd3f54dc455819011 100644 (file)
@@ -21,8 +21,8 @@
         <table>
             <thead>
                 <th>№</th>
-                <th>{% if software %}Software{% else %}Instance{% endif %}</th>
-                <th>{% if reference %}References{% elif software %}Total{% else %}Blocks{% endif %}</th>
+                <th>{% if software %}Software{% elif error_code %}Error code{% else %}Instance{% endif %}</th>
+                <th>{% if reference %}References{% elif software or error_code %}Total{% else %}Blocks{% endif %}</th>
             </thead>
 
             <tbody>
@@ -30,9 +30,7 @@
                 <tr>
                     <td>{{loop.index}}</td>
                     <td>
-                        {% if software %}
-                            {{entry['domain']}}
-                        {% elif originator %}
+                        {% if software or originator or error_code %}
                             {{entry['domain']}}
                         {% elif entry['domain'] == None %}
                             -