From 5f0ad34fddd85cc7d109cd1d3fc38e7b38bebfc8 Mon Sep 17 00:00:00 2001 From: Franck Charras <29153872+fcharras@users.noreply.github.com> Date: Mon, 16 Oct 2023 17:48:37 +0200 Subject: [PATCH] Add colors to the spreadsheet for better readability --- benchmarks/kmeans/consolidate_result_csv.py | 47 ++++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/benchmarks/kmeans/consolidate_result_csv.py b/benchmarks/kmeans/consolidate_result_csv.py index 1994786..0eb51ec 100644 --- a/benchmarks/kmeans/consolidate_result_csv.py +++ b/benchmarks/kmeans/consolidate_result_csv.py @@ -1,5 +1,6 @@ import hashlib from io import BytesIO +from itertools import zip_longest from operator import attrgetter import numpy as np @@ -385,6 +386,8 @@ def _gspread_sync(source, gspread_url, gspread_auth_key): # freeze filter rows and benchmark-defining cols worksheet.freeze(rows=1, cols=walltime_worksheet_col) + format_queries = [] + # Text is centerd and wrapped in all cells global_format = dict( horizontalAlignment="CENTER", @@ -395,7 +398,7 @@ def _gspread_sync(source, gspread_url, gspread_auth_key): f"{gspread.utils.rowcol_to_a1(1, 1)}:" f"{gspread.utils.rowcol_to_a1(n_rows + 1, n_cols)}" ) - worksheet.format(global_range, global_format) + format_queries.append(dict(range=global_range, format=global_format)) # benchmark_id and walltime columns are bold bold_format = dict(textFormat=dict(bold=True)) @@ -407,12 +410,44 @@ def _gspread_sync(source, gspread_url, gspread_auth_key): f"{gspread.utils.rowcol_to_a1(2, walltime_worksheet_col)}:" f"{gspread.utils.rowcol_to_a1(n_rows + 1, walltime_worksheet_col)}" ) - worksheet.batch_format( - [ - dict(range=benchmark_id_col_range, format=bold_format), - dict(range=walltime_col_range, format=bold_format), - ] + format_queries.append(dict(range=benchmark_id_col_range, format=bold_format)) + format_queries.append(dict(range=walltime_col_range, format=bold_format)) + + # Header is light-ish yellow + yellow_lighter_header = dict( + backgroundColorStyle=dict( + rgbColor=dict(red=1, green=1, blue=102 / 255, alpha=1) + ) + ) + header_row_range = ( + f"{gspread.utils.rowcol_to_a1(1, 1)}:" + f"{gspread.utils.rowcol_to_a1(1, n_cols)}" + ) + format_queries.append(dict(range=header_row_range, format=yellow_lighter_header)) + + # Every other benchmark_id has greyed background + bright_gray_background = dict( + backgroundColorStyle=dict( + rgbColor=dict(red=232 / 255, green=233 / 255, blue=235 / 255, alpha=1) + ) + ) + benchmark_ids = df[BENCHMARK_ID_NAME] + benchmark_ids_ending_idx = ( + np.where((benchmark_ids.shift() != benchmark_ids).values[1:])[0] + 2 ) + for benchmark_id_range_start, benchmark_id_range_end in zip_longest( + *(iter(benchmark_ids_ending_idx),) * 2 + ): + benchmark_row_range = ( + f"{gspread.utils.rowcol_to_a1(benchmark_id_range_start + 1, 1)}:" + f"{gspread.utils.rowcol_to_a1(benchmark_id_range_end or (n_rows + 1), n_cols)}" # noqa + ) + format_queries.append( + dict(range=benchmark_row_range, format=bright_gray_background) + ) + + # Apply formats + worksheet.batch_format(format_queries) # auto-resize rows and cols worksheet.columns_auto_resize(0, n_cols - 1)