mirror of
https://github.com/Doctorado-ML/beflask.git
synced 2025-08-15 23:25:51 +00:00
Add dataset report
This commit is contained in:
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"[python]": {
|
||||
"editor.defaultFormatter": "ms-python.black-formatter"
|
||||
},
|
||||
"python.formatting.provider": "none"
|
||||
}
|
BIN
app/app.db
BIN
app/app.db
Binary file not shown.
@@ -15,6 +15,7 @@ from flask import (
|
||||
send_file,
|
||||
url_for,
|
||||
)
|
||||
from dotenv import dotenv_values
|
||||
from flask_login import current_user, login_required
|
||||
|
||||
results = Blueprint("results", __name__, template_folder="templates")
|
||||
@@ -84,6 +85,7 @@ def best(file_name):
|
||||
message=f"This best results file ({file_name}) has not been "
|
||||
"created yet! or...",
|
||||
error=str(e),
|
||||
back=url_for("results.select"),
|
||||
)
|
||||
info = file_name.split("_")
|
||||
model = info[3].split(".")[0]
|
||||
@@ -103,14 +105,22 @@ def set_compare():
|
||||
def report(file_name):
|
||||
os.chdir(current_user.benchmark.folder)
|
||||
back = request.args.get("url") or ""
|
||||
back_name = request.args.get("url_name") or ""
|
||||
with open(os.path.join(Folders.results, file_name)) as f:
|
||||
data = json.load(f)
|
||||
try:
|
||||
summary = process_data(file_name, current_app.config["COMPARE"], data)
|
||||
except Exception as e:
|
||||
return render_template("error.html", message=str(e))
|
||||
return render_template(
|
||||
"error.html", message=str(e), back=url_for("results.select")
|
||||
)
|
||||
return render_template(
|
||||
"report.html", data=data, file=file_name, summary=summary, back=back
|
||||
"report.html",
|
||||
data=data,
|
||||
file=file_name,
|
||||
summary=summary,
|
||||
back=back,
|
||||
back_name=back_name,
|
||||
)
|
||||
|
||||
|
||||
@@ -177,3 +187,35 @@ def download(file_name):
|
||||
os.chdir(current_app.root_path)
|
||||
shutil.copyfile(src, dest)
|
||||
return send_file(dest, as_attachment=True)
|
||||
|
||||
|
||||
@results.route("/dataset_report/<dataset>")
|
||||
@login_required
|
||||
def dataset_report(dataset):
|
||||
# Get info of the results obtained for a dataset
|
||||
os.chdir(current_user.benchmark.folder)
|
||||
app_config = dotenv_values(".env")
|
||||
dt = Datasets()
|
||||
data = dt.get_attributes(dataset)
|
||||
names = Files.get_all_results(hidden=False)
|
||||
results = {}
|
||||
for name in names:
|
||||
try:
|
||||
with open(os.path.join(Folders.results, name)) as f:
|
||||
data = json.load(f)
|
||||
for result in data["results"]:
|
||||
if dataset == result["dataset"]:
|
||||
results[name] = result
|
||||
except Exception as e:
|
||||
return render_template(
|
||||
"error.html",
|
||||
message=f"Couldn't process file ({name})",
|
||||
error=str(e),
|
||||
back=url_for("results.dataset_report", dataset=dataset),
|
||||
)
|
||||
return render_template(
|
||||
"dataset.html",
|
||||
dataset_name=dataset,
|
||||
results=results,
|
||||
app_config=app_config,
|
||||
)
|
||||
|
@@ -4,9 +4,9 @@
|
||||
<button type="button"
|
||||
class="btn btn-primary position-relative"
|
||||
onclick="location.href='{{ back }}'">
|
||||
Back to Best Results Report
|
||||
Back to {{ back_name }}
|
||||
<span class="position-absolute top-0 start-100 translate-middle p-2 bg-danger border border-light rounded-circle">
|
||||
<span class="visually-hidden">Back to Best Results Report</span>
|
||||
<span class="visually-hidden">Back to {{ back_name }}</span>
|
||||
</span>
|
||||
</button>
|
||||
{% endif %}
|
||||
@@ -85,7 +85,7 @@
|
||||
data-field="time"
|
||||
data-sortable="true"
|
||||
data-sorter="remove_plus">Time</th>
|
||||
<th class="text-center" data-field="hyperparameters" data-sortable="true">hyperparameters</th>
|
||||
<th class="text-center" data-field="hyperparameters" data-sortable="true">Hyperparameters</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<script>
|
||||
@@ -103,7 +103,9 @@
|
||||
<tbody>
|
||||
{% for item in data.results %}
|
||||
<tr>
|
||||
<td>{{ item.dataset }}</td>
|
||||
<td class="text-left">
|
||||
<a href="{{ url_for("results.dataset_report", dataset=item.dataset) }}">{{ item.dataset }}</a>
|
||||
</td>
|
||||
<td class="text-end">{{ '{:,}'.format(item.samples) }}</td>
|
||||
<td class="text-end">{{"%d" % item.features}}</td>
|
||||
<td class="text-end">{{"%d" % item.classes}}</td>
|
||||
|
@@ -1,4 +1,4 @@
|
||||
{% extends "base.html" %}
|
||||
{% extends "report_tables.html" %}
|
||||
{% block content %}
|
||||
<div class="alert alert-primary" role="alert">
|
||||
<h3>{{ title }}</h3>
|
||||
@@ -15,12 +15,14 @@
|
||||
<tbody>
|
||||
{% for dataset, info in data.items() %}
|
||||
<tr>
|
||||
<td>{{ dataset }}</td>
|
||||
<td class="text-left">
|
||||
<a href="{{ url_for("results.dataset_report", dataset=dataset) }}">{{ dataset }}</a>
|
||||
</td>
|
||||
<td class="text-end">{{ '%9.7f' % info[0] }}</td>
|
||||
<td class="text-center">{{ info[1] }}</td>
|
||||
<td>
|
||||
{% set url = url_for(request.endpoint, **request.view_args)|urlencode %}
|
||||
<a href="{{ url_for('results.report', file_name = info[2]) }}?url={{ url }}">{{ info[2] }}</a>
|
||||
<a href="{{ url_for('results.report', file_name = info[2]) }}?url={{ url }}&url_name=Best Results Report">{{ info[2] }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
46
app/results/templates/dataset.html
Normal file
46
app/results/templates/dataset.html
Normal file
@@ -0,0 +1,46 @@
|
||||
{% extends "report_tables.html" %}
|
||||
{% block content %}
|
||||
<div class="alert alert-primary" role="alert">
|
||||
<h3>Results for {{ dataset_name }}</h3>
|
||||
</div>
|
||||
<table id="files-table"
|
||||
class="table table-striped table-hover table-bordered bg-light"
|
||||
data-toggle="table"
|
||||
data-sticky-header="true"
|
||||
data-sticky-header-offset-y="50"
|
||||
data-sortable="true">
|
||||
<thead>
|
||||
<tr class="bg-primary text-white">
|
||||
<th class="text-center" data-field="file" data-sortable="true">File Name</th>
|
||||
<th class="text-center" data-field="samples" data-sortable="true">Samples</th>
|
||||
<th class="text-center" data-field="features" data-sortable="true">Features</th>
|
||||
<th class="text-center" data-field="classes" data-sortable="true">Classes</th>
|
||||
<th class="text-center" data-field="nodes" data-sortable="true">{{ app_config.nodes }}</th>
|
||||
<th class="text-center" data-field="leaves" data-sortable="true">{{ app_config.leaves }}</th>
|
||||
<th class="text-center" data-field="depth" data-sortable="true">{{ app_config.depth }}</th>
|
||||
<th class="text-center" data-field="score" data-sortable="true">Score</th>
|
||||
<th class="text-center" data-field="time" data-sortable="true">Time</th>
|
||||
<th class="text-center" data-field="hyperparameters" data-sortable="true">Hyperparameters</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for file_name, item in results.items() %}
|
||||
<tr>
|
||||
<td class="text-left">
|
||||
{% set url = url_for(request.endpoint, **request.view_args)|urlencode %}
|
||||
<a href="{{ url_for('results.report', file_name=file_name) }}?url={{ url }}&url_name={{ dataset_name }} report">{{ file_name }}</a>
|
||||
</td>
|
||||
<td class="text-end">{{ '{:,}'.format(item.samples) }}</td>
|
||||
<td class="text-end">{{"%d" % item.features}}</td>
|
||||
<td class="text-end">{{"%d" % item.classes}}</td>
|
||||
<td class="text-end">{{ '{:,.2f}'.format(item.nodes) }}</td>
|
||||
<td class="text-end">{{ '{:,}'.format(item.leaves) }}</td>
|
||||
<td class="text-end">{{ '{:,}'.format(item.depth) }}</td>
|
||||
<td class="text-end">{{"%.6f±%.4f" % (item.score, item.score_std)}}</td>
|
||||
<td class="text-end">{{"%.6f±%.4f" % (item.time, item.time_std)}}</td>
|
||||
<td class="text-left">{{ item.hyperparameters }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
@@ -240,7 +240,8 @@
|
||||
<hr>
|
||||
<div class='_1'>{{ message }}</div>
|
||||
<div class='_2'>{{ error }}</div>
|
||||
<a class='btn' href='/'>Go Back</a>
|
||||
{% set back_url = back | default('/') %}
|
||||
<a class='btn' href='{{ back_url }}'>Go Back</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@@ -1,20 +1,9 @@
|
||||
{% extends "base.html" %}
|
||||
{% block styles %}
|
||||
{{ super() }}
|
||||
<link rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet"
|
||||
href="https://unpkg.com/bootstrap-table@1.21.4/dist/bootstrap-table.min.css">
|
||||
<link href="https://unpkg.com/bootstrap-table@1.21.4/dist/extensions/sticky-header/bootstrap-table-sticky-header.css"
|
||||
rel="stylesheet">
|
||||
{% endblock %}
|
||||
{% extends "report_tables.html" %}
|
||||
{% block content %}
|
||||
{% include "_table_report.html" %}
|
||||
{% endblock %}
|
||||
{% block jscript %}
|
||||
{{ super() }}
|
||||
<script src="https://unpkg.com/bootstrap-table@1.21.4/dist/bootstrap-table.min.js"></script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.21.4/dist/extensions/sticky-header/bootstrap-table-sticky-header.min.js"></script>
|
||||
<script src="{{ url_for('static', filename="js/report.js") }}"></script>
|
||||
<script src="{{ url_for('static', filename="js/excelFiles.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
17
app/results/templates/report_tables.html
Normal file
17
app/results/templates/report_tables.html
Normal file
@@ -0,0 +1,17 @@
|
||||
{% extends "base.html" %}
|
||||
{% block styles %}
|
||||
{{ super() }}
|
||||
<link rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet"
|
||||
href="https://unpkg.com/bootstrap-table@1.21.4/dist/bootstrap-table.min.css">
|
||||
<link href="https://unpkg.com/bootstrap-table@1.21.4/dist/extensions/sticky-header/bootstrap-table-sticky-header.css"
|
||||
rel="stylesheet">
|
||||
{% endblock %}
|
||||
{% block content %}{% endblock %}
|
||||
{% block jscript %}
|
||||
{{ super() }}
|
||||
<script src="https://unpkg.com/bootstrap-table@1.21.4/dist/bootstrap-table.min.js"></script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.21.4/dist/extensions/sticky-header/bootstrap-table-sticky-header.min.js"></script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.21.4/dist/extensions/multiple-sort/bootstrap-table-multiple-sort.js"></script>
|
||||
{% endblock %}
|
@@ -1,21 +1,9 @@
|
||||
{% extends "base.html" %}
|
||||
{% block styles %}
|
||||
{{ super() }}
|
||||
<link rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.7.2/font/bootstrap-icons.css">
|
||||
<link rel="stylesheet"
|
||||
href="https://unpkg.com/bootstrap-table@1.21.4/dist/bootstrap-table.min.css">
|
||||
<link href="https://unpkg.com/bootstrap-table@1.21.4/dist/extensions/sticky-header/bootstrap-table-sticky-header.css"
|
||||
rel="stylesheet">
|
||||
{% endblock %}
|
||||
{% extends "report_tables.html" %}
|
||||
{% block content %}
|
||||
{% include "_table_select.html" %}
|
||||
{% endblock %}
|
||||
{% block jscript %}
|
||||
{{ super() }}
|
||||
<script src="https://unpkg.com/bootstrap-table@1.21.4/dist/bootstrap-table.min.js"></script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.21.4/dist/extensions/sticky-header/bootstrap-table-sticky-header.min.js"></script>
|
||||
<script src="https://unpkg.com/bootstrap-table@1.21.4/dist/extensions/multiple-sort/bootstrap-table-multiple-sort.js"></script>
|
||||
<script src="{{ url_for('static', filename="js/select.js") }}"></script>
|
||||
<script src="{{ url_for('static', filename="js/excelFiles.js") }}"></script>
|
||||
{% endblock %}
|
||||
|
Reference in New Issue
Block a user