From 5f7fb7d5ace5c65b6a1440ebf2845b8bf4fe4ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Tue, 30 May 2023 17:04:33 +0200 Subject: [PATCH] Begin add datasets report with excel --- benchmark/scripts/be_flask.py | 56 ++++++++++++++----- benchmark/scripts/templates/datasets.html | 30 ++++++++++ .../templates/partials/datasets_table.html | 27 +++++++++ .../scripts/templates/partials/excelFiles.js | 25 +++++++++ .../partials/{js_report.js => report.js} | 20 +------ .../partials/{js_select.js => select.js} | 27 ++------- .../partials/table_select_design.html | 1 + benchmark/scripts/templates/report.html | 3 +- benchmark/scripts/templates/select.html | 5 +- 9 files changed, 134 insertions(+), 60 deletions(-) create mode 100644 benchmark/scripts/templates/datasets.html create mode 100644 benchmark/scripts/templates/partials/datasets_table.html create mode 100644 benchmark/scripts/templates/partials/excelFiles.js rename benchmark/scripts/templates/partials/{js_report.js => report.js} (53%) rename benchmark/scripts/templates/partials/{js_select.js => select.js} (75%) diff --git a/benchmark/scripts/be_flask.py b/benchmark/scripts/be_flask.py index 3cbd75b..653cf72 100755 --- a/benchmark/scripts/be_flask.py +++ b/benchmark/scripts/be_flask.py @@ -7,6 +7,7 @@ from benchmark.Utils import Files, Folders from benchmark.Arguments import EnvData from benchmark.ResultsBase import StubReport from benchmark.ResultsFiles import Excel +from benchmark.Datasets import Datasets from flask import Flask from flask import render_template, request, redirect, url_for @@ -18,6 +19,25 @@ FRAMEWORKS = "frameworks" TEST = "test" +class AjaxResponse: + def __init__(self, success, file_name, code=200): + self.success = success + self.file_name = file_name + self.code = code + + def to_string(self): + return ( + json.dumps( + { + "success": self.success, + "file": self.file_name, + } + ), + self.code, + {"ContentType": "application/json"}, + ) + + def process_data(file_name, compare, data): report = StubReport( os.path.join(Folders.results, file_name), compare=compare @@ -60,6 +80,20 @@ def index(compare="False"): ) +@app.route("/datasets/") +def datasets(compare): + dt = Datasets() + datos = [] + for dataset in dt: + datos.append(dt.get_attributes(dataset)) + return render_template( + "datasets.html", + datasets=datos, + compare=compare, + framework=app.config[FRAMEWORK], + ) + + @app.route("/show", methods=["post"]) def show(): selected_file = request.form["selected-file"] @@ -85,6 +119,9 @@ def excel(): selected_files = request.json["selectedFiles"] compare = request.json["compare"] book = None + if selected_files[0] == "datasets": + # Create a list of datasets + return AjaxResponse(True, "datasets").to_string() try: for file_name in selected_files: file_name_result = os.path.join(Folders.results, file_name) @@ -102,24 +139,13 @@ def excel(): except Exception as e: if book is not None: book.close() - return ( - json.dumps( - { - "success": False, - "error": "Could not create excel file, " + str(e), - } - ), - 200, - {"ContentType": "application/json"}, - ) + return AjaxResponse( + False, "Could not create excel file, " + str(e) + ).to_string() if book is not None: book.close() Files.open(file_excel, test=app.config[TEST]) - return ( - json.dumps({"success": True, "file": Files.be_list_excel}), - 200, - {"ContentType": "application/json"}, - ) + return AjaxResponse(True, Files.be_list_excel).to_string() @app.route("/config//") diff --git a/benchmark/scripts/templates/datasets.html b/benchmark/scripts/templates/datasets.html new file mode 100644 index 0000000..84063ab --- /dev/null +++ b/benchmark/scripts/templates/datasets.html @@ -0,0 +1,30 @@ +{% extends "base.html" %} +{% if framework == "bootstrap" %} + {% set close_button = '' %} + {% set button_class = "btn btn-primary btn-small" %} + {% set h1_class = "text-center" %} + {% set table_class = "table table-striped table-hover table-bordered" %} + {% set head_class = "bg-primary text-white" %} + {% set text_right = "text-end" %} + {% set container = "container-fluid" %} +{% else %} + {% set close_button = '' %} + {% set button_class = "button is-primary is-small" %} + {% set h1_class = "title is-1 has-text-centered" %} + {% set table_class = "table is-striped is-hoverable cell-border is-bordered" %} + {% set head_class = "is-selected" %} + {% set text_right = "has-text-right" %} + {% set container = "container is-fluid" %} +{% endif %} +{% block content %} +
+

{{ close_button|safe }} Datasets Report

+ + {% include "partials/datasets_table.html" %} +
+{% endblock %} +{% block jscript %} + +{% endblock %} \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/datasets_table.html b/benchmark/scripts/templates/partials/datasets_table.html new file mode 100644 index 0000000..4bd13ab --- /dev/null +++ b/benchmark/scripts/templates/partials/datasets_table.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} +{% block content %} + + + + + + + + + + + + + {% for dataset in datasets %} + + + + + + + + + {% endfor %} + +
DatasetSamplesFeaturesCont. Feat.ClassesBalance
{{ dataset.dataset }}{{ "{:,}".format(dataset.samples) }}{{ "{:,}".format(dataset.features) }}{{ dataset.cont_features }}{{ dataset.classes }}{{ dataset.balance }}
+{% endblock %} \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/excelFiles.js b/benchmark/scripts/templates/partials/excelFiles.js new file mode 100644 index 0000000..d8e33fa --- /dev/null +++ b/benchmark/scripts/templates/partials/excelFiles.js @@ -0,0 +1,25 @@ +function excelFiles(selectedFiles, compare) { + var data = { + "selectedFiles": selectedFiles, + "compare": compare + }; + // send data to server with ajax post + $.ajax({ + type:'POST', + url:'/excel', + data: JSON.stringify(data), + contentType: "application/json", + dataType: 'json', + success: function(data){ + if (data.success) { + alert("Se ha generado el archivo "+data.file); + } else { + alert(data.file); + } + }, + error: function (xhr, ajaxOptions, thrownError) { + var mensaje = JSON.parse(xhr.responseText || '{\"mensaje\": \"Error indeterminado\"}'); + alert(mensaje.mensaje); + } + }); +} \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/js_report.js b/benchmark/scripts/templates/partials/report.js similarity index 53% rename from benchmark/scripts/templates/partials/js_report.js rename to benchmark/scripts/templates/partials/report.js index 482f9c9..2ad33c5 100644 --- a/benchmark/scripts/templates/partials/js_report.js +++ b/benchmark/scripts/templates/partials/report.js @@ -18,23 +18,5 @@ $(document).ready(function () { function excelFile() { var selectedFiles = ["{{ file }}"]; var compare = "{{ compare }}" == "True"; - var data = { - "selectedFiles": selectedFiles, - "compare": compare - }; - // send data to server with ajax post - $.ajax({ - type:'POST', - url:'/excel', - data: JSON.stringify(data), - contentType: "application/json", - dataType: 'json', - success: function(data){ - alert("Se ha generado el archivo "+data.file); - }, - error: function (xhr, ajaxOptions, thrownError) { - var mensaje = JSON.parse(xhr.responseText || '{\"mensaje\": \"Error indeterminado\"}'); - alert(mensaje.mensaje); - } - }); + excelFiles(selectedFiles, compare) } \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/js_select.js b/benchmark/scripts/templates/partials/select.js similarity index 75% rename from benchmark/scripts/templates/partials/js_select.js rename to benchmark/scripts/templates/partials/select.js index 00af45b..f4eb84f 100644 --- a/benchmark/scripts/templates/partials/js_select.js +++ b/benchmark/scripts/templates/partials/select.js @@ -55,29 +55,7 @@ function excel() { return; } var compare = $("#compare").is(':checked'); - // send data to server with ajax post - var data = { - selectedFiles: selectedFiles, - compare: compare - }; - $.ajax({ - type:'POST', - url:'/excel', - data: JSON.stringify(data), - contentType: "application/json", - dataType: 'json', - success: function(data){ - if (data.success) { - alert("Se ha generado el archivo "+data.file); - } else { - alert(data.error); - } - }, - error: function (xhr, ajaxOptions, thrownError) { - var mensaje = JSON.parse(xhr.responseText || '{\"message\": \"Error indeterminado\"}'); - alert(mensaje.message); - } - }); + excelFiles(selectedFiles, compare); } function setCheckBoxes(value) { var checkbox = document.getElementsByName("selected_files"); @@ -87,4 +65,7 @@ function setCheckBoxes(value) { } function redirectIndex(candidate){ location.href="/config/"+ candidate + "/" + $("#compare").is(':checked'); +} +function redirectDatasets(){ + location.href="/datasets/" + $("#compare").is(':checked'); } \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/table_select_design.html b/benchmark/scripts/templates/partials/table_select_design.html index bfe2ee6..ad0d97e 100644 --- a/benchmark/scripts/templates/partials/table_select_design.html +++ b/benchmark/scripts/templates/partials/table_select_design.html @@ -5,6 +5,7 @@ +
diff --git a/benchmark/scripts/templates/report.html b/benchmark/scripts/templates/report.html index 6ab0303..238660b 100644 --- a/benchmark/scripts/templates/report.html +++ b/benchmark/scripts/templates/report.html @@ -20,6 +20,7 @@ {% set selected = "is-selected" %} {% endif %} {% endblock %} diff --git a/benchmark/scripts/templates/select.html b/benchmark/scripts/templates/select.html index 757c5f0..1787b07 100644 --- a/benchmark/scripts/templates/select.html +++ b/benchmark/scripts/templates/select.html @@ -24,7 +24,7 @@ {% set button_pre = '' %} {% set selected = "is-selected" %} - {% set align_right = "text-end" %} + {% set align_right = "has-text-right" %} {% set level = "level" %} {% set tag_class = "tag is-info is-small" %} {% set container = "container is-fluid" %} @@ -42,7 +42,8 @@ crossorigin="anonymous"> {% endif %} {% endblock %}