Skip to content

report

Reportable

Bases: Protocol

__str__() abstractmethod

Return a string representation.

Source code in src/flowcean/core/report.py
19
20
21
@abstractmethod
def __str__(self) -> str:
    """Return a string representation."""

Report

Bases: dict[str, ReportEntry]

A structured container for evaluation results of multiple models.

The Report maps model names to their metric results. For each model:

  • top-level keys are metric names,
  • values are either:
    • a single Reportable (e.g., scalar metric result), or
    • a nested mapping from submetric names to Reportable objects (e.g., per-class F1 scores, per-feature regression errors, or multi-output results).

This hierarchical structure allows uniform representation of both simple metrics and complex hierarchical metrics across multiple models.

Example:

report = Report( ... { ... "model_a": { ... "accuracy": 0.95, ... "f1": {"class_0": 0.91, "class_1": 0.89}, ... }, ... "model_b": { ... "mae": {"feature_x": 0.2, "feature_y": 0.3}, ... }, ... } ... )

pretty_print(header_style='bold magenta', metric_style='cyan', value_style='green', title_style='bold yellow')

Pretty print the report to the terminal.

Source code in src/flowcean/core/report.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def pretty_print(
    self,
    header_style: StyleType = "bold magenta",
    metric_style: StyleType = "cyan",
    value_style: StyleType = "green",
    title_style: StyleType = "bold yellow",
) -> None:
    """Pretty print the report to the terminal."""
    console = Console()
    for model, entry in self.items():
        table = Table(show_header=True, header_style=header_style)
        table.add_column("Metric", style=metric_style, no_wrap=True)
        table.add_column("Value", style=value_style)

        for metric, value in entry.items():
            if isinstance(value, Mapping):
                value = cast("Mapping[str, Reportable]", value)
                for submetric, subvalue in value.items():
                    table.add_row(
                        f"{metric}{submetric}",
                        _format_value(subvalue),
                    )
            else:
                table.add_row(metric, _format_value(value))

        panel = Panel(
            table,
            title=f"[{title_style}]{model}[/]",
            expand=False,
        )
        console.print(panel)