INNER CODE UNIT · Python
normalize_refs
simonlin1212/Vibe-Research · calc/cli.py:86
def normalize_refs(evidence_ids: list, calc_ids: list) -> list[dict]:
refs = []
for kind, ids in (("evidence", evidence_ids), ("calculation", calc_ids)):
for rid in ids:
rid = str(rid).strip()
if not REF_PATTERNS[kind].match(rid):
raise ValueError(f"{kind} 引用 {rid!r} 格式非法(evidence 形如 ev-xxxx,calculation 形如 calc-xxxx)")
refs.append({"ref_type": kind, "ref_id": rid})
uniq = {(r["ref_type"], r["ref_id"]): r for r in refs}
return [uniq[k] for k in sorted(uniq)]
def _load_history_csv(spec: dict, run_dir: str | None) -> tuple[list, dict]:
"""从 <run_dir>/raw/ 确定性加载一列数值:返回 (values, 解析记录)。realpath 校验,拒绝越出 raw/。"""
if not run_dir:
raise ValueError("history_csv 需要 --run-dir")
if not isinstance(spec, dict):
raise ValueError("history_csv 必须是对象 {raw_ref, column, where}")