From 007c419979760d1b528c5634c124baaf13f15233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana?= Date: Mon, 29 May 2023 20:07:00 +0200 Subject: [PATCH] Add generate excel fault tolerance with compare --- benchmark/scripts/be_flask.py | 36 +++++++++++++------ .../scripts/templates/partials/js_select.js | 10 ++++-- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/benchmark/scripts/be_flask.py b/benchmark/scripts/be_flask.py index ebed0fe..7829d78 100755 --- a/benchmark/scripts/be_flask.py +++ b/benchmark/scripts/be_flask.py @@ -85,17 +85,33 @@ def excel(): else: selected_files = request.form["selected-files"] book = None - for file_name in selected_files: - file_name_result = os.path.join(Folders.results, file_name) - if book is None: - file_excel = os.path.join(Folders.excel, Files.be_list_excel) - book = xlsxwriter.Workbook(file_excel, {"nan_inf_to_errors": True}) - excel = Excel( - file_name=file_name_result, - book=book, - compare=app.config[COMPARE], + try: + for file_name in selected_files: + file_name_result = os.path.join(Folders.results, file_name) + if book is None: + file_excel = os.path.join(Folders.excel, Files.be_list_excel) + book = xlsxwriter.Workbook( + file_excel, {"nan_inf_to_errors": True} + ) + excel = Excel( + file_name=file_name_result, + book=book, + compare=app.config[COMPARE], + ) + excel.report() + except Exception as e: + if book is not None: + book.close() + return ( + json.dumps( + { + "success": False, + "error": "Could not create excel file, " + str(e), + } + ), + 200, + {"ContentType": "application/json"}, ) - excel.report() if book is not None: book.close() Files.open(file_excel, test=app.config[TEST]) diff --git a/benchmark/scripts/templates/partials/js_select.js b/benchmark/scripts/templates/partials/js_select.js index 13f6216..620558f 100644 --- a/benchmark/scripts/templates/partials/js_select.js +++ b/benchmark/scripts/templates/partials/js_select.js @@ -51,11 +51,15 @@ function excel() { contentType: "application/json", dataType: 'json', success: function(data){ - alert("Se ha generado el archivo "+data.file); + 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 || '{\"mensaje\": \"Error indeterminado\"}'); - alert(mensaje.mensaje); + var mensaje = JSON.parse(xhr.responseText || '{\"message\": \"Error indeterminado\"}'); + alert(mensaje.message); } }); }