diff --git a/benchmark/scripts/be_flask.py b/benchmark/scripts/be_flask.py index 95774f8..9af9c83 100755 --- a/benchmark/scripts/be_flask.py +++ b/benchmark/scripts/be_flask.py @@ -2,9 +2,11 @@ import os import json import webbrowser +import xlsxwriter from benchmark.Utils import Files, Folders from benchmark.Arguments import Arguments, EnvData from benchmark.ResultsBase import StubReport +from benchmark.ResultsFiles import Excel from flask import Flask from flask import render_template, request, redirect, url_for @@ -13,6 +15,8 @@ from flask import render_template, request, redirect, url_for app = Flask(__name__) FRAMEWORK = "framework" FRAMEWORKS = "frameworks" +COMPARE = "compare" +TEST = "test" def process_data(file_name, data): @@ -68,6 +72,34 @@ def show(): ) +@app.route("/excel", methods=["post"]) +def excel(): + if request.is_json: + selected_files = request.json + else: + selected_files = request.form["selected-files"] + book = None + for file_name in selected_files: + file_name_result = os.path.join(Folders.results, file_name) + if book is None: + file_excel = os.path.join(Folders.excel, Files.be_list_excel) + book = xlsxwriter.Workbook(file_excel, {"nan_inf_to_errors": True}) + excel = Excel( + file_name=file_name_result, + book=book, + compare=app.config[COMPARE], + ) + excel.report() + 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"}, + ) + + @app.route("/config/") def config(framework): if not framework in app.config[FRAMEWORKS]: @@ -82,14 +114,15 @@ def config(framework): def main(args_test=None): - # arguments = Arguments(prog="be_flask") - # arguments.xset("model", required=False) - # arguments.xset("score", required=False).xset("compare") - # arguments.xset("nan") - # args = arguments.parse(args_test) + arguments = Arguments(prog="be_flask") + arguments.xset("model", required=False) + arguments.xset("score", required=False).xset("compare") + args = arguments.parse(args_test) config = EnvData().load() app.config[FRAMEWORK] = config[FRAMEWORK] + app.config[COMPARE] = args.compare app.config[FRAMEWORKS] = ["bootstrap", "bulma"] + app.config[TEST] = args_test is not None webbrowser.open_new("http://127.0.0.1:1234/") app.run(port=1234) diff --git a/benchmark/scripts/templates/partials/js_select.html b/benchmark/scripts/templates/partials/js_select.html index 96bb38a..2593b27 100644 --- a/benchmark/scripts/templates/partials/js_select.html +++ b/benchmark/scripts/templates/partials/js_select.html @@ -28,4 +28,32 @@ $('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); + } + } + if (selectedFiles.length == 0) { + alert("Select at least one file"); + return; + } + // send data to server with ajax post + $.ajax({ + type:'POST', + url:'/excel', + data: JSON.stringify(selectedFiles), + 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); + } + }); + } \ No newline at end of file diff --git a/benchmark/scripts/templates/partials/table_select.html b/benchmark/scripts/templates/partials/table_select.html index a313e49..40357f5 100644 --- a/benchmark/scripts/templates/partials/table_select.html +++ b/benchmark/scripts/templates/partials/table_select.html @@ -27,6 +27,7 @@ {{ "%.6f" % data["score"] }} {{ button_pre | safe }}{{ file }}{{ button_post | safe }} + {% endfor %} diff --git a/benchmark/scripts/templates/partials/table_select_design.html b/benchmark/scripts/templates/partials/table_select_design.html index 7c88002..8a71dd2 100644 --- a/benchmark/scripts/templates/partials/table_select_design.html +++ b/benchmark/scripts/templates/partials/table_select_design.html @@ -1,8 +1,9 @@

Benchmark Results

- {% include "partials/table_select.html" %} +