Fix row height in excel files

This commit is contained in:
2021-09-27 11:38:23 +02:00
parent d09ab98a46
commit 7a4409bb1f
3 changed files with 60 additions and 40 deletions

2
.gitignore vendored
View File

@@ -128,6 +128,8 @@ dmypy.json
# Pyre type checker # Pyre type checker
.pyre/ .pyre/
.idea/
# Results # Results
results/* results/*
exreport/exreport_output/* exreport/exreport_output/*

View File

@@ -338,6 +338,8 @@ class Excel(BaseReport):
) )
bold = self.book.add_format({"bold": True, "font_size": 14}) bold = self.book.add_format({"bold": True, "font_size": 14})
self.sheet.write(self.row + 1, 0, message, bold) self.sheet.write(self.row + 1, 0, message, bold)
for c in range(self.row + 2):
self.sheet.set_row(c, 20)
self.book.close() self.book.close()
@@ -468,7 +470,7 @@ class Benchmark:
fout = open(os.path.join(Folders.results, Files.exreport_output), "w") fout = open(os.path.join(Folders.results, Files.exreport_output), "w")
ferr = open(os.path.join(Folders.results, Files.exreport_err), "w") ferr = open(os.path.join(Folders.results, Files.exreport_err), "w")
result = subprocess.run( result = subprocess.run(
["Rscript", os.path.join(Folders.src, "benchmark.r")], ["Rscript", os.path.join(Folders.src, Files.benchmark_r)],
stdout=fout, stdout=fout,
stderr=ferr, stderr=ferr,
) )
@@ -523,7 +525,6 @@ class Benchmark:
results = Benchmark.build_results() results = Benchmark.build_results()
book = xlsxwriter.Workbook(Benchmark.get_excel_file_name()) book = xlsxwriter.Workbook(Benchmark.get_excel_file_name())
sheet = book.add_worksheet("Benchmark") sheet = book.add_worksheet("Benchmark")
datasets = results[list(results)[0]]
normal = book.add_format({"font_size": 14}) normal = book.add_format({"font_size": 14})
decimal = book.add_format({"num_format": "0.000000", "font_size": 14}) decimal = book.add_format({"num_format": "0.000000", "font_size": 14})
merge_format = book.add_format( merge_format = book.add_format(
@@ -534,45 +535,61 @@ class Benchmark:
"font_size": 14, "font_size": 14,
} }
) )
sheet.merge_range(0, 0, 1, 0, "Benchmark of Models", merge_format) row = row_init = 3
row = 3
# Set column width def header():
sheet.set_column(0, 0, 40) nonlocal row
for column in range(2 * len(results)): sheet.merge_range(0, 0, 1, 0, "Benchmark of Models", merge_format)
sheet.set_column(column + 1, column + 1, 15) # Set column width
# Set report header sheet.set_column(0, 0, 40)
# Merge 2 rows for column in range(2 * len(results)):
sheet.merge_range(row, 0, row + 1, 0, "Dataset", merge_format) sheet.set_column(column + 1, column + 1, 15)
column = 1 # Set report header
for model in results: # Merge 2 rows
# Merge 2 columns sheet.merge_range(row, 0, row + 1, 0, "Dataset", merge_format)
sheet.merge_range(
row, column, row, column + 1, model, merge_format
)
column += 2
row += 1
column = 1
for _ in range(len(results)):
sheet.write(row, column, "Accuracy", merge_format)
sheet.write(row, column + 1, "Stdev", merge_format)
column += 2
for dataset, _ in datasets.items():
row += 1
sheet.write(row, 0, f"{dataset:30s}", normal)
column = 1 column = 1
for model in results: for model in results:
sheet.write( # Merge 2 columns
row, sheet.merge_range(
column, row, column, row, column + 1, model, merge_format
float(results[model][dataset][0]),
decimal,
) )
column += 1 column += 2
sheet.write( row += 1
row, column = 1
column, for _ in range(len(results)):
float(results[model][dataset][1]), sheet.write(row, column, "Accuracy", merge_format)
decimal, sheet.write(row, column + 1, "Stdev", merge_format)
) column += 2
column += 1
def body():
nonlocal row
datasets = results[list(results)[0]]
for dataset, _ in datasets.items():
row += 1
sheet.write(row, 0, f"{dataset:30s}", normal)
column = 1
for model in results:
sheet.write(
row,
column,
float(results[model][dataset][0]),
decimal,
)
column += 1
sheet.write(
row,
column,
float(results[model][dataset][1]),
decimal,
)
column += 1
def footer():
for c in range(row_init, row + 1):
sheet.set_row(c, 20)
header()
body()
footer()
book.close() book.close()

View File

@@ -19,6 +19,7 @@ class Files:
cmd_open_macos = "/usr/bin/open" cmd_open_macos = "/usr/bin/open"
cmd_open_linux = "/usr/bin/xdg-open" cmd_open_linux = "/usr/bin/xdg-open"
exreport_pdf = "Rplots.pdf" exreport_pdf = "Rplots.pdf"
benchmark_r = "benchmark.r"
@staticmethod @staticmethod
def best_results(model): def best_results(model):