Begin best results report

This commit is contained in:
2023-05-31 23:30:51 +02:00
parent 7d5f3058c3
commit a51fed6281
10 changed files with 149 additions and 80 deletions

View File

@@ -14,4 +14,6 @@ def create_app():
app.register_blueprint(main)
app.config[FRAMEWORK] = config[FRAMEWORK]
app.config[FRAMEWORKS] = ["bootstrap", "bulma"]
app.jinja_env.auto_reload = True
app.config["TEMPLATES_AUTO_RELOAD"] = True
return app

View File

@@ -91,9 +91,12 @@ def datasets(compare):
framework=current_app.config[FRAMEWORK],
)
@main.route("/showfile/<file_name>/<compare>")
def showfile(file_name, compare):
def showfile(file_name, compare, back=None):
compare = compare.capitalize() == "True"
back = request.args["url"] if back is None else back
print(f"back [{back}]")
with open(os.path.join(Folders.results, file_name)) as f:
data = json.load(f)
try:
@@ -106,15 +109,19 @@ def showfile(file_name, compare):
file=file_name,
summary=summary,
framework=current_app.config[FRAMEWORK],
compare=compare,
back=back,
)
@main.route("/show", methods=["post"])
def show():
selected_file = request.form["selected-file"]
compare = request.form["compare"]
return showfile(selected_file, compare)
return showfile(
file_name=selected_file,
compare=compare,
back=url_for("main.index", compare=compare),
)
@main.route("/excel", methods=["post"])
@@ -167,3 +174,13 @@ def config(framework, compare):
current_app.config[FRAMEWORK] = framework
return redirect(url_for("main.index", compare=compare))
@main.route("/best_results/<file>/<compare>")
def best_results(file, compare):
compare = compare.capitalize() == "True"
try:
with open(os.path.join(Folders.results, file)) as f:
data = json.load(f)
except Exception as e:
return render_template("error.html", message=str(e), compare=compare)
return render_template("report_best.html", data=data, compare=compare)

View File

@@ -6,8 +6,8 @@
{%- macro get_table_class() -%}
table table-striped table-hover table-bordered
{%- endmacro -%}
{%- macro icon(icon) -%}
<i class="mdi mdi-{{icon}}"></i>
{%- macro icon(icon_name) -%}
<i class="mdi mdi-{{icon_name}}"></i>
{%- endmacro -%}
{%- macro get_button(text, action) -%}
<button class="btn btn-primary btn-small" onclick="{{ action }}">{{ text|safe }}</button>
@@ -15,8 +15,8 @@ table table-striped table-hover table-bordered
{%- macro get_button_class() -%}
button btn-primary btn-small
{%- endmacro %}
{%- macro get_button_view(file) -%}
<button class="btn btn-primary btn-small" onclick="showFile('{{ file }}')"><i class="mdi mdi-eye"></i></button>
{%- macro get_button_tag(icon_name, method, visible=True, name="") -%}
<button class="btn btn-primary btn-small" onclick="{{ method }}" {{ "" if visible else "hidden='true'" }} {{ "" if name=="" else "name='" + name +"'"}}><i class="mdi mdi-{{ icon_name }}"></i></button>
{%- endmacro -%}
{%- macro get_button_reset() -%}
<button class="btn btn-primary btn-small btn-danger" onclick="setCheckBoxes(false)"><i class="mdi mdi-checkbox-multiple-blank"></i></button>

View File

@@ -8,14 +8,14 @@
{%- macro get_table_class() -%}
table is-striped is-hoverable cell-border is-bordered
{%- endmacro -%}
{%- macro icon(icon) -%}
<i class="mdi mdi-{{icon}}"></i>
{%- macro icon(icon_name) -%}
<i class="mdi mdi-{{icon_name}}"></i>
{%- endmacro -%}
{%- macro get_button(text, action) -%}
<button class="button is-primary is-small" onclick="{{ action }}">{{ text|safe }}</button>
{%- endmacro -%}
{%- macro get_button_view(file) -%}
<span class="tag is-link is-normal" type="button" onclick="showFile('{{ file }}')"><i class="mdi mdi-eye"></i></span>
{%- macro get_button_tag(icon_name, method, visible=True, name="") -%}
<span class="{{ "tag is-link is-normal" if visible else "" }}" type="button" onclick="{{ method }}" {{ "" if visible else "hidden='true'" }} {{ "" if name=="" else "name='" + name +"'"}}>{{icon(icon_name)}}</span>
{%- endmacro -%}
{%- macro get_button_reset() -%}
<span class="tag is-link is-danger" type="button" onclick="setCheckBoxes(false)"><i class="mdi mdi-checkbox-multiple-blank"></i></span>

