mirror of
https://github.com/Doctorado-ML/benchmark.git
synced 2025-08-15 15:35:52 +00:00
Add automatic download excel files
This commit is contained in:
@@ -235,6 +235,16 @@ class Arguments(argparse.ArgumentParser):
|
||||
"help": "number of folds",
|
||||
},
|
||||
],
|
||||
"output": [
|
||||
("-o", "--output"),
|
||||
{
|
||||
"type": str,
|
||||
"default": "local",
|
||||
"choices": ["local", "docker"],
|
||||
"required": False,
|
||||
"help": "in be_flask tells if it is running in local or in docker {local, docker}",
|
||||
},
|
||||
],
|
||||
"platform": [
|
||||
("-P", "--platform"),
|
||||
{
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
PYTHON_VERSION = "{}.{}".format(sys.version_info.major, sys.version_info.minor)
|
||||
@@ -16,6 +15,7 @@ class Folders:
|
||||
img = "img"
|
||||
excel = "excel"
|
||||
sql = "sql"
|
||||
current = os.getcwd()
|
||||
|
||||
@staticmethod
|
||||
def src():
|
||||
|
@@ -1,19 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
from benchmark.Arguments import EnvData
|
||||
from flask import Flask
|
||||
from .main import main
|
||||
from .main import main, OUTPUT
|
||||
|
||||
FRAMEWORK = "framework"
|
||||
FRAMEWORKS = "frameworks"
|
||||
TEST = "test"
|
||||
|
||||
|
||||
def create_app():
|
||||
def create_app(output="local"):
|
||||
app = Flask(__name__)
|
||||
config = EnvData().load()
|
||||
app.register_blueprint(main)
|
||||
app.config[FRAMEWORK] = config[FRAMEWORK]
|
||||
app.config[FRAMEWORKS] = ["bootstrap", "bulma"]
|
||||
app.config[OUTPUT] = output
|
||||
app.jinja_env.auto_reload = True
|
||||
app.config["TEMPLATES_AUTO_RELOAD"] = True
|
||||
return app
|
||||
|
@@ -1,19 +1,21 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import json
|
||||
import shutil
|
||||
import xlsxwriter
|
||||
from benchmark.Utils import Files, Folders
|
||||
from benchmark.Arguments import EnvData
|
||||
from benchmark.ResultsBase import StubReport
|
||||
from benchmark.ResultsFiles import Excel, ReportDatasets
|
||||
from benchmark.Datasets import Datasets
|
||||
from flask import Blueprint, current_app
|
||||
from flask import Blueprint, current_app, send_file
|
||||
from flask import render_template, request, redirect, url_for
|
||||
|
||||
|
||||
main = Blueprint("main", __name__)
|
||||
FRAMEWORK = "framework"
|
||||
FRAMEWORKS = "frameworks"
|
||||
OUTPUT = "output"
|
||||
TEST = "test"
|
||||
|
||||
|
||||
@@ -29,6 +31,7 @@ class AjaxResponse:
|
||||
{
|
||||
"success": self.success,
|
||||
"file": self.file_name,
|
||||
"output": current_app.config[OUTPUT],
|
||||
}
|
||||
),
|
||||
self.code,
|
||||
@@ -120,7 +123,9 @@ def show():
|
||||
return showfile(
|
||||
file_name=selected_file,
|
||||
compare=compare,
|
||||
back=url_for("main.index", compare=compare),
|
||||
back=url_for(
|
||||
"main.index", compare=compare, output=current_app.config[OUTPUT]
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -134,7 +139,8 @@ def excel():
|
||||
report = ReportDatasets(excel=True, output=False)
|
||||
report.report()
|
||||
excel_name = os.path.join(Folders.excel, Files.datasets_report_excel)
|
||||
Files.open(excel_name, test=current_app.config[TEST])
|
||||
if current_app.config[OUTPUT] == "local":
|
||||
Files.open(excel_name, test=current_app.config[TEST])
|
||||
return AjaxResponse(True, Files.datasets_report_excel).to_string()
|
||||
try:
|
||||
for file_name in selected_files:
|
||||
@@ -158,10 +164,21 @@ def excel():
|
||||
).to_string()
|
||||
if book is not None:
|
||||
book.close()
|
||||
Files.open(file_excel, test=current_app.config[TEST])
|
||||
if current_app.config[OUTPUT] == "local":
|
||||
Files.open(file_excel, test=current_app.config[TEST])
|
||||
return AjaxResponse(True, Files.be_list_excel).to_string()
|
||||
|
||||
|
||||
@main.route("/download/<file_name>")
|
||||
def download(file_name):
|
||||
src = os.path.join(Folders.current, Folders.excel, file_name)
|
||||
dest = os.path.join(
|
||||
Folders.src(), "scripts", "app", "static", "excel", file_name
|
||||
)
|
||||
shutil.copyfile(src, dest)
|
||||
return send_file(dest, as_attachment=True)
|
||||
|
||||
|
||||
@main.route("/config/<framework>/<compare>")
|
||||
def config(framework, compare):
|
||||
if framework not in current_app.config[FRAMEWORKS]:
|
||||
|
1
benchmark/scripts/app/static/excel/.gitignore
vendored
Normal file
1
benchmark/scripts/app/static/excel/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.xlsx
|
@@ -12,7 +12,11 @@ function excelFiles(selectedFiles, compare) {
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
if (data.success) {
|
||||
alert("Se ha generado el archivo "+data.file);
|
||||
if (data.output == "local") {
|
||||
alert("Se ha generado el archivo " + data.file);
|
||||
} else {
|
||||
window.open('/download/' + data.file, "_blank");
|
||||
}
|
||||
} else {
|
||||
alert(data.file);
|
||||
}
|
||||
|
@@ -1,11 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
import webbrowser
|
||||
from benchmark.scripts.app.app import create_app, TEST
|
||||
from benchmark.Arguments import Arguments
|
||||
from benchmark.scripts.app.app import create_app, TEST, OUTPUT
|
||||
|
||||
# Launch a flask server to serve the results
|
||||
|
||||
def main(args_test=None):
|
||||
arguments = Arguments(prog="be_flask")
|
||||
arguments.xset("output")
|
||||
args = arguments.parse(args_test)
|
||||
app = create_app()
|
||||
app.config[TEST] = args_test is not None
|
||||
webbrowser.open_new("http://127.0.0.1:1234/")
|
||||
app.run(port=1234)
|
||||
app.config[OUTPUT] = args.output
|
||||
if args.output == "local":
|
||||
webbrowser.open_new("http://127.0.0.1:1234/")
|
||||
app.run(port=1234, host="0.0.0.0")
|
||||
|
Reference in New Issue
Block a user