refactor(evidence): unify formulas with typed evidence
This commit is contained in:
@@ -55,7 +55,45 @@ def project_session(
|
||||
"esito": "accettata" if decision.type == "evidence_accepted" else "scartata",
|
||||
"decision_seq": decision.seq,
|
||||
}
|
||||
return list(entries.values())
|
||||
return list(entries.values()) + _formula_proposals(decisions, linking)
|
||||
|
||||
|
||||
def _formula_proposals(decisions: list["DecisionRecord"], linking: "SchemaLinking") -> list[dict]:
|
||||
"""Project locally approved F4 formulas without representing them as Evidence.
|
||||
|
||||
A proposal remains in the persisted session artifact until a separate curator
|
||||
imports, reviews, and publishes it in the workspace repository.
|
||||
"""
|
||||
approved = {
|
||||
decision.detail: decision.seq
|
||||
for decision in decisions
|
||||
if decision.type == "concept_formula_approved" and decision.detail
|
||||
}
|
||||
proposals = []
|
||||
for formula in linking.concept_formulas:
|
||||
if not isinstance(formula, dict):
|
||||
continue
|
||||
concept = formula.get("concept")
|
||||
sql = formula.get("sql")
|
||||
columns = formula.get("columns")
|
||||
if not isinstance(concept, str) or not isinstance(sql, str) or not isinstance(columns, list):
|
||||
continue
|
||||
# A referenced published Formula Evidence is already represented by its
|
||||
# Evidence receipt/citation, so it must not be reintroduced as a proposal.
|
||||
evidence_id = formula.get("evidence_id", formula.get("id", ""))
|
||||
if isinstance(evidence_id, str) and evidence_id.startswith("evidence:"):
|
||||
continue
|
||||
proposals.append({
|
||||
"schema_version": 1,
|
||||
"kind": "formula_proposal",
|
||||
"publication": "session_only",
|
||||
"concept": concept,
|
||||
"columns": columns,
|
||||
"sql": sql,
|
||||
"sources": formula.get("sources", []),
|
||||
"decision_seq": approved.get(concept),
|
||||
})
|
||||
return proposals
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
||||
Reference in New Issue
Block a user