Skip to content

Commit

Permalink
Add a basic search to finished tests and rename URL parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dav1312 committed Sep 21, 2022
1 parent 2ab066c commit c156c60
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 50 deletions.
16 changes: 10 additions & 6 deletions server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,19 +469,23 @@ def get_finished_runs(
skip=0,
limit=0,
username="",
success_only=False,
yellow_only=False,
ltc_only=False,
status=False,
tc=False,
info=""
):
q = {"finished": True}
if username:
q["args.username"] = username
if ltc_only:
if tc == "stc":
q["tc_base"] = {"$lte": 40}
if tc == "ltc":
q["tc_base"] = {"$gte": 40}
if success_only:
if status == "green":
q["is_green"] = True
if yellow_only:
if status == "yellow":
q["is_yellow"] = True
if info:
q["args.info"] = {"$regex": ".*{}.*".format(info), "$options": "i"}

c = self.runs.find(
q, skip=skip, limit=limit, sort=[("last_updated", DESCENDING)]
Expand Down
10 changes: 7 additions & 3 deletions server/fishtest/static/css/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,19 @@ legend {
content: "\f00b";
}

.mainnavbar [href="/tests/finished?success_only=1"]::before {
.mainnavbar [href="/tests/finished"]::before {
content: "\f11e";
}

.mainnavbar [href="/tests/finished?status=green"]::before {
content: "\f14a";
}

.mainnavbar [href="/tests/finished?yellow_only=1"]::before {
.mainnavbar [href="/tests/finished?status=yellow"]::before {
content: "\f3fd";
}

.mainnavbar [href="/tests/finished?ltc_only=1"]::before {
.mainnavbar [href="/tests/finished?tc=ltc"]::before {
content: "\f017";
}

Expand Down
4 changes: 2 additions & 2 deletions server/fishtest/templates/actions.mak
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</div>
<div class="col-12 col-md-auto mb-3">
<label for="user" class="form-label">From user</label>
<input id="user" type="text" name="user" class="form-control" placeholder="username" value="${request.GET.get('user') if request.GET.get('user') != None else ''}">
<input id="user" type="text" name="user" class="form-control" placeholder="username" value="${request.GET.get('user') if request.GET.get('user') is not None else ''}">
</div>

<input type="hidden" id="before" name="before" value=-1>
Expand Down Expand Up @@ -78,5 +78,5 @@
</div>

<script>
document.querySelector('#restrict').value = ('${request.GET.get("action") if request.GET.get("action") != None else ''}');
document.querySelector('#restrict').value = ('${request.GET.get("action") if request.GET.get("action") is not None else ''}');
</script>
7 changes: 4 additions & 3 deletions server/fishtest/templates/base.mak
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ monitoring = request.rundb.conn["admin"].command("getFreeMonitoringStatus")
<strong class="links-heading d-flex w-100 align-items-center fw-semibold">Tests</strong>
<ul class="list-unstyled fw-normal small">
<li><a href="/tests" class="links-link rounded">Overview</a></li>
<li><a href="/tests/finished?ltc_only=1" class="links-link rounded">LTC</a></li>
<li><a href="/tests/finished?success_only=1" class="links-link rounded">Greens</a></li>
<li><a href="/tests/finished?yellow_only=1" class="links-link rounded">Yellows</a></li>
<li><a href="/tests/finished" class="links-link rounded">Finished</a></li>
<li><a href="/tests/finished?tc=ltc" class="links-link rounded">LTC</a></li>
<li><a href="/tests/finished?status=green" class="links-link rounded">Greens</a></li>
<li><a href="/tests/finished?status=yellow" class="links-link rounded">Yellows</a></li>
<li><a href="https://groups.google.com/g/fishcooking-results" target="_blank" rel="noopener" class="links-link rounded">History</a></li>
</ul>
</li>
Expand Down
4 changes: 2 additions & 2 deletions server/fishtest/templates/run_table.mak
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%page args="runs, pages=None, show_delete=False, header=None, count=None, toggle=None, alt=None, title=''"/>
<%page args="runs, pages=None, show_delete=False, header=None, count=None, toggle=None, alt=None"/>

<%namespace name="base" file="base.mak"/>

% if toggle is None:
<script>
document.title = '${username + " - " if username else ""}Finished Tests${title} - page ${page_idx+1} | Stockfish Testing';
document.title = '${username + " - " if username else ""}Finished Tests - page ${page_idx+1} | Stockfish Testing';
</script>
% endif

Expand Down
50 changes: 31 additions & 19 deletions server/fishtest/templates/tests_finished.mak
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
<%inherit file="base.mak"/>
<%
title = ""
if "ltc_only" in request.url:
title += " - LTC"
if "success_only" in request.url:
title += " - Greens"
if "yellow_only" in request.url:
title += " - Yellows"
%>

<script>
document.title = 'Finishes Test${title} | Stockfish Testing';
document.title = 'Finished Tests | Stockfish Testing';
</script>

<h2>
Finished Tests
% if 'success_only' in request.url:
- Greens
% elif 'yellow_only' in request.url:
- Yellows
% elif 'ltc_only' in request.url:
- LTC
% endif
</h2>

<form class="row mb-3">
<div class="col-12 col-md-auto mb-3">
<label for="tc" class="form-label">Time control</label>
<select id="tc" class="form-select" name="tc">
<option value="">All</option>
<option value="stc" ${"selected" if request.GET.get('tc') == "stc" else ''}>STC</option>
<option value="ltc" ${"selected" if request.GET.get('tc') == "ltc" else ''}>LTC</option>
</select>
</div>

<div class="col-12 col-md-auto mb-3">
<label for="status" class="form-label">Status</label>
<select id="status" class="form-select" name="status">
<option value="">All</option>
<option value="yellow" ${"selected" if request.GET.get('status') == "yellow" else ''}>Yellow</option>
<option value="green" ${"selected" if request.GET.get('status') == "green" else ''}>Green</option>
</select>
</div>

<div class="col-12 col-md-auto mb-3">
<label for="info" class="form-label">Info</label>
<input id="info" type="text" name="info" class="form-control" placeholder="Run info" value="${request.GET.get('info') if request.GET.get('info') is not None else ''}">
</div>

<div class="col-12 col-md-auto mb-3 d-flex align-items-end">
<button type="submit" class="btn btn-success w-100">Search</button>
</div>
</form>

<%include file="run_table.mak" args="runs=finished_runs,
header='Finished',
count=num_finished_runs,
pages=finished_runs_pages,
title=title"
pages=finished_runs_pages"
/>
24 changes: 12 additions & 12 deletions server/fishtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,19 +1166,19 @@ def tests_view(request):

def get_paginated_finished_runs(request):
username = request.matchdict.get("username", "")
success_only = request.params.get("success_only", False)
yellow_only = request.params.get("yellow_only", False)
ltc_only = request.params.get("ltc_only", False)
status = request.params.get("status", False)
tc = request.params.get("tc", False)
info = request.params.get("info", False)

page_idx = max(0, int(request.params.get("page", 1)) - 1)
page_size = 25
finished_runs, num_finished_runs = request.rundb.get_finished_runs(
username=username,
success_only=success_only,
yellow_only=yellow_only,
ltc_only=ltc_only,
status=status,
tc=tc,
skip=page_idx * page_size,
limit=page_size,
info=info,
)

pages = [
Expand Down Expand Up @@ -1217,12 +1217,12 @@ def get_paginated_finished_runs(request):
)

for page in pages:
if success_only:
page["url"] += "&success_only=1"
if yellow_only:
page["url"] += "&yellow_only=1"
if ltc_only:
page["url"] += "&ltc_only=1"
if status:
page["url"] += "&status={}".format(status)
if tc:
page["url"] += "&tc={}".format(tc)
if info:
page["url"] += "&info={}".format(info)

failed_runs = []
for run in finished_runs:
Expand Down
2 changes: 1 addition & 1 deletion server/tests/test_rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def test_30_finish(self):
self.rundb.buffer(run, True)

def test_40_list_LTC(self):
finished_runs = self.rundb.get_finished_runs(limit=3, ltc_only=True)[0]
finished_runs = self.rundb.get_finished_runs(limit=3, tc="ltc")[0]
for run in finished_runs:
print(run["args"]["tc"])

Expand Down
4 changes: 2 additions & 2 deletions server/utils/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def qlen(c):
print("{} rows {:1.4f}".format(qlen(c), end - start) + "s\nFetching finished runs ...")
start = time.time()
c, n = rundb.get_finished_runs(
skip=0, limit=50, username="", success_only=False, ltc_only=False
skip=0, limit=50, username="", status=False, tc=False
)
end = time.time()

Expand All @@ -59,7 +59,7 @@ def qlen(c):
)
start = time.time()
c, n = rundb.get_finished_runs(
skip=0, limit=50, username="vdv", success_only=False, ltc_only=False
skip=0, limit=50, username="vdv", status=False, tc=False
)
end = time.time()

Expand Down

0 comments on commit c156c60

Please sign in to comment.