Skip to content

Commit

Permalink
Do not put results_info in the db.
Browse files Browse the repository at this point in the history
Rendered data does not belong in the db.
  • Loading branch information
vdbergh committed Jun 15, 2024
1 parent 322eea2 commit 6f66fee
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 32 deletions.
32 changes: 24 additions & 8 deletions server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,13 +820,23 @@ def aggregate_unfinished_runs(self, username=None):
)

pending_hours = 0
results_infos = {}
for run in runs["pending"] + runs["active"]:
run_id = str(run["_id"])
if cores > 0:
eta = remaining_hours(run) / cores
pending_hours += eta
results = run["results"]
run["results_info"] = format_results(results, run)
return (runs, pending_hours, cores, nps, games_per_minute, machines_count)
results_infos[run_id] = format_results(run)
return (
runs,
results_infos,
pending_hours,
cores,
nps,
games_per_minute,
machines_count,
)

def get_finished_runs(
self,
Expand Down Expand Up @@ -863,7 +873,13 @@ def get_finished_runs(

# Don't show runs that were deleted
runs_list = [run for run in c if not run.get("deleted")]
return [runs_list, count]

results_infos = {}
for run in runs_list:
run_id = str(run["_id"])
results_infos[run_id] = format_results(run)

return [runs_list, results_infos, count]

def calc_itp(self, run, count):
# Tests default to 100% base throughput, but we have several adjustments behind the scenes to get internal throughput.
Expand Down Expand Up @@ -1467,11 +1483,11 @@ def stop_run(self, run_id):
self.set_inactive_run(run)

results = run["results"]
run["results_info"] = format_results(results, run)
results_info = format_results(run)
# De-couple the styling of the run from its finished status
if run["results_info"]["style"] == "#44EB44":
if results_info["style"] == "#44EB44":
run["is_green"] = True
elif run["results_info"]["style"] == "yellow":
elif results_info["style"] == "yellow":
run["is_yellow"] = True
try:
validate(runs_schema, run, "run")
Expand Down Expand Up @@ -1587,12 +1603,12 @@ def purge_run(self, run, p=0.001, res=7.0, iters=1):
if run["args"]["sprt"]["state"] != "":
revived = False

run["results_info"] = format_results(results, run)
results_info = format_results(run)
if revived:
self.set_active_run(run)
else:
# Copied code. Must be refactored.
style = run["results_info"]["style"]
style = results_info["style"]
run["is_green"] = style == "#44EB44"
run["is_yellow"] = style == "yellow"
self.buffer(run, True)
Expand Down
6 changes: 1 addition & 5 deletions server/fishtest/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def total_games_must_match(run):
# about non-validation of runs created with the prior
# schema.

RUN_VERSION = 1
RUN_VERSION = 3

runs_schema = intersect(
{
Expand All @@ -617,10 +617,6 @@ def total_games_must_match(run):
"committed_games": uint,
"total_games": uint,
"results": results_schema,
"results_info?": {
"style": str,
"info": [str, ...],
},
"args": intersect(
{
"base_tag": str,
Expand Down
16 changes: 8 additions & 8 deletions server/fishtest/templates/elo_results.mak
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<%page args="run, show_gauge=False"/>
<%page args="run, results_info, show_gauge=False"/>

<%!
from fishtest.util import is_active_sprt_ltc

def results_pre_attrs(run):
def results_pre_attrs(results_info, run):
ret = ''
style = run['results_info'].get('style', '')
style = results_info.get('style', '')
if style:
ret = f'style="background-color: {style};"'

Expand All @@ -21,7 +21,7 @@

<%def name="list_info(run)">
<%
info = run['results_info']['info']
info = results_info['info']
l = len(info)
elo_ptnml_run = (
"sprt" not in run["args"]
Expand Down Expand Up @@ -68,23 +68,23 @@
% endif
</%def>

% if 'sprt' in run['args'] and 'Pending' not in run['results_info']['info'][0]:
% if 'sprt' in run['args'] and 'Pending' not in results_info['info'][0]:
<a href="/tests/live_elo/${str(run['_id'])}" style="color: inherit;">
% endif
% if show_gauge:
<div id="chart_div_${str(run['_id'])}" style="width:90px;float:left;"></div>
% if 'sprt' in run['args'] and 'Pending' not in run['results_info']['info'][0]:
% if 'sprt' in run['args'] and 'Pending' not in results_info['info'][0]:
<div style="margin-left:90px;padding: 30px 0;">
% else:
<div style="margin-left:90px;">
% endif
% endif
<pre ${results_pre_attrs(run)|n}>
<pre ${results_pre_attrs(results_info, run)|n}>
${list_info(run)}
</pre>
% if show_gauge:
</div>
% endif
% if 'sprt' in run['args'] and 'Pending' not in run['results_info']['info'][0]:
% if 'sprt' in run['args'] and 'Pending' not in results_info['info'][0]:
</a>
% endif
7 changes: 5 additions & 2 deletions server/fishtest/templates/run_table.mak
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%page args="runs, pages=None, show_delete=False, header=None, count=None, toggle=None, alt=None, title=''"/>
<%page args="runs, results_infos, pages=None, show_delete=False, header=None, count=None, toggle=None, alt=None, title=''"/>

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

Expand Down Expand Up @@ -60,6 +60,9 @@
<thead></thead>
<tbody>
% for run in runs:
<%
results_info = results_infos[str(run["_id"])]
%>
<tr>
% if show_delete:
<td style="width: 1%;" class="run-button run-deny">
Expand Down Expand Up @@ -111,7 +114,7 @@
</td>

<td style="width: 1%;" class="run-elo">
<%include file="elo_results.mak" args="run=run" />
<%include file="elo_results.mak" args="run=run, results_info=results_info" />
</td>

<td style="width: 13%;" class="run-live">
Expand Down
11 changes: 8 additions & 3 deletions server/fishtest/templates/run_tables.mak
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
%>

<%include file="run_table.mak" args="runs=pending_approval_runs,
results_infos=results_infos,
show_delete=True,
header='Pending approval',
count=len(pending_approval_runs),
Expand All @@ -21,6 +22,7 @@
/>

<%include file="run_table.mak" args="runs=paused_runs,
results_infos=results_infos,
show_delete=True,
header='Paused',
count=len(paused_runs),
Expand All @@ -29,6 +31,7 @@
/>

<%include file="run_table.mak" args="runs=failed_runs,
results_infos=results_infos,
show_delete=True,
toggle=prefix+'failed',
count=len(failed_runs),
Expand All @@ -37,16 +40,18 @@
/>

<%include file="run_table.mak" args="runs=runs['active'],
results_infos=results_infos,
header='Active',
toggle=prefix+'active',
count=len(runs['active']),
count=len(runs['active']),
alt='No active tests'"
/>
% endif

<%include file="run_table.mak" args="runs=finished_runs,
<%include file="run_table.mak" args="runs=finished_runs,
results_infos=results_infos,
header='Finished',
count=num_finished_runs,
toggle=prefix+'finished' if page_idx==0 else None,
pages=finished_runs_pages"
/>
/>
2 changes: 1 addition & 1 deletion server/fishtest/templates/tests_view.mak
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</h2>

<div class="elo-results-top">
<%include file="elo_results.mak" args="run=run" />
<%include file="elo_results.mak" args="run=run, results_info=results_info" />
</div>

<div class="row">
Expand Down
4 changes: 3 additions & 1 deletion server/fishtest/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ def format_bounds(elo_model, elo0, elo1):
)


def format_results(run_results, run):
def format_results(run):
run_results = run["results"]

result = {"style": "", "info": []}

# win/loss/draw count
Expand Down
11 changes: 8 additions & 3 deletions server/fishtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,6 @@ def tests_view(request):
raise HTTPNotFound("Resource not found")
follow = 1 if "follow" in request.params else 0
results = run["results"]
run["results_info"] = format_results(results, run)
run_args = [("id", str(run["_id"]), "")]
if run.get("rescheduled_from"):
run_args.append(("rescheduled_from", run["rescheduled_from"], ""))
Expand Down Expand Up @@ -1602,6 +1601,7 @@ def tests_view(request):
return {
"run": run,
"run_args": run_args,
"results_info": format_results(run),
"page_title": get_page_title(run),
"approver": request.has_permission("approve_run"),
"chi2": chi2,
Expand All @@ -1627,7 +1627,7 @@ def get_paginated_finished_runs(request):
page_idx = max(0, int(page_param) - 1) if page_param.isdigit() else 0
page_size = 25

finished_runs, num_finished_runs = request.rundb.get_finished_runs(
finished_runs, results_infos, num_finished_runs = request.rundb.get_finished_runs(
username=username,
success_only=success_only,
yellow_only=yellow_only,
Expand All @@ -1654,6 +1654,7 @@ def get_paginated_finished_runs(request):

return {
"finished_runs": finished_runs,
"results_infos": results_infos,
"finished_runs_pages": pages,
"num_finished_runs": num_finished_runs,
"failed_runs": failed_runs,
Expand Down Expand Up @@ -1693,15 +1694,19 @@ def homepage_results(request):

(
runs,
results_infos,
pending_hours,
cores,
nps,
games_per_minute,
machines_count,
) = request.rundb.aggregate_unfinished_runs()
finished_runs = get_paginated_finished_runs(request)
results_infos.update(finished_runs["results_infos"])
return {
**get_paginated_finished_runs(request),
**finished_runs,
"runs": runs,
"results_infos": results_infos,
"machines_count": machines_count,
"pending_hours": "{:.1f}".format(pending_hours),
"cores": cores,
Expand Down
1 change: 0 additions & 1 deletion server/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ def test_auto_purge_runs(self):
run = self.rundb.get_run(run_id)
self.assertTrue(run["finished"])
self.assertTrue(all([not t["active"] for t in run["tasks"]]))
self.assertTrue("Total: {}".format(num_games) in run["results_info"]["info"][1])


if __name__ == "__main__":
Expand Down

0 comments on commit 6f66fee

Please sign in to comment.