mirror of
https://github.com/Doctorado-ML/beflask.git
synced 2025-08-16 07:35:51 +00:00
First approach on ranking
This commit is contained in:
@@ -5,7 +5,7 @@ from flask_login import LoginManager
|
||||
from .config import Config
|
||||
from .models import User, db
|
||||
|
||||
from .results.main_select import results
|
||||
from .results.main_results import results
|
||||
from .admin.main_admin import admin
|
||||
from .main import main
|
||||
|
||||
|
8
app/results/forms.py
Normal file
8
app/results/forms.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import SubmitField, SelectField
|
||||
from benchmark.Arguments import ALL_METRICS
|
||||
|
||||
|
||||
class RankingForm(FlaskForm):
|
||||
score = SelectField("Score", choices=ALL_METRICS)
|
||||
submit = SubmitField("Generate Ranking")
|
@@ -5,7 +5,7 @@ import shutil
|
||||
import xlsxwriter
|
||||
from benchmark.Datasets import Datasets
|
||||
from benchmark.ResultsBase import StubReport
|
||||
from benchmark.ResultsFiles import Excel, ReportDatasets
|
||||
from benchmark.ResultsFiles import Excel, ReportDatasets, Benchmark
|
||||
from benchmark.Utils import Files, Folders
|
||||
from flask import (
|
||||
Blueprint,
|
||||
@@ -14,9 +14,11 @@ from flask import (
|
||||
request,
|
||||
send_file,
|
||||
url_for,
|
||||
redirect,
|
||||
)
|
||||
from dotenv import dotenv_values
|
||||
from flask_login import current_user, login_required
|
||||
from .forms import RankingForm
|
||||
|
||||
results = Blueprint("results", __name__, template_folder="templates")
|
||||
|
||||
@@ -231,3 +233,36 @@ def dataset_report(dataset):
|
||||
results=results,
|
||||
app_config=app_config,
|
||||
)
|
||||
|
||||
|
||||
@results.route("/ranking", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def ranking():
|
||||
os.chdir(current_user.benchmark.folder)
|
||||
form = RankingForm()
|
||||
if form.validate_on_submit():
|
||||
benchmark = Benchmark(score=form.score.data, visualize=False)
|
||||
try:
|
||||
benchmark.compile_results()
|
||||
benchmark.save_results()
|
||||
benchmark.report(tex_output=False)
|
||||
benchmark.exreport()
|
||||
benchmark.excel()
|
||||
except ValueError as e:
|
||||
return render_template(
|
||||
"error.html", message="Couldn't generate ranking", error=str(e)
|
||||
)
|
||||
except KeyError as e:
|
||||
return render_template(
|
||||
"error.html",
|
||||
message="Couldn't generate ranking. It seems that there are "
|
||||
"partial results for some classifiers",
|
||||
error=f"Key not found {str(e)}",
|
||||
)
|
||||
return redirect(
|
||||
url_for(
|
||||
"results.download",
|
||||
file_name=benchmark.get_excel_file_name(),
|
||||
)
|
||||
)
|
||||
return render_template("ranking.html", form=form)
|
13
app/results/templates/ranking.html
Normal file
13
app/results/templates/ranking.html
Normal file
@@ -0,0 +1,13 @@
|
||||
{% extends "base.html" %}
|
||||
{% from 'bootstrap5/form.html' import render_form %}
|
||||
{% block content %}
|
||||
<div class="alert alert-{{ alert_type }} col-md-4" role="alert">
|
||||
<h4 class="alert-heading">{{ title }}</h4>
|
||||
<button class="btn btn-primary"
|
||||
onclick="window.location.href='{{ url_for("main.index") }}'">Back</button>
|
||||
<div class="row">
|
||||
<div>{{ render_form(form) }}</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
```
|
@@ -20,6 +20,7 @@
|
||||
</li>
|
||||
<li>{{ render_nav_item('results.select', 'Results') }}</li>
|
||||
<li>{{ render_nav_item('results.datasets', 'Datasets') }}</li>
|
||||
<li>{{ render_nav_item('results.ranking', 'Ranking') }}</li>
|
||||
<li>{{ render_nav_item('main.config', 'Config') }}</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user