mirror of
https://github.com/Doctorado-ML/beflask.git
synced 2025-08-16 15:45:51 +00:00
Add datasets and enhance select
This commit is contained in:
BIN
app/app.db
BIN
app/app.db
Binary file not shown.
@@ -1,17 +1,26 @@
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
dotenv_file = ".env"
|
||||||
basedir = os.path.abspath(os.path.dirname(__file__))
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||||
load_dotenv(os.path.join(basedir, ".env"))
|
load_dotenv(os.path.join(basedir, dotenv_file))
|
||||||
|
|
||||||
|
|
||||||
class Config(object):
|
class Config(object):
|
||||||
FRAMEWORKS = ["bootstrap", "bulma"]
|
FRAMEWORKS = ["bootstrap", "bulma"]
|
||||||
FRAMEWORK = os.environ.get("FRAMEWORK") or FRAMEWORKS[0]
|
FRAMEWORK = os.environ.get("FRAMEWORK") or FRAMEWORKS[0]
|
||||||
OUTPUT = os.environ.get("OUTPUT") or "local" # local or docker
|
OUTPUT = os.environ.get("OUTPUT") or "local" # local or docker
|
||||||
|
COMPARE = os.environ.get("COMPARE") == "True" or False
|
||||||
TEMPLATES_AUTO_RELOAD = True
|
TEMPLATES_AUTO_RELOAD = True
|
||||||
SECRET_KEY = os.environ.get("SECRET_KEY") or "really-hard-to-guess-key"
|
SECRET_KEY = os.environ.get("SECRET_KEY") or "really-hard-to-guess-key"
|
||||||
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
SQLALCHEMY_DATABASE_URI = os.environ.get(
|
||||||
"DATABASE_URL"
|
"DATABASE_URL"
|
||||||
) or "sqlite:///" + os.path.join(basedir, "app.db")
|
) or "sqlite:///" + os.path.join(basedir, "app.db")
|
||||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def save():
|
||||||
|
with open(dotenv_file, "w") as f:
|
||||||
|
f.write("FRAMEWORK=" + Config.FRAMEWORK + "\n")
|
||||||
|
f.write("OUTPUT=" + Config.OUTPUT + "\n")
|
||||||
|
f.write("COMPARE=" + str(Config.COMPARE) + "\n")
|
||||||
|
3
app/env.dist
Normal file
3
app/env.dist
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
OUTPUT="local"
|
||||||
|
FRAMEWORK="bulma"
|
||||||
|
COMPARE="True"
|
@@ -1,16 +1,16 @@
|
|||||||
import os
|
import os
|
||||||
|
import json
|
||||||
from benchmark.Utils import Files, Folders
|
from benchmark.Utils import Files, Folders
|
||||||
from benchmark.ResultsBase import StubReport
|
from benchmark.ResultsBase import StubReport
|
||||||
|
from benchmark.Datasets import Datasets
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from flask import Blueprint, current_app, send_file
|
from flask import Blueprint, current_app, send_file
|
||||||
from flask import render_template, current_app, request, redirect, url_for
|
from flask import render_template, current_app, request, redirect, url_for
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
# import json
|
|
||||||
# import shutil
|
# import shutil
|
||||||
# import xlsxwriter
|
# import xlsxwriter
|
||||||
# from benchmark.ResultsFiles import Excel, ReportDatasets
|
# from benchmark.ResultsFiles import Excel, ReportDatasets
|
||||||
# from benchmark.Datasets import Datasets
|
|
||||||
|
|
||||||
results = Blueprint("results", __name__, template_folder="templates")
|
results = Blueprint("results", __name__, template_folder="templates")
|
||||||
|
|
||||||
@@ -43,5 +43,59 @@ def select(compare="False"):
|
|||||||
|
|
||||||
@results.route("/datasets")
|
@results.route("/datasets")
|
||||||
@login_required
|
@login_required
|
||||||
def datasets(compare="False"):
|
def datasets():
|
||||||
return render_template("test.html")
|
os.chdir(current_user.benchmark.folder)
|
||||||
|
dt = Datasets()
|
||||||
|
datos = []
|
||||||
|
for dataset in dt:
|
||||||
|
datos.append(dt.get_attributes(dataset))
|
||||||
|
return render_template("datasets.html", datasets=datos)
|
||||||
|
|
||||||
|
|
||||||
|
@results.route("/best/<file_name>")
|
||||||
|
@login_required
|
||||||
|
def best(file_name):
|
||||||
|
os.chdir(current_user.benchmark.folder)
|
||||||
|
dt = Datasets()
|
||||||
|
datos = []
|
||||||
|
for dataset in dt:
|
||||||
|
datos.append(dt.get_attributes(dataset))
|
||||||
|
return render_template("datasets.html", datasets=datos)
|
||||||
|
|
||||||
|
|
||||||
|
@results.route("/report/<file_name>")
|
||||||
|
@login_required
|
||||||
|
def report(file_name):
|
||||||
|
os.chdir(current_user.benchmark.folder)
|
||||||
|
with open(os.path.join(Folders.results, file_name)) as f:
|
||||||
|
data = json.load(f)
|
||||||
|
try:
|
||||||
|
compare = current_app.config["COMPARE"]
|
||||||
|
summary = process_data(file_name, compare, data)
|
||||||
|
except Exception as e:
|
||||||
|
return render_template("error.html", message=str(e), compare=compare)
|
||||||
|
return render_template(
|
||||||
|
"report.html",
|
||||||
|
data=data,
|
||||||
|
file=file_name,
|
||||||
|
summary=summary,
|
||||||
|
framework=current_app.config["FRAMEWORK"],
|
||||||
|
back=back,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def process_data(file_name, compare, data):
|
||||||
|
report = StubReport(
|
||||||
|
os.path.join(Folders.results, file_name), compare=compare
|
||||||
|
)
|
||||||
|
new_list = []
|
||||||
|
for result in data["results"]:
|
||||||
|
symbol = report._compute_status(result["dataset"], result["score"])
|
||||||
|
result["symbol"] = symbol if symbol != " " else " "
|
||||||
|
new_list.append(result)
|
||||||
|
data["results"] = new_list
|
||||||
|
# Compute summary with explanation of symbols
|
||||||
|
summary = {}
|
||||||
|
for key, value in report._compare_totals.items():
|
||||||
|
summary[key] = (report._status_meaning(key), value)
|
||||||
|
return summary
|
||||||
|
25
app/results/templates/_table_datasets.html
Normal file
25
app/results/templates/_table_datasets.html
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<table id="file-table"
|
||||||
|
class="table table-striped table-hover table-bordered bg-light">
|
||||||
|
<thead>
|
||||||
|
<tr class="bg-primary text-white">
|
||||||
|
<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-end">{{ "{:,}".format(dataset.samples) }}</td>
|
||||||
|
<td class="text-end">{{ "{:,}".format(dataset.features) }}</td>
|
||||||
|
<td class="text-end">{{ dataset.cont_features }}</td>
|
||||||
|
<td class="text-end">{{ dataset.classes }}</td>
|
||||||
|
<td>{{ dataset.balance }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
@@ -1,7 +1,7 @@
|
|||||||
{%- macro get_button_tag(icon_name, method, visible=True, name="") -%}
|
<div class="float-right">
|
||||||
<button class="btn btn-primary btn-small" onclick="{{ method }}" {{ "" if visible else "hidden='true'" }} {{ "" if name=="" else "name='" + name +"'"}}><i class="mdi mdi-{{ icon_name }}"></i>
|
<input type="checkbox" id="compare" name="compare" {% if config["COMPARE"] %}{{ "checked" }}{% endif %}>
|
||||||
</button>
|
<span class="badge bg-info bg-small" onclick="$('#compare').click()">Comparing with best results</span>
|
||||||
{%- endmacro -%}
|
</div>
|
||||||
<table id="file-table"
|
<table id="file-table"
|
||||||
class="table table-striped table-hover table-bordered">
|
class="table table-striped table-hover table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -39,9 +39,17 @@
|
|||||||
<td>{{ "%s" % data["title"] }}</td>
|
<td>{{ "%s" % data["title"] }}</td>
|
||||||
<td class="text-end">{{ "%.6f" % data["score"] }}</td>
|
<td class="text-end">{{ "%.6f" % data["score"] }}</td>
|
||||||
<td>
|
<td>
|
||||||
{{ get_button_tag("table-eye", "showFile('" ~ file ~ "') ") | safe }}
|
|
||||||
{% set file_best = "best_results_" ~ parts[1] ~ "_" ~ parts[2] ~ ".json" %}
|
{% set file_best = "best_results_" ~ parts[1] ~ "_" ~ parts[2] ~ ".json" %}
|
||||||
{{ get_button_tag("star-circle-outline", "redirectDouble('best_results', '" ~ file_best ~ "') ", visible=False, name="best_buttons") | safe }}
|
<button class="btn btn-primary btn-small"
|
||||||
|
onclick="{{ url_for("results.report", file_name=file) }}">
|
||||||
|
<i class="mdi mdi-table-eye"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-primary btn-small"
|
||||||
|
onclick="{{ url_for("results.best", file_name=file_best) }}"
|
||||||
|
hidden="true"
|
||||||
|
name="best_buttons">
|
||||||
|
<i class="mdi mdi-star-circle-outline"></i>
|
||||||
|
</button>
|
||||||
<input type="checkbox" name="selected_files" value="{{ file }}" />
|
<input type="checkbox" name="selected_files" value="{{ file }}" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
26
app/results/templates/datasets.html
Normal file
26
app/results/templates/datasets.html
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
{% include "_table_datasets.html" %}
|
||||||
|
{% endblock %}
|
||||||
|
{% block jscript %}
|
||||||
|
{{ super() }}
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$(document).ajaxStart(function(){
|
||||||
|
$("body").addClass('ajaxLoading');
|
||||||
|
});
|
||||||
|
$(document).ajaxStop(function(){
|
||||||
|
$("body").removeClass('ajaxLoading');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// Check if row is selected
|
||||||
|
$('#file-table tbody').on('click', 'tr', function () {
|
||||||
|
if ($(this).hasClass('selected')) {
|
||||||
|
$(this).removeClass('selected');
|
||||||
|
} else {
|
||||||
|
$('#file-table tbody tr.selected').removeClass("selected")
|
||||||
|
$(this).addClass('selected');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
Reference in New Issue
Block a user