diff --git a/benchmark/Results.py b/benchmark/Results.py index 8eb5253..76b1874 100644 --- a/benchmark/Results.py +++ b/benchmark/Results.py @@ -1,5 +1,6 @@ import os import sys +from pathlib import Path from operator import itemgetter from types import SimpleNamespace import math @@ -330,9 +331,12 @@ class Excel(BaseReport): ) self._compare_totals = {} if book is None: - self.excel_file_name = self.file_name.replace(".json", ".xlsx") + self.excel_file_name = Path(self.file_name).name.replace( + Files.report_ext, ".xlsx" + ) self.book = xlsxwriter.Workbook( - self.excel_file_name, {"nan_inf_to_errors": True} + os.path.join(Folders.excel, self.excel_file_name), + {"nan_inf_to_errors": True}, ) self.set_book_properties() self.close = True @@ -616,7 +620,9 @@ class ReportDatasets: if excel: self.max_length = 0 if book is None: - self.excel_file_name = Files.datasets_report_excel + self.excel_file_name = os.path.join( + Folders.excel, Files.datasets_report_excel + ) self.book = xlsxwriter.Workbook( self.excel_file_name, {"nan_inf_to_errors": True} ) @@ -1113,9 +1119,7 @@ class Benchmark: f.write("\\hline\n\\end{tabular}}\n\\end{sidewaystable}\n") def get_excel_file_name(self): - return os.path.join( - Folders.exreport, Files.exreport_excel(self._score) - ) + return os.path.join(Folders.excel, Files.exreport_excel(self._score)) def excel(self): book = xlsxwriter.Workbook( @@ -1564,7 +1568,9 @@ class Summary: path, self.data_filtered[num]["file"] ) if book is None: - file_name = Files.be_list_excel + file_name = os.path.join( + Folders.excel, Files.be_list_excel + ) book = xlsxwriter.Workbook( file_name, {"nan_inf_to_errors": True} ) diff --git a/benchmark/Utils.py b/benchmark/Utils.py index 77851d3..61cc664 100644 --- a/benchmark/Utils.py +++ b/benchmark/Utils.py @@ -13,6 +13,7 @@ class Folders: exreport = "exreport" report = os.path.join(exreport, "exreport_output") img = "img" + excel = "excel" @staticmethod def src(): diff --git a/benchmark/scripts/be_init_project.py b/benchmark/scripts/be_init_project.py index 4ceb135..737ce8c 100755 --- a/benchmark/scripts/be_init_project.py +++ b/benchmark/scripts/be_init_project.py @@ -15,6 +15,7 @@ def main(args_test=None): folders.append(os.path.join(args.project_name, Folders.exreport)) folders.append(os.path.join(args.project_name, Folders.report)) folders.append(os.path.join(args.project_name, Folders.img)) + folders.append(os.path.join(args.project_name, Folders.excel)) try: for folder in folders: print(f"Creating folder {folder}") diff --git a/benchmark/scripts/be_list.py b/benchmark/scripts/be_list.py index 1415767..30764d0 100755 --- a/benchmark/scripts/be_list.py +++ b/benchmark/scripts/be_list.py @@ -1,6 +1,7 @@ #! /usr/bin/env python +import os from benchmark.Results import Summary -from benchmark.Utils import Files +from benchmark.Utils import Files, Folders from benchmark.Arguments import Arguments """List experiments of a model @@ -28,5 +29,6 @@ def main(args_test=None): return excel_generated = data.manage_results() if excel_generated: - print(f"Generated file: {Files.be_list_excel}") - Files.open(Files.be_list_excel, test=args_test is not None) + name = os.path.join(Folders.excel, Files.be_list_excel) + print(f"Generated file: {name}") + Files.open(name, test=args_test is not None) diff --git a/benchmark/scripts/be_report.py b/benchmark/scripts/be_report.py index 3e54c63..30a5f88 100755 --- a/benchmark/scripts/be_report.py +++ b/benchmark/scripts/be_report.py @@ -1,7 +1,9 @@ #!/usr/bin/env python +import os from benchmark.Results import Report, Excel, SQL, ReportBest, ReportDatasets -from benchmark.Utils import Files +from benchmark.Utils import Files, Folders from benchmark.Arguments import Arguments +from pathlib import Path """Build report on screen of a result file, optionally generate excel and sql @@ -69,11 +71,13 @@ def main(args_test=None): sql.report() if args.excel: excel = Excel( - file_name=args.file_name, + file_name=Path(args.file_name).name, compare=args.compare, ) excel.report() - Files.open(excel.get_file_name(), is_test) + Files.open( + os.path.join(Folders.excel, excel.get_file_name()), is_test + ) case "datasets": report = ReportDatasets(args.excel) report.report() diff --git a/benchmark/tests/Benchmark_test.py b/benchmark/tests/Benchmark_test.py index 5fd9916..0ed2e22 100644 --- a/benchmark/tests/Benchmark_test.py +++ b/benchmark/tests/Benchmark_test.py @@ -15,10 +15,10 @@ class BenchmarkTest(TestBase): files.append(Files.exreport(score)) files.append(Files.exreport_output(score)) files.append(Files.exreport_err(score)) - files.append(Files.exreport_excel(score)) files.append(Files.exreport_pdf) files.append(Files.tex_output("accuracy")) self.remove_files(files, Folders.exreport) + self.remove_files([Files.exreport_excel("accuracy")], Folders.excel) self.remove_files(files, ".") return super().tearDown() diff --git a/benchmark/tests/Excel_test.py b/benchmark/tests/Excel_test.py index 6ed24cf..1241776 100644 --- a/benchmark/tests/Excel_test.py +++ b/benchmark/tests/Excel_test.py @@ -13,7 +13,7 @@ class ExcelTest(TestBase): "results_accuracy_STree_iMac27_2021-10-27_09:40:40_0.xlsx", "results_accuracy_ODTE_Galgo_2022-04-20_10:52:20_0.xlsx", ] - self.remove_files(files, Folders.results) + self.remove_files(files, Folders.excel) return super().tearDown() def test_report_excel_compared(self): @@ -21,7 +21,7 @@ class ExcelTest(TestBase): report = Excel(file_name, compare=True) report.report() file_output = report.get_file_name() - book = load_workbook(file_output) + book = load_workbook(os.path.join(Folders.excel, file_output)) sheet = book["STree"] self.check_excel_sheet(sheet, "excel_compared") @@ -30,14 +30,14 @@ class ExcelTest(TestBase): report = Excel(file_name, compare=False) report.report() file_output = report.get_file_name() - book = load_workbook(file_output) + book = load_workbook(os.path.join(Folders.excel, file_output)) sheet = book["STree"] self.check_excel_sheet(sheet, "excel") def test_Excel_Add_sheet(self): file_name = "results_accuracy_STree_iMac27_2021-10-27_09:40:40_0.json" excel_file_name = file_name.replace(".json", ".xlsx") - book = Workbook(os.path.join(Folders.results, excel_file_name)) + book = Workbook(os.path.join(Folders.excel, excel_file_name)) excel = Excel(file_name=file_name, book=book) excel.report() report = Excel( @@ -46,7 +46,7 @@ class ExcelTest(TestBase): ) report.report() book.close() - book = load_workbook(os.path.join(Folders.results, excel_file_name)) + book = load_workbook(os.path.join(Folders.excel, excel_file_name)) sheet = book["STree"] self.check_excel_sheet(sheet, "excel_add_STree") sheet = book["ODTE"] diff --git a/benchmark/tests/Util_test.py b/benchmark/tests/Util_test.py index 4c99020..51c7027 100644 --- a/benchmark/tests/Util_test.py +++ b/benchmark/tests/Util_test.py @@ -11,6 +11,8 @@ class UtilTest(TestBase): self.assertEqual("results", Folders.results) self.assertEqual("hidden_results", Folders.hidden_results) self.assertEqual("exreport", Folders.exreport) + self.assertEqual("excel", Folders.excel) + self.assertEqual("img", Folders.img) self.assertEqual( os.path.join(Folders.exreport, "exreport_output"), Folders.report ) diff --git a/benchmark/tests/scripts/Be_Benchmark_test.py b/benchmark/tests/scripts/Be_Benchmark_test.py index 0249473..58c44d6 100644 --- a/benchmark/tests/scripts/Be_Benchmark_test.py +++ b/benchmark/tests/scripts/Be_Benchmark_test.py @@ -16,10 +16,10 @@ class BeBenchmarkTest(TestBase): files.append(Files.exreport(score)) files.append(Files.exreport_output(score)) files.append(Files.exreport_err(score)) - files.append(Files.exreport_excel(self.score)) files.append(Files.exreport_pdf) files.append(Files.tex_output(self.score)) self.remove_files(files, Folders.exreport) + self.remove_files([Files.exreport_excel(self.score)], Folders.excel) self.remove_files(files, ".") return super().tearDown() @@ -41,7 +41,7 @@ class BeBenchmarkTest(TestBase): self.check_file_file(file_name, "exreport_tex") # Check excel file file_name = os.path.join( - Folders.exreport, Files.exreport_excel(self.score) + Folders.excel, Files.exreport_excel(self.score) ) book = load_workbook(file_name) replace = None diff --git a/benchmark/tests/scripts/Be_Init_Project_test.py b/benchmark/tests/scripts/Be_Init_Project_test.py index 0d0af29..b835703 100644 --- a/benchmark/tests/scripts/Be_Init_Project_test.py +++ b/benchmark/tests/scripts/Be_Init_Project_test.py @@ -33,6 +33,7 @@ class BeInitProjectTest(TestBase): Folders.exreport, Folders.report, Folders.img, + Folders.excel, ] for folder in expected: self.assertIsFolder(os.path.join(test_project, folder)) diff --git a/benchmark/tests/scripts/Be_List_test.py b/benchmark/tests/scripts/Be_List_test.py index f9e8c83..526f0cd 100644 --- a/benchmark/tests/scripts/Be_List_test.py +++ b/benchmark/tests/scripts/Be_List_test.py @@ -39,7 +39,7 @@ class BeListTest(TestBase): stdout, stderr = self.execute_script("be_list", ["-m", "STree"]) self.assertEqual(stderr.getvalue(), "") self.check_output_file(stdout, "be_list_report_excel") - book = load_workbook(Files.be_list_excel) + book = load_workbook(os.path.join(Folders.excel, Files.be_list_excel)) sheet = book["STree"] self.check_excel_sheet(sheet, "excel") @@ -50,7 +50,7 @@ class BeListTest(TestBase): stdout, stderr = self.execute_script("be_list", ["-m", "STree"]) self.assertEqual(stderr.getvalue(), "") self.check_output_file(stdout, "be_list_report_excel_2") - book = load_workbook(Files.be_list_excel) + book = load_workbook(os.path.join(Folders.excel, Files.be_list_excel)) sheet = book["STree"] self.check_excel_sheet(sheet, "excel") sheet = book["STree2"] diff --git a/benchmark/tests/scripts/Be_Report_test.py b/benchmark/tests/scripts/Be_Report_test.py index b2848ce..2af5ef2 100644 --- a/benchmark/tests/scripts/Be_Report_test.py +++ b/benchmark/tests/scripts/Be_Report_test.py @@ -17,7 +17,10 @@ class BeReportTest(TestBase): "results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.xlsx", ] self.remove_files(files, Folders.results) - self.remove_files([Files.datasets_report_excel], os.getcwd()) + self.remove_files( + [Files.datasets_report_excel], + os.path.join(os.getcwd(), Folders.excel), + ) return super().tearDown() def test_be_report(self): @@ -67,7 +70,9 @@ class BeReportTest(TestBase): # replace benchmark version line = self.replace_benchmark_version(line, output_text, index) self.assertEqual(line, output_text[index]) - file_name = os.path.join(os.getcwd(), Files.datasets_report_excel) + file_name = os.path.join( + os.getcwd(), Folders.excel, Files.datasets_report_excel + ) book = load_workbook(file_name) sheet = book["Datasets"] self.check_excel_sheet( @@ -129,7 +134,7 @@ class BeReportTest(TestBase): ["file", file_name, "-x", "-c"], ) file_name = os.path.join( - Folders.results, file_name.replace(".json", ".xlsx") + Folders.excel, file_name.replace(Files.report_ext, ".xlsx") ) book = load_workbook(file_name) sheet = book["STree"] @@ -144,7 +149,7 @@ class BeReportTest(TestBase): ["file", file_name, "-x"], ) file_name = os.path.join( - Folders.results, file_name.replace(".json", ".xlsx") + Folders.excel, file_name.replace(".json", ".xlsx") ) book = load_workbook(file_name) sheet = book["STree"] diff --git a/benchmark/tests/test_files/be_init_project.test b/benchmark/tests/test_files/be_init_project.test index 1e52072..2826682 100644 --- a/benchmark/tests/test_files/be_init_project.test +++ b/benchmark/tests/test_files/be_init_project.test @@ -4,6 +4,7 @@ Creating folder test_project/hidden_results Creating folder test_project/exreport Creating folder test_project/exreport/exreport_output Creating folder test_project/img +Creating folder test_project/excel Done! Please, edit .env file with your settings and add a datasets folder with an all.txt file with the datasets you want to use. diff --git a/benchmark/tests/test_files/be_list_report_excel.test b/benchmark/tests/test_files/be_list_report_excel.test index 269c52a..8155f53 100644 --- a/benchmark/tests/test_files/be_list_report_excel.test +++ b/benchmark/tests/test_files/be_list_report_excel.test @@ -4,4 +4,4 @@  1 2021-10-27 results_accuracy_STree_iMac27_2021-10-27_09:40:40_0.json 0.04158 0.943 default A  2 2021-09-30 results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json 0.04544 0.173 With gridsearched hyperparameters Added results/results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json to some_results.xlsx -Generated file: some_results.xlsx +Generated file: excel/some_results.xlsx diff --git a/benchmark/tests/test_files/be_list_report_excel_2.test b/benchmark/tests/test_files/be_list_report_excel_2.test index dedfc9d..b317759 100644 --- a/benchmark/tests/test_files/be_list_report_excel_2.test +++ b/benchmark/tests/test_files/be_list_report_excel_2.test @@ -5,4 +5,4 @@  2 2021-09-30 results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json 0.04544 0.173 With gridsearched hyperparameters Added results/results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json to some_results.xlsx Added results/results_accuracy_STree_iMac27_2021-10-27_09:40:40_0.json to some_results.xlsx -Generated file: some_results.xlsx +Generated file: excel/some_results.xlsx