View File

@@ -1,71 +1,97 @@
$(document).ready(function () {
var table = $('#file-table').DataTable({
"paging": true,
"searching": true,
"ordering": true,
"info": true,
"select.items": "row",
"pageLength": 25,
"columnDefs": [{
"targets": 8,
"orderable": false
}],
//"language": {
// "lengthMenu": "_MENU_"
//}
});
// Check if row is selected
$('#file-table tbody').on('click', 'tr', function () {
if ($(this).hasClass('{{ select.selected() }}')) {
$(this).removeClass('{{ select.selected() }}');
} else {
table.$('tr.{{ select.selected() }}').removeClass('{{ select.selected() }}');
$(this).addClass('{{ select.selected() }}');
}
});
// Show file with doubleclick
$('#file-table tbody').on('dblclick', 'tr', function () {
showFile($(this).attr("id"));
});
$(document).ajaxStart(function(){
$("body").addClass('ajaxLoading');
});
$(document).ajaxStop(function(){
$("body").removeClass('ajaxLoading');
});
var table = $("#file-table").DataTable({
paging: true,
searching: true,
ordering: true,
info: true,
"select.items": "row",
pageLength: 25,
columnDefs: [
{
targets: 8,
orderable: false,
},
],
//"language": {
// "lengthMenu": "_MENU_"
//}
});
// Check if row is selected
$("#file-table tbody").on("click", "tr", function () {
if ($(this).hasClass("{{ select.selected() }}")) {
$(this).removeClass("{{ select.selected() }}");
} else {
table
.$("tr.{{ select.selected() }}")
.removeClass("{{ select.selected() }}");
$(this).addClass("{{ select.selected() }}");
}
});
// Show file with doubleclick
$("#file-table tbody").on("dblclick", "tr", function () {
showFile($(this).attr("id"));
});
$(document).ajaxStart(function () {
$("body").addClass("ajaxLoading");
});
$(document).ajaxStop(function () {
$("body").removeClass("ajaxLoading");
});
$('#compare').change(function() {
if ($(this).is(':checked')) {
$("[name='best_buttons']").removeAttr("hidden");
$("[name='best_buttons']").addClass("tag is-link is-normal");
} else {
$("[name='best_buttons']").attr("hidden", true);
$("[name='best_buttons']").removeClass("tag is-link is-normal");
}
});
if ($('#compare').is(':checked')) {
$("[name='best_buttons']").removeAttr("hidden");
$("[name='best_buttons']").addClass("tag is-link is-normal");
} else {
$("[name='best_buttons']").attr("hidden", true);
$("[name='best_buttons']").removeClass("tag is-link is-normal");
}
});
function showFile(selectedFile) {
var form = $('<form action="/show" method="post">' +
'<input type="hidden" name="selected-file" value="' + selectedFile + '" />' +
'<input type="hidden" name="compare" value='+$("#compare").is(':checked')+' />' +
'</form>');
$('body').append(form);
form.submit();
var form = $(
'<form action="/show" method="post">' +
'<input type="hidden" name="selected-file" value="' +
selectedFile +
'" />' +
'<input type="hidden" name="compare" value=' +
$("#compare").is(":checked") +
" />" +
"</form>"
);
$("body").append(form);
form.submit();
}
function excel() {
var checkbox = document.getElementsByName("selected_files");
var selectedFiles = [];
for (var i = 0; i < checkbox.length; i++) {
if (checkbox[i].checked) {
selectedFiles.push(checkbox[i].value);
}
var checkbox = document.getElementsByName("selected_files");
var selectedFiles = [];
for (var i = 0; i < checkbox.length; i++) {
if (checkbox[i].checked) {
selectedFiles.push(checkbox[i].value);
}
if (selectedFiles.length == 0) {
alert("Select at least one file");
return;
}
var compare = $("#compare").is(':checked');
excelFiles(selectedFiles, compare);
}
if (selectedFiles.length == 0) {
alert("Select at least one file");
return;
}
var compare = $("#compare").is(":checked");
excelFiles(selectedFiles, compare);
}
function setCheckBoxes(value) {
var checkbox = document.getElementsByName("selected_files");
for (i = 0; i < checkbox.length; i++) {
checkbox[i].checked=value;
}
var checkbox = document.getElementsByName("selected_files");
for (i = 0; i < checkbox.length; i++) {
checkbox[i].checked = value;
}
}
function redirectIndex(candidate){
location.href="/config/"+ candidate + "/" + $("#compare").is(':checked');
function redirectDouble(route, parameter) {
location.href = "/"+ route + "/" + parameter + "/" + $("#compare").is(":checked");
}
function redirectSimple(route) {
location.href = "/" + route + "/" + $("#compare").is(":checked");
}
function redirectDatasets(){
location.href="/datasets/" + $("#compare").is(':checked');
}

View File

@@ -2,7 +2,7 @@
<section class="section">
<div class="container-fluid">
<div class="p-4 bg-primary text-white">
<button type="button" class="btn-close" aria-label="Close" onclick="location.href = '/index/{{ compare }}'"></button>
<button type="button" class="btn-close" aria-label="Close" onclick="location.href = '{{back}}'"></button>
<h1>{{ data.title }}</h1>
</div>
<div>

View File

@@ -3,7 +3,7 @@
<div class="container is-fluid">
<div class="hero is-info is-bold">
<div class="hero-body">
<button class="delete is-large" onclick="location.href = '/index/{{ compare }}'"></button>
<button class="delete is-large" onclick="location.href = '{{ back }}'"></button>
<h1 class="is-size-3">{{ data.title }}</h1>
</div>
</div>

View File

@@ -26,7 +26,9 @@
<td>{{ "%s" % data["title"] }}</td>
<td class="{{ select.get_align_right() }}">{{ "%.6f" % data["score"] }}</td>
<td>
{{ select.get_button_view(file) | safe }}
{{ select.get_button_tag("eye", "showFile('" ~ file ~ "')") | safe }}
{% set file_best = "best_results_" ~ parts[1] ~ "_" ~ parts[2] ~ ".json" %}
{{ select.get_button_tag("star-circle-outline", "redirectDouble('best_results', '" ~ file_best ~ "')", visible=False, name="best_buttons") | safe }}
<input
type="checkbox"
name="selected_files"

View File

@@ -2,12 +2,11 @@
{{ select.header("Benchmark Results") }}
<div class="{{ select.get_level_class() }}">
<div class="{{ select.get_left_position() }}">
{{ select.get_button("Use " ~ candidate, "redirectIndex('" ~ candidate ~ "')")|safe }}
{{ select.get_button("Use " ~ candidate, "redirectDouble('config', '" ~ candidate ~ "')")|safe }}
{{ select.get_button(select.icon("excel") ~ " Excel", "excel()")|safe }}
{{ select.get_button(select.icon("database-eye") ~ " Datasets", "redirectDatasets()")|safe }}
{{ select.get_button(select.icon("star-circle-outline") ~ " Best results", "{{ url_for('best_results')}}")}}
{{ select.get_button(select.icon("database-eye") ~ " Datasets", "redirectSimple('datasets')")|safe }}
</div>
<div class={{ select.get_right_position }}>
<div class="{{ select.get_right_position() }}">
<input type="checkbox" id="compare" name="compare" {% if compare %} {{ "checked" }} {% endif %}>
<span class="{{ select.get_tag_class() }}">Comparing with best results</span>
</div>

View File

@@ -0,0 +1,23 @@
<table class="table">
<thead>
<tr>
<th>Dataset</th>
<th>Score</th>
<th>Hyperparameters</th>
<th>File</th>
</tr>
</thead>
<tbody>
{% for dataset, info in data.items() %}
<tr>
<td>{{ dataset }}</td>
<td>{{ '%9.7f' % info[0] }}</td>
<td>{{ info[1] }}</td>
<td>
{% set url = url_for(request.endpoint, **request.view_args)|urlencode %}
<a href="{{ url_for('main.showfile', file_name = info[2], compare = compare) }}?url={{ url }}">{{ info[2] }}</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>