feat(bioflow): stage_done 摘要从 manifest.metrics 提取关键指标(命中/比对率等) (#010)

This commit is contained in:
2026-10-13 11:28:18 +08:00
parent 6b4b5e571f
commit 9cb0bf2e35
+25 -1
View File
@@ -617,6 +617,30 @@ def parse_progress_marker(line: str) -> dict[str, Any] | None:
return None
_METRIC_LABELS = {
"hits": "命中", "hit_count": "命中", "mapping_rate": "比对率",
"aligned": "比对", "mapped": "比对", "identified": "鉴定",
"members": "成员", "de_genes": "差异基因", "up": "上调", "down": "下调",
"enriched": "富集", "count": "数量", "total": "总数",
"records": "记录", "sequences": "序列",
}
def _metrics_summary(stage: str, metrics: dict) -> str:
"""阶段完成摘要(G 关键指标自然语言转述);无指标时退化为「阶段已完成」。"""
if not isinstance(metrics, dict) or not metrics:
return f"阶段 {stage} 已完成"
parts = []
for k, v in metrics.items():
if not isinstance(v, (int, float, str, bool)):
continue
label = _METRIC_LABELS.get(str(k), str(k))
parts.append(f"{label} {v}")
if parts:
return f"阶段 {stage} 完成:{','.join(parts)}"
return f"阶段 {stage} 已完成"
@dataclass
class JobRecord:
"""任务内存记录(DB 行 + 派生路径)。"""
@@ -1071,7 +1095,7 @@ class Runner:
"job_id": record.id, "stage": stage, "exit_code": exit_code,
"manifest_ref": manifest.path,
"metrics": manifest.metrics,
"summary": f"阶段 {stage} 已完成",
"summary": _metrics_summary(stage, manifest.metrics),
})
return "done"