Begin add datasets report with excel

This commit is contained in:
2023-05-30 17:04:33 +02:00
parent dd3cb91951
commit 5f7fb7d5ac
9 changed files with 134 additions and 60 deletions

View File

@@ -7,6 +7,7 @@ from benchmark.Utils import Files, Folders
from benchmark.Arguments import EnvData from benchmark.Arguments import EnvData
from benchmark.ResultsBase import StubReport from benchmark.ResultsBase import StubReport
from benchmark.ResultsFiles import Excel from benchmark.ResultsFiles import Excel
from benchmark.Datasets import Datasets
from flask import Flask from flask import Flask
from flask import render_template, request, redirect, url_for from flask import render_template, request, redirect, url_for
@@ -18,6 +19,25 @@ FRAMEWORKS = "frameworks"
TEST = "test" 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): def process_data(file_name, compare, data):
report = StubReport( report = StubReport(
os.path.join(Folders.results, file_name), compare=compare os.path.join(Folders.results, file_name), compare=compare
@@ -60,6 +80,20 @@ def index(compare="False"):
) )
@app.route("/datasets/<compare>")
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"]) @app.route("/show", methods=["post"])
def show(): def show():
selected_file = request.form["selected-file"] selected_file = request.form["selected-file"]
@@ -85,6 +119,9 @@ def excel():
selected_files = request.json["selectedFiles"] selected_files = request.json["selectedFiles"]
compare = request.json["compare"] compare = request.json["compare"]
book = None book = None
if selected_files[0] == "datasets":
# Create a list of datasets
return AjaxResponse(True, "datasets").to_string()
try: try:
for file_name in selected_files: for file_name in selected_files:
file_name_result = os.path.join(Folders.results, file_name) file_name_result = os.path.join(Folders.results, file_name)
@@ -102,24 +139,13 @@ def excel():
except Exception as e: except Exception as e:
if book is not None: if book is not None:
book.close() book.close()
return ( return AjaxResponse(
json.dumps( False, "Could not create excel file, " + str(e)
{ ).to_string()
"success": False,
"error": "Could not create excel file, " + str(e),
}
),
200,
{"ContentType": "application/json"},
)
if book is not None: if book is not None:
book.close() book.close()
Files.open(file_excel, test=app.config[TEST]) Files.open(file_excel, test=app.config[TEST])
return ( return AjaxResponse(True, Files.be_list_excel).to_string()
json.dumps({"success": True, "file": Files.be_list_excel}),
200,
{"ContentType": "application/json"},
)
@app.route("/config/<framework>/<compare>") @app.route("/config/<framework>/<compare>")

View File

@@ -0,0 +1,30 @@
{% extends "base.html" %}
{% if framework == "bootstrap" %}
{% set close_button = '<button type="button" class="btn-close btn-small" aria-label="Close" onclick="location.href = \'/index/' ~ compare ~ '\'"></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 = '<button class="delete is-large" onclick="location.href = \'/index/' ~ compare ~ '\'"></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 %}
<div class="{{ container }}">
<h1 class="{{ h1_class }}">{{ close_button|safe }} Datasets Report</h1>
<button class="{{ button }}" onclick="excelFiles(['datasets'], false)"><i class="mdi mdi-file-excel"></i> Excel</button>
{% include "partials/datasets_table.html" %}
</div>
{% endblock %}
{% block jscript %}
<script>
{% include "partials/excelFiles.js" %}
</script>
{% endblock %}

View File

@@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block content %}
<table class="{{ table_class }}">
<thead>
<tr class="{{ head_class }}">
<th class="{{ text_center }}">Dataset</th>
<th class="{{ text_center }}">Samples</th>
<th class="{{ text_center }}">Features</th>
<th class="{{ text_center }}">Cont. Feat.</th>
<th class="{{ text_center }}">Classes</th>
<th class="{{ text_center }}">Balance</th>
</tr>
</thead>
<tbody>
{% for dataset in datasets %}
<tr>
<td>{{ dataset.dataset }}</td>
<td class="{{ text_right }}">{{ "{:,}".format(dataset.samples) }}</td>
<td class="{{ text_right }}">{{ "{:,}".format(dataset.features) }}</td>
<td class="{{ text_right }}">{{ dataset.cont_features }}</td>
<td class="{{ text_right }}">{{ dataset.classes }}</td>
<td>{{ dataset.balance }}</td>
<tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@@ -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);
}
});
}

