| 370 | |
| 371 | |
| 372 | def metrics_table( |
| 373 | metrics, |
| 374 | all_branches: bool = False, |
| 375 | all_tags: bool = False, |
| 376 | all_commits: bool = False, |
| 377 | precision: Optional[int] = None, |
| 378 | round_digits: bool = False, |
| 379 | ): |
| 380 | from dvc.utils.diff import format_dict |
| 381 | from dvc.utils.flatten import flatten |
| 382 | |
| 383 | td = TabularData(["Revision", "Path"], fill_value="-") |
| 384 | |
| 385 | for branch, val in metrics.items(): |
| 386 | for fname, metric in val.get("data", {}).items(): |
| 387 | row_data: dict[str, str] = {"Revision": branch, "Path": fname} |
| 388 | metric = metric.get("data", {}) |
| 389 | flattened = ( |
| 390 | flatten(format_dict(metric)) |
| 391 | if isinstance(metric, dict) |
| 392 | else {"": metric} |
| 393 | ) |
| 394 | row_data.update( |
| 395 | { |
| 396 | k: _format_field(v, precision, round_digits) |
| 397 | for k, v in flattened.items() |
| 398 | } |
| 399 | ) |
| 400 | td.row_from_dict(row_data) |
| 401 | |
| 402 | rev, path, *metrics_headers = td.keys() |
| 403 | td.project(rev, path, *sorted(metrics_headers)) |
| 404 | |
| 405 | if not any([all_branches, all_tags, all_commits]): |
| 406 | td.drop("Revision") |
| 407 | |
| 408 | return td |
| 409 | |
| 410 | |
| 411 | def show_metrics( |