From 86ec8ac55ce496d70a38e09f63611807dd265b26 Mon Sep 17 00:00:00 2001 From: Huaqi Fang <578567190@qq.com> Date: Mon, 14 Oct 2024 16:25:13 +0800 Subject: [PATCH] tools: optimize the color settings for different toolchain bench for parse_report.py Signed-off-by: Huaqi Fang <578567190@qq.com> --- tools/scripts/misc/parse_report.py | 63 ++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/tools/scripts/misc/parse_report.py b/tools/scripts/misc/parse_report.py index 3b58d49c..87f51a7b 100644 --- a/tools/scripts/misc/parse_report.py +++ b/tools/scripts/misc/parse_report.py @@ -140,28 +140,75 @@ def generate_excel_from_bench(rvbench, xlsname): def beautify_excel(excelfile): wb = openpyxl.load_workbook(filename=excelfile) + tools = ["nuclei_gnu", "terapines", "nuclei_llvm"] for ws in wb.worksheets: + # 设置字体样式 bold_font_style = openpyxl.styles.Font(name="阿里巴巴普惠体 3.0 55 Regular", bold=True, size=11) font_stype = openpyxl.styles.Font(name="阿里巴巴普惠体 3.0 55 Regular", bold=False, size=11) alignment_style = openpyxl.styles.Alignment(horizontal="center", vertical="center", wrap_text=True) - fill_style = openpyxl.styles.PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") + ## 设置不同工具链配置下的背景色 + # 淡红色 + def_fill_style = openpyxl.styles.PatternFill(start_color="da9694", end_color="da9694", fill_type="solid") + # 黄色 + gnu_fill_style = openpyxl.styles.PatternFill(start_color="FFFF00", end_color="FFFF00", fill_type="solid") + # 浅蓝色 + llvm_fill_style = openpyxl.styles.PatternFill(start_color="00b0f0", end_color="00b0f0", fill_type="solid") + # 浅绿色 + zcc_fill_style = openpyxl.styles.PatternFill(start_color="92d050", end_color="92d050", fill_type="solid") + fill_styles = { + "nuclei_gnu": gnu_fill_style, + "nuclei_llvm": llvm_fill_style, + "terapines": zcc_fill_style, + "default": def_fill_style + } + # 设置第一行第一列的指定宽度和高度 + # 设置第一行自动换行,第二列以后的固定宽度为10 ws.row_dimensions[1].height = 60 ws.column_dimensions['A'].width = 50 for colidx in range(1, ws.max_row): ws.column_dimensions[openpyxl.utils.get_column_letter(colidx+1)].width = 10 + cfgnames = None + # 遍历每个sheet, 第一行,第一列加粗 + # 然后从第二列开始,将每一列中最大值加粗 + # 且每一列按照 nuclei_gnu, nuclei_llvm, terapines这样的分类找到最大值,并给最大值给背景色,背景色的设定参见 fill_styles for col in ws.iter_cols(min_row=1, max_row=ws.max_row, min_col=1, max_col=ws.max_column): - maxval = None - if col[0].column > 1: - colvals = [cell.value for cell in col][1:] - maxval = max(colvals, key=lambda x: x if x else 0) - for cell in col: + maxvals = dict() + if col[0].column == 1: + cfgnames = [cell.value for cell in col] + else: + colvals = [cell.value for cell in col] + for (cfg, value) in zip(cfgnames, colvals): + if cfg == "config": + continue + newval = value if value else 0 + matchedtool = "default" + for tool in tools: + if tool in cfg: + matchedtool = tool + break + if matchedtool not in maxvals: + maxvals[matchedtool] = newval + else: + maxvals[matchedtool] = max(maxvals[matchedtool], newval) + maxval = 0 + if len(maxvals) > 0: + maxval = max(list(maxvals.values())) + for (cfg, cell) in zip(cfgnames, col): cell.alignment = alignment_style if cell.row == 1 or cell.column == 1: cell.font = bold_font_style else: cell.font = font_stype - if cell.column > 1 and maxval and cell.value == maxval: - cell.fill = fill_style + if cell.column > 1 and cell.row > 1: + matchedtool = "default" + for tool in tools: + if tool in cfg: + matchedtool = tool + break + if cell.value and maxvals[matchedtool] == cell.value: + cell.fill = fill_styles[matchedtool] + if maxval == cell.value: # 让最大值加粗 + cell.font = bold_font_style wb.save(excelfile.replace(".xlsx", "_styled.xlsx")) pass def generate_bench_excel(rptdir, BENCHTYPE="barebench", CAREVAR="bench"):