From a547ed68e874cd6e3955c29a8839e6303a0ccb37 Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Mon, 9 Oct 2023 12:21:04 +0200 Subject: [PATCH] Debug test list using HTML table --- api/debian/changelog | 6 +++ api/ooniapi/prio.py | 30 +++++++++-- api/ooniapi/templates/debug_prio.html | 75 +++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 api/ooniapi/templates/debug_prio.html diff --git a/api/debian/changelog b/api/debian/changelog index 5fa90797..e51936e8 100644 --- a/api/debian/changelog +++ b/api/debian/changelog @@ -1,3 +1,9 @@ +ooni-api (1.0.75) unstable; urgency=medium + + * Debug test list using HTML table + + -- Federico Ceratto Mon, 09 Oct 2023 11:32:34 +0200 + ooni-api (1.0.74) unstable; urgency=medium * Filter measurements by OONIRun ID diff --git a/api/ooniapi/prio.py b/api/ooniapi/prio.py index 9a71938b..1a29be2a 100644 --- a/api/ooniapi/prio.py +++ b/api/ooniapi/prio.py @@ -26,7 +26,14 @@ from typing import List, Dict, Tuple import random -from flask import Blueprint, current_app, request, Response, make_response +from flask import ( + Blueprint, + current_app, + request, + Response, + make_response, + render_template, +) from sqlalchemy import sql as sa from ooniapi.config import metrics @@ -146,7 +153,9 @@ def fetch_reactive_url_list(cc: str, probe_asn: int) -> tuple: q = q.replace("--asn-filter--", "AND probe_asn = :asn") # support uppercase or lowercase match - r = query_click(sa.text(q), dict(cc=cc, cc_low=cc.lower(), asn=probe_asn), query_prio=1) + r = query_click( + sa.text(q), dict(cc=cc, cc_low=cc.lower(), asn=probe_asn), query_prio=1 + ) return tuple(r) @@ -321,6 +330,9 @@ def debug_prioritization() -> Response: in: query type: string description: Probe ASN + - name: format + in: query + description: JSON or HTML - name: limit in: query type: integer @@ -336,10 +348,22 @@ def debug_prioritization() -> Response: category_codes = param_category_codes() asn = param_asn("probe_asn") or 0 limit = int(param("limit") or -1) + fmt = (param("format") or "HTML").upper() test_items, entries, prio_rules = generate_test_list( country_code, category_codes, asn, limit, True ) - return cachedjson("0s", test_items=test_items, entries=entries, prio_rules=prio_rules) + if fmt == "JSON": + out = cachedjson( + "0s", test_items=test_items, entries=entries, prio_rules=prio_rules + ) + else: + out = render_template( + "debug_prio.html", + test_items=test_items, + entries=entries, + prio_rules=prio_rules, + ) + return out @prio_bp.route("/api/_/show_countries_prioritization") diff --git a/api/ooniapi/templates/debug_prio.html b/api/ooniapi/templates/debug_prio.html new file mode 100644 index 00000000..3133c700 --- /dev/null +++ b/api/ooniapi/templates/debug_prio.html @@ -0,0 +1,75 @@ + + + + OONI API + + {% block head_meta %} + + {% endblock %} + + {% block head_css %} + + {% endblock %} + + {% block head %} + {% endblock %} + + {% block head_js %} + {% endblock %} + + + + + +{% block body %} + + {% block navbar %} + {% endblock %} + + {% block uncontained %} + {% endblock %} + +
+ + {% block content_fluid %} + {% endblock %} + +
+
+ +
+ + + + + + + + + + + {% for i in test_items %} + + + + + + + + {% endfor %} + +
urlcategory_codemsmt_cntpriorityweight
{{ i["url"] }}{{ i["category_code"] }}{{ i["msmt_cnt"] }}{{ i["priority"] }}{{ i["weight"] }}
+ +
+ + {% block footer %} + {% include 'footer.html' %} + {% endblock %} + + {% block tail_js %} + {% endblock %} + +{% endblock %} + + +