mirror of
https://github.com/Doctorado-ML/benchmark.git
synced 2025-08-15 23:45:54 +00:00
Generate excel file from results
This commit is contained in:
@@ -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/<framework>")
|
||||
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)
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
@@ -27,6 +27,7 @@
|
||||
<td>{{ "%.6f" % data["score"] }}</td>
|
||||
<td>
|
||||
{{ button_pre | safe }}{{ file }}{{ button_post | safe }}
|
||||
<input type="checkbox" class="{{ checkbox_class }}" name="selected_files" value="{{ file }}">
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
<div class="container">
|
||||
<h1 class="{{ h1_class }}"><b>Benchmark Results</b></h1>
|
||||
<button class="{{ button_class }}" onclick="location.href='/config/{{ candidate }}';">Use {{ candidate
|
||||
<button class="{{ button_class }}" onclick="location.href='/config/{{ candidate }}'">Use {{ candidate
|
||||
}}</button>
|
||||
{% include "partials/table_select.html" %}
|
||||
<input type="button" class="{{ button_class }}" onclick="excel()" value="Excel">
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
|
||||
|
Reference in New Issue
Block a user