(
results: Iterable[NormalizedResult],
*,
rows_field: str,
cols_field: str,
metric: str = "success_rate",
)
| 150 | |
| 151 | |
| 152 | def build_metric_matrix( |
| 153 | results: Iterable[NormalizedResult], |
| 154 | *, |
| 155 | rows_field: str, |
| 156 | cols_field: str, |
| 157 | metric: str = "success_rate", |
| 158 | ) -> dict[str, Any]: |
| 159 | result_list = list(results) |
| 160 | row_names = sorted({group_key(item, rows_field) for item in result_list}) |
| 161 | col_names = sorted({group_key(item, cols_field) for item in result_list}) |
| 162 | matrix: dict[str, dict[str, float | int | None]] = {} |
| 163 | for row_name in row_names: |
| 164 | matrix[row_name] = {} |
| 165 | for col_name in col_names: |
| 166 | cell_items = [ |
| 167 | item |
| 168 | for item in result_list |
| 169 | if group_key(item, rows_field) == row_name and group_key(item, cols_field) == col_name |
| 170 | ] |
| 171 | matrix[row_name][col_name] = metric_value(cell_items, metric) |
| 172 | return { |
| 173 | "rows": row_names, |
| 174 | "cols": col_names, |
| 175 | "metric": metric, |
| 176 | "values": matrix, |
| 177 | } |
| 178 | |
| 179 | |
| 180 | def metric_value(results: Iterable[NormalizedResult], metric: str) -> float | int | None: |
no test coverage detected