View File

@@ -18,23 +18,5 @@ $(document).ready(function () {
function excelFile() { function excelFile() {
var selectedFiles = ["{{ file }}"]; var selectedFiles = ["{{ file }}"];
var compare = "{{ compare }}" == "True"; var compare = "{{ compare }}" == "True";
var data = { excelFiles(selectedFiles, compare)
"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);
}
});
} }

View File

@@ -55,29 +55,7 @@ function excel() {
return; return;
} }
var compare = $("#compare").is(':checked'); var compare = $("#compare").is(':checked');
// send data to server with ajax post excelFiles(selectedFiles, compare);
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);
}
});
} }
function setCheckBoxes(value) { function setCheckBoxes(value) {
var checkbox = document.getElementsByName("selected_files"); var checkbox = document.getElementsByName("selected_files");
@@ -87,4 +65,7 @@ function setCheckBoxes(value) {
} }
function redirectIndex(candidate){ function redirectIndex(candidate){
location.href="/config/"+ candidate + "/" + $("#compare").is(':checked'); location.href="/config/"+ candidate + "/" + $("#compare").is(':checked');
}
function redirectDatasets(){
location.href="/datasets/" + $("#compare").is(':checked');
} }

View File

@@ -5,6 +5,7 @@
<button class="{{ button_class }}" onclick="redirectIndex('{{candidate}}')">Use {{ candidate <button class="{{ button_class }}" onclick="redirectIndex('{{candidate}}')">Use {{ candidate
}}</button> }}</button>
<button class="{{ button_class }}" onclick="excel()"><i class="mdi mdi-file-excel"></i> Excel</button> <button class="{{ button_class }}" onclick="excel()"><i class="mdi mdi-file-excel"></i> Excel</button>
<button class="{{ button_class }}" onclick="redirectDatasets()"><i class="mdi mdi-database-eye"></i> Datasets</button>
</div> </div>
<div class={{ frtag_position }}> <div class={{ frtag_position }}>
<input type="checkbox" id="compare" name="compare" {% if compare %} {{ "checked" }} {% endif %}> <input type="checkbox" id="compare" name="compare" {% if compare %} {{ "checked" }} {% endif %}>

View File

@@ -20,6 +20,7 @@
{% set selected = "is-selected" %} {% set selected = "is-selected" %}
{% endif %} {% endif %}
<script> <script>
{% include "partials/js_report.js" %} {% include "partials/report.js" %}
{% include "partials/excelFiles.js" %}
</script> </script>
{% endblock %} {% endblock %}

View File

@@ -24,7 +24,7 @@
{% set button_pre = '<span class="tag is-link is-normal" type="button" onclick="showFile(\'' %} {% set button_pre = '<span class="tag is-link is-normal" type="button" onclick="showFile(\'' %}
{% set button_post = '\')"><i class="mdi mdi-eye"></i></span>' %} {% set button_post = '\')"><i class="mdi mdi-eye"></i></span>' %}
{% set selected = "is-selected" %} {% set selected = "is-selected" %}
{% set align_right = "text-end" %} {% set align_right = "has-text-right" %}
{% set level = "level" %} {% set level = "level" %}
{% set tag_class = "tag is-info is-small" %} {% set tag_class = "tag is-info is-small" %}
{% set container = "container is-fluid" %} {% set container = "container is-fluid" %}
@@ -42,7 +42,8 @@
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
{% endif %} {% endif %}
<script> <script>
{% include "partials/js_select.js" %} {% include "partials/select.js" %}
{% include "partials/excelFiles.js" %}
</script> </script>
{% endblock %} {% endblock %}