Support multi-sample promotion evidence
This commit is contained in:
@@ -109,24 +109,35 @@ def collect_positive_runs(
|
||||
) -> dict[CandidateKey, list[dict[str, Any]]]:
|
||||
best_by_candidate_sample: dict[tuple[CandidateKey, str], dict[str, Any]] = {}
|
||||
portfolio_model_asset_id = portfolio.get("model_asset_id")
|
||||
|
||||
positive_runs: list[tuple[str, dict[str, Any]]] = []
|
||||
for sample in portfolio.get("samples") or []:
|
||||
sample_slug = str(sample.get("sample_slug") or "unknown")
|
||||
for run in sample.get("runs") or []:
|
||||
key = as_candidate_key(
|
||||
run,
|
||||
fallback_model_asset_id=str(portfolio_model_asset_id) if portfolio_model_asset_id else None,
|
||||
fallback_tile_size=default_tile_size,
|
||||
fallback_tile_overlap=default_tile_overlap,
|
||||
)
|
||||
f1 = numeric(run, "f1_score")
|
||||
if key is None or f1 is None:
|
||||
continue
|
||||
enriched = dict(run)
|
||||
enriched["sample_slug"] = sample_slug
|
||||
existing = best_by_candidate_sample.get((key, sample_slug))
|
||||
existing_f1 = numeric(existing or {}, "f1_score")
|
||||
if existing is None or existing_f1 is None or f1 > existing_f1:
|
||||
best_by_candidate_sample[(key, sample_slug)] = enriched
|
||||
positive_runs.append((sample_slug, run))
|
||||
for item in portfolio.get("items") or []:
|
||||
sample_slug = str(item.get("sample_slug") or "unknown")
|
||||
positive_runs.append((sample_slug, item))
|
||||
|
||||
for sample_slug, run in positive_runs:
|
||||
key = as_candidate_key(
|
||||
run,
|
||||
fallback_model_asset_id=str(portfolio_model_asset_id) if portfolio_model_asset_id else None,
|
||||
fallback_tile_size=default_tile_size,
|
||||
fallback_tile_overlap=default_tile_overlap,
|
||||
)
|
||||
f1 = numeric(run, "f1_score")
|
||||
if f1 is None:
|
||||
f1 = numeric(run, "f1")
|
||||
if key is None or f1 is None:
|
||||
continue
|
||||
enriched = dict(run)
|
||||
enriched["f1_score"] = f1
|
||||
enriched["sample_slug"] = sample_slug
|
||||
existing = best_by_candidate_sample.get((key, sample_slug))
|
||||
existing_f1 = numeric(existing or {}, "f1_score")
|
||||
if existing is None or existing_f1 is None or f1 > existing_f1:
|
||||
best_by_candidate_sample[(key, sample_slug)] = enriched
|
||||
|
||||
grouped: dict[CandidateKey, list[dict[str, Any]]] = defaultdict(list)
|
||||
for (key, _sample_slug), run in best_by_candidate_sample.items():
|
||||
|
||||
Reference in New Issue
Block a user