Skip to content

Commit f0aa096

Browse files
committed
ui: flakes: support filtering by branch prefix
Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a88484e commit f0aa096

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

contest/backend/query.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ def branches():
3535
return rows
3636

3737

38-
#SELECT branch,branch_date,count(*),remote FROM results GROUP BY branch,branch_date,remote ORDER BY branch_date DESC LIMIT 510;
39-
40-
def branches_to_rows(br_cnt, remote):
38+
def branches_to_rows(br_cnt, remote, br_pfx=None):
4139
global psql
4240

4341
cnt = 0
4442
with psql.cursor() as cur:
45-
if remote:
46-
q = f"SELECT branch,count(*),branch_date,remote FROM results GROUP BY branch,branch_date,remote ORDER BY branch_date DESC LIMIT {br_cnt}"
47-
else:
48-
q = f"SELECT branch,count(*),branch_date FROM results GROUP BY branch,branch_date ORDER BY branch_date DESC LIMIT {br_cnt}"
43+
remote_k = ",remote" if remote else ""
44+
# Slap the -2 in here as the first letter of the date, to avoid prefix of prefix matches
45+
pfx_flt = f"WHERE branch LIKE '{br_pfx}-2%' " if br_pfx else ""
46+
47+
q = f"SELECT branch,count(*),branch_date{remote_k} FROM results {pfx_flt} GROUP BY branch,branch_date{remote_k} ORDER BY branch_date DESC LIMIT {br_cnt}"
48+
4949
cur.execute(q)
5050
for r in cur.fetchall():
5151
cnt += r[1]
@@ -108,7 +108,12 @@ def results():
108108
if not br_cnt:
109109
br_cnt = 10
110110

111-
limit = branches_to_rows(br_cnt, remote)
111+
br_pfx = request.args.get('br-pfx')
112+
if br_pfx:
113+
# Slap the -2 in here as the first letter of the date, to avoid prefix of prefix matches
114+
where.append(f"branch LIKE '{br_pfx}-2%'")
115+
116+
limit = branches_to_rows(br_cnt, remote, br_pfx)
112117

113118
t2 = datetime.datetime.now()
114119

ui/contest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function reload_select_filters(first_load)
168168
old_values[elem_id] = elem.value;
169169
}
170170

171-
// Keep the "all" option, remove the rest
171+
// Wipe the options and re-add
172172
$("select option").remove();
173173

174174
// We have all JSONs now, do processing.

ui/flakes.html

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<br />
3030
<input type="number" id="br-cnt" name="ld-pw" min="1" value="100" disabled>
3131
<div style="height=1em">&nbsp;</div>
32+
<label for="br-pfx">Branch prefix</label>
33+
<select id="br-pfx" name="ld-pw" disabled></select>
34+
<div style="height=1em">&nbsp;</div>
3235
<label for="ld-remote">Remote</label>
3336
<select id="ld-remote" name="ld-pw" disabled></select>
3437
<div style="height=1em">&nbsp;</div>

ui/flakes.js

+18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function get_sort_key()
1212
return "cnt";
1313
}
1414

15+
var branch_pfx_set = new Set();
16+
1517
function load_result_table(data_raw)
1618
{
1719
// Get all branch names
@@ -22,6 +24,19 @@ function load_result_table(data_raw)
2224
let br_cnt = document.getElementById("br-cnt").value;
2325
const branches = Array.from(branch_set).slice(0, br_cnt);
2426

27+
// Populate the load filters with prefixes
28+
let select_br_pfx = document.getElementById("br-pfx");
29+
for (const br of branches) {
30+
const br_pfx = nipa_br_pfx_get(br);
31+
32+
if (select_br_pfx.length == 0)
33+
nipa_select_add_option(select_br_pfx, "-- all --", "");
34+
if (branch_pfx_set.has(br_pfx))
35+
continue;
36+
nipa_select_add_option(select_br_pfx, br_pfx, br_pfx);
37+
branch_pfx_set.add(br_pfx);
38+
}
39+
2540
// Build the result map
2641
var pw_n = document.getElementById("pw-n").checked;
2742
var pw_y = document.getElementById("pw-y").checked;
@@ -175,6 +190,7 @@ function reload_data()
175190
{
176191
const format_l2 = document.getElementById("ld-cases");
177192
const br_cnt = document.getElementById("br-cnt");
193+
const br_pfx = document.getElementById("br-pfx");
178194
const remote = document.getElementById("ld-remote");
179195

180196
let req_url = "query/results";
@@ -184,6 +200,8 @@ function reload_data()
184200
req_url += "&format=l2";
185201
if (remote.value)
186202
req_url += "&remote=" + remote.value;
203+
if (br_pfx.value)
204+
req_url += "&br-pfx=" + br_pfx.value;
187205

188206
nipa_filters_disable(["ld-pw", "fl-pw"]);
189207
$(document).ready(function() {

0 commit comments

Comments
 (0)