From a51fed6281e19bd22ede43ac37e96a43fe35cb1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana?= Date: Wed, 31 May 2023 23:30:51 +0200 Subject: [PATCH] Begin best results report --- benchmark/scripts/app/app.py | 2 + benchmark/scripts/app/main.py | 25 ++- .../partials/cfg_select_bootstrap.jinja | 8 +- .../templates/partials/cfg_select_bulma.jinja | 8 +- .../scripts/app/templates/partials/select.js | 148 ++++++++++-------- .../partials/table_report_bootstrap.html | 2 +- .../partials/table_report_bulma.html | 2 +- .../app/templates/partials/table_select.html | 4 +- .../partials/table_select_design.html | 7 +- .../scripts/app/templates/report_best.html | 23 +++ 10 files changed, 149 insertions(+), 80 deletions(-) create mode 100644 benchmark/scripts/app/templates/report_best.html diff --git a/benchmark/scripts/app/app.py b/benchmark/scripts/app/app.py index 46258da..8b286cb 100755 --- a/benchmark/scripts/app/app.py +++ b/benchmark/scripts/app/app.py @@ -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 diff --git a/benchmark/scripts/app/main.py b/benchmark/scripts/app/main.py index c858c0e..3c71260 100755 --- a/benchmark/scripts/app/main.py +++ b/benchmark/scripts/app/main.py @@ -91,9 +91,12 @@ def datasets(compare): framework=current_app.config[FRAMEWORK], ) + @main.route("/showfile//") -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//") +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) diff --git a/benchmark/scripts/app/templates/partials/cfg_select_bootstrap.jinja b/benchmark/scripts/app/templates/partials/cfg_select_bootstrap.jinja index b7e33ed..f530810 100644 --- a/benchmark/scripts/app/templates/partials/cfg_select_bootstrap.jinja +++ b/benchmark/scripts/app/templates/partials/cfg_select_bootstrap.jinja @@ -6,8 +6,8 @@ {%- macro get_table_class() -%} table table-striped table-hover table-bordered {%- endmacro -%} -{%- macro icon(icon) -%} - +{%- macro icon(icon_name) -%} + {%- endmacro -%} {%- macro get_button(text, action) -%} @@ -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) -%} - +{%- macro get_button_tag(icon_name, method, visible=True, name="") -%} + {%- endmacro -%} {%- macro get_button_reset() -%} diff --git a/benchmark/scripts/app/templates/partials/cfg_select_bulma.jinja b/benchmark/scripts/app/templates/partials/cfg_select_bulma.jinja index 47fdd89..862074a 100644 --- a/benchmark/scripts/app/templates/partials/cfg_select_bulma.jinja +++ b/benchmark/scripts/app/templates/partials/cfg_select_bulma.jinja @@ -8,14 +8,14 @@ {%- macro get_table_class() -%} table is-striped is-hoverable cell-border is-bordered {%- endmacro -%} -{%- macro icon(icon) -%} - +{%- macro icon(icon_name) -%} + {%- endmacro -%} {%- macro get_button(text, action) -%} {%- endmacro -%} -{%- macro get_button_view(file) -%} - +{%- macro get_button_tag(icon_name, method, visible=True, name="") -%} + {{icon(icon_name)}} {%- endmacro -%} {%- macro get_button_reset() -%} diff --git a/benchmark/scripts/app/templates/partials/select.js b/benchmark/scripts/app/templates/partials/select.js index ab76399..4baf072 100644 --- a/benchmark/scripts/app/templates/partials/select.js +++ b/benchmark/scripts/app/templates/partials/select.js @@ -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 = $('
' + - '' + - '' + - '
'); - $('body').append(form); - form.submit(); + var form = $( + '
' + + '' + + '
- +

{{ data.title }}

diff --git a/benchmark/scripts/app/templates/partials/table_report_bulma.html b/benchmark/scripts/app/templates/partials/table_report_bulma.html index 886f184..86859e7 100644 --- a/benchmark/scripts/app/templates/partials/table_report_bulma.html +++ b/benchmark/scripts/app/templates/partials/table_report_bulma.html @@ -3,7 +3,7 @@
- +

{{ data.title }}

diff --git a/benchmark/scripts/app/templates/partials/table_select.html b/benchmark/scripts/app/templates/partials/table_select.html index dfa1649..f74e4b4 100644 --- a/benchmark/scripts/app/templates/partials/table_select.html +++ b/benchmark/scripts/app/templates/partials/table_select.html @@ -26,7 +26,9 @@ {{ "%s" % data["title"] }} {{ "%.6f" % data["score"] }} - {{ 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 }}
- {{ 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 }}
-
+
Comparing with best results
diff --git a/benchmark/scripts/app/templates/report_best.html b/benchmark/scripts/app/templates/report_best.html new file mode 100644 index 0000000..b4092ab --- /dev/null +++ b/benchmark/scripts/app/templates/report_best.html @@ -0,0 +1,23 @@ + + + + + + + + + + + {% for dataset, info in data.items() %} + + + + + + + {% endfor %} + +
DatasetScoreHyperparametersFile
{{ dataset }}{{ '%9.7f' % info[0] }}{{ info[1] }} + {% set url = url_for(request.endpoint, **request.view_args)|urlencode %} + {{ info[2] }} +