Skip to content

Commit

Permalink
Debug test list using HTML table
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoCeratto committed Oct 9, 2023
1 parent f1e28fb commit a547ed6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 3 deletions.
6 changes: 6 additions & 0 deletions api/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ooni-api (1.0.75) unstable; urgency=medium

* Debug test list using HTML table

-- Federico Ceratto <[email protected]> Mon, 09 Oct 2023 11:32:34 +0200

ooni-api (1.0.74) unstable; urgency=medium

* Filter measurements by OONIRun ID
Expand Down
30 changes: 27 additions & 3 deletions api/ooniapi/prio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
75 changes: 75 additions & 0 deletions api/ooniapi/templates/debug_prio.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<head>
<title>OONI API</title>

{% block head_meta %}
<meta charset="UTF-8">
{% endblock %}

{% block head_css %}
<link href="/static/css/master.css" rel="stylesheet" />
{% endblock %}

{% block head %}
{% endblock %}

{% block head_js %}
{% endblock %}

<script src="https://www.kryogenix.org/code/browser/sorttable/sorttable.js"></script>

</head>
<body>
{% block body %}

{% block navbar %}
{% endblock %}

{% block uncontained %}
{% endblock %}

<div class="container">

{% block content_fluid %}
{% endblock %}

<form>
<label>CC</label> <input type="text" name="probe_cc"> <br>
<input type="submit" value="Submit">
</form>

<table class="sortable">
<tr>
<th>url</th>
<th>category_code</th>
<th>msmt_cnt</th>
<th>priority</th>
<th>weight</th>
</tr>

{% for i in test_items %}
<tr class="item">
<td>{{ i["url"] }}</td>
<td>{{ i["category_code"] }}</td>
<td>{{ i["msmt_cnt"] }}</td>
<td>{{ i["priority"] }}</td>
<td>{{ i["weight"] }}</td>
</tr>
{% endfor %}

</table>

</div>

{% block footer %}
{% include 'footer.html' %}
{% endblock %}

{% block tail_js %}
{% endblock %}

{% endblock %}
</body>
</html>

0 comments on commit a547ed6

Please sign in to comment.