MCPcopy Create free account
hub / github.com/JasonLSC/GSCodec_Studio / build_table

Function build_table

tools/static_bench/make_rd_table.py:301–370  ·  view source on GitHub ↗
(rows: Sequence[Dict], dataset_labels: Sequence[str])

Source from the content-addressed store, hash-verified

299
300
301def build_table(rows: Sequence[Dict], dataset_labels: Sequence[str]) -> str:
302 rankings = compute_rankings(rows, dataset_labels)
303
304 header_columns = ["\\multirow{2}{*}{\\textbf{Method}}"]
305 for dataset in dataset_labels[:-1]:
306 header_columns.append(
307 f"\\multicolumn{{{len(METRICS)}}}{{c|}}{{\\textbf{{{latex_escape(dataset)}}}}}"
308 )
309 last_dataset = dataset_labels[-1]
310 header_columns.append(
311 f"\\multicolumn{{{len(METRICS)}}}{{c}}{{\\textbf{{{latex_escape(last_dataset)}}}}}"
312 )
313
314 first_header = header_columns[0]
315 for col in header_columns[1:]:
316 first_header += f" & {col}"
317
318 second_header_cells = [""]
319 for _dataset in dataset_labels:
320 for spec in METRICS:
321 second_header_cells.append(spec.header)
322
323 second_header = " & ".join(["", *second_header_cells[1:]])
324
325 column_spec_parts = ["l"]
326 for index, _ in enumerate(dataset_labels):
327 column_spec_parts.append("c" * len(METRICS))
328 column_spec_str = "|".join(column_spec_parts)
329
330 lines: List[str] = []
331 lines.append(r"\definecolor{tabfirst}{RGB}{255, 223, 127}")
332 lines.append(r"\definecolor{tabsecond}{RGB}{224, 224, 224}")
333 lines.append(r"\definecolor{tabthird}{RGB}{205, 179, 139}")
334 lines.append("")
335 lines.append(r"\begin{table*}[t]")
336 lines.append(r"\centering")
337 lines.append("")
338 lines.append(r"\tiny")
339 lines.append(r"\setlength{\tabcolsep}{4pt}")
340 lines.append(r"\caption{\textbf{Rate--distortion comparison on static scenes.} The \colorbox{tabfirst}{best}, \colorbox{tabsecond}{second best}, and \colorbox{tabthird}{third best} results are highlighted for each metric.}")
341 lines.append(f"\\begin{{tabular}}{{{column_spec_str}}}")
342 lines.append(r"\toprule")
343 lines.append(first_header + r"\\")
344 cmidrule_end = 1 + len(dataset_labels) * len(METRICS)
345 lines.append(r"\cmidrule{2-" + f"{cmidrule_end}" + "}")
346 lines.append(second_header + r"\\")
347 lines.append(r"\midrule")
348
349 for idx, row in enumerate(rows):
350 tokens: List[str] = [row["display_name"]]
351 for dataset in dataset_labels:
352 metrics = row["datasets"].get(dataset)
353 for metric_index, spec in enumerate(METRICS):
354 value = metrics[metric_index] if metrics is not None else None
355 numeric_str = format_metric(value, spec.decimals)
356 highlighted = apply_highlight(row["row_id"], dataset, metric_index, numeric_str, rankings)
357 tokens.append(highlighted)
358 line = " & ".join(tokens) + r"\\"

Callers 1

mainFunction · 0.70

Calls 5

getMethod · 0.80
compute_rankingsFunction · 0.70
latex_escapeFunction · 0.70
format_metricFunction · 0.70
apply_highlightFunction · 0.70

Tested by

no test coverage detected