in agents/report_web_viewer/img_browse.py [0:0]
def auccess_report(file_path, request):
stride = int(request.args.get("stride", 1))
template_group = request.args.get("Template Group", False) == "on"
one_per_template = request.args.get("Template Results", False) == "on"
num_actions_to_plot = int(request.args.get("num_to_plot", 50))
num_actions_to_anim = int(request.args.get("num_to_anim", 4))
template_to_display = int(request.args.get("template", -1))
with open(file_path) as file_io:
report = file_io.read()
table = {}
actions_table ={}
templates = set()
for line in report.split("\n"):
if not line:
continue
line = line.split(",")
identifier, score = line[0], line[1]
score = float(score)
if ":" in identifier:
template, task_no = identifier.split(":")
table[(template, task_no)] = score
templates.add(template)
if len(line) > 2:
actions = line[2].replace("-", ",").split(";")
actions_table[(template, task_no)] = actions
template_means = {
template: np.mean(
list(
map(lambda x: x[1],
filter(lambda x: x[0][0] == template, table.items()))))
for template in templates
}
lexographic = [(template_means[key[0]], key[0], score, key[1])
for key, score in table.items()]
if template_to_display!= -1:
template_to_display = "%05d" % template_to_display
lexographic = [entry for entry in lexographic if entry[1] == template_to_display]
if template_group:
lexographic.sort(reverse=True)
else:
lexographic.sort(key=lambda x: (x[2], x[1], x[3]), reverse=True)
lexographic = lexographic[::stride]
if one_per_template:
new_records = []
for record in lexographic:
if not any(x[1] == record[1] for x in new_records):
new_records.append(record)
lexographic = new_records
if template_group:
i = 0
lexographic.insert(0, "sep")
while i < len(lexographic) - 1:
if lexographic[i][1] != lexographic[i + 1][1] and ("sep" not in (
lexographic[i], lexographic[i + 1])):
lexographic.insert(i + 1, "sep")
i += 1
actions_to_anim = {key: ';'.join(actions[:num_actions_to_anim]) for key, actions in actions_table.items()}
actions_to_plot = {key: ";".join(actions[:num_actions_to_plot]) for key, actions in actions_table.items()}
# import ipdb; ipdb.set_trace()
return render_template("auccess_report.html",
img_dir=img_dir,
gif_dir=gif_dir,
join=os.path.join,
enumerate=enumerate,
records=lexographic,
template_results=one_per_template,
num_to_plot=num_actions_to_plot,
num_to_anim=num_actions_to_anim,
actions_to_anim=actions_to_anim,
actions_to_plot=actions_to_plot)