Skip to content

tdfs4ds.impact_report

tdfs4ds.impact_report

Impact report: the output of tdfs4ds.impact.impact_of as a shareable file.

Pure functions: no database, no language model. render_impact_report returns the text (html, md or csv); write_impact_report is the only I/O.

The model is the dict returned by impact_of. Newer optional keys are read when present and ignored when missing: features, feature_edges, severity_counts, schema_version and agent (used, ledger, footprint, narrative, consumer_answers, skipped_reason), efficiency (EXPLAIN comparison), measure (measured comparison on volatile tables) and dependents (the reading by dependent object, with an explanation per affected feature). The agent block is shown only when agent.used is true, and its wording is labelled as unverified.

REVIEW_NOTE_SHORT module-attribute

REVIEW_NOTE_SHORT = 'These checks are not exhaustive and can report false positives: have an expert review the findings. They support experts, they do not replace them.'

__all__ module-attribute

__all__ = ['render_impact_report', 'write_impact_report']

_FORMATS module-attribute

_FORMATS = ('html', 'md', 'csv')

_SEVERITY_ORDER module-attribute

_SEVERITY_ORDER = {'breaks': 0, 'values_change': 1, 'may_change': 2, 'unaffected': 3}

_COLORS module-attribute

_COLORS = {'breaks': '#b3261e', 'values_change': '#b26a00', 'may_change': '#7a5c00', 'unaffected': '#2e7d32', 'not_verifiable': '#6b6b6b', 'depends': '#37474f'}

_EFF_COLORS module-attribute

_EFF_COLORS = {'faster': '#2e7d32', 'same': '#37474f', 'slower': '#b3261e', 'not_comparable': '#6b6b6b'}

_AGENT_NOTE module-attribute

_AGENT_NOTE = 'Written by the assistant, unverified wording: check every claim against the evidence above. ' + REVIEW_NOTE_SHORT

_CSV_COLUMNS module-attribute

_CSV_COLUMNS = ['edited_feature', 'edited_process_id', 'affected_object', 'affected_kind', 'affected_feature', 'severity', 'reason', 'consequence', 'evidence', 'explanation', 'type_note', 'cost_reference', 'agent_opinion', 'agent_confidence', 'agent_reason']

_REVIEW_HEADERS module-attribute

_REVIEW_HEADERS = ['Object', 'Why undecided', 'Code', 'Agent opinion', 'Confidence', 'Agrees with code', 'Reason', 'Evidence']

_REVIEW_NOTE module-attribute

_REVIEW_NOTE = "Agent opinions, for expert review. The agent reads the findings the code could not decide, or only in part; its opinion sits beside the code's finding and never replaces it."

_PARSE_NOTE module-attribute

_PARSE_NOTE = 'The parser cannot follow these SQL constructs: have an expert review the objects below; the findings about them may be incomplete.'

MAX_EXAMPLE_ROWS module-attribute

MAX_EXAMPLE_ROWS = 5

_EXAMPLES_NOTE module-attribute

_EXAMPLES_NOTE = 'Rows present in both results (same entity key) whose value of the column differs: at most %d per column, as returned by the database, not a sample of the whole difference.' % MAX_EXAMPLE_ROWS

_SQL_NOTE module-attribute

_SQL_NOTE = 'The SELECT of the current definition (from SHOW VIEW) and the proposed SELECT, without the REPLACE VIEW header. Removed lines are marked on the left, added lines on the right; nothing was applied.'

_REFERENCE_NOTE module-attribute

_REFERENCE_NOTE = 'Logged durations cover the whole run of the process (ingestion included): a reference, not the time of the SELECT alone.'

_LEDGER_HEADERS module-attribute

_LEDGER_HEADERS = ['Tool', 'Source', 'Model', 'Result', 'Seconds', 'Note']

_CSS module-attribute

_CSS = '\n.tdimp{--navy:#00233C;--orange:#FF5F00;--ink:#2c3e50;--muted:#5A6B7B;--line:#E3E8EE;--panel:#fff;\n  font:15px/1.55 system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;color:var(--ink);\n  max-width:1080px;margin:0 auto;padding:8px 4px 60px;background:#f5f7fa}\n.tdimp *{box-sizing:border-box}\n.tdimp h1{margin:.2em 0 .1em;font-size:26px;color:#fff;letter-spacing:-.02em;word-break:break-word}\n.tdimp h2{margin:0 0 6px;font-size:19px;color:var(--navy)}\n.tdimp h3{margin:14px 0 6px;font-size:14px;color:var(--navy)}\n.tdimp p.muted{color:var(--muted);font-size:13.5px;margin:.2em 0 10px}\n.tdimp code{background:#eef1f5;border-radius:5px;padding:1px 6px;font-family:ui-monospace,Menlo,Consolas,monospace;font-size:12.5px;color:#c0392b;word-break:break-word}\n.tdimp header.hero{background:linear-gradient(135deg,#00233C,#004069);border-radius:16px;padding:24px 28px;margin-bottom:20px}\n.tdimp .kicker{letter-spacing:.16em;text-transform:uppercase;font-size:11.5px;color:var(--orange);font-weight:700}\n.tdimp .hero-sub{color:#bcd0e0;font-size:14px;margin-top:8px}\n.tdimp .kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:12px;margin:0 0 18px}\n.tdimp .kpi{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:13px 15px}\n.tdimp .kpi-label{font-size:11.5px;color:var(--muted);text-transform:uppercase;letter-spacing:.05em}\n.tdimp .kpi-value{font-size:24px;font-weight:800;margin-top:4px;color:var(--navy)}\n.tdimp section.card{background:var(--panel);border:1px solid var(--line);border-radius:14px;padding:18px 20px;margin:16px 0}\n.tdimp section.ai{border-left:4px solid var(--orange)}\n.tdimp .scroll{overflow-x:auto}\n.tdimp table{width:100%;border-collapse:collapse;font-size:13.5px}\n.tdimp th,.tdimp td{text-align:left;vertical-align:top;padding:7px 9px;border-bottom:1px solid var(--line)}\n.tdimp th{font-size:11.5px;text-transform:uppercase;letter-spacing:.04em;color:var(--muted);background:#f8fafc}\n.tdimp td.sev{font-weight:700}\n.tdimp ul,.tdimp ol{margin:6px 0 0 20px;padding:0}\n.tdimp li{margin:4px 0}\n.tdimp .sqlcmp{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:12px;margin-top:8px}\n.tdimp .sqlpane{border:1px solid var(--line);border-radius:10px;overflow:hidden;min-width:0}\n.tdimp .sqlhead{background:#f8fafc;color:var(--muted);font-size:11.5px;text-transform:uppercase;letter-spacing:.04em;padding:6px 10px;border-bottom:1px solid var(--line)}\n.tdimp .sqlpane pre{margin:0;padding:8px 0;max-height:480px;overflow:auto;font:12.5px/1.45 ui-monospace,Menlo,Consolas,monospace;color:#1f2d3a;background:#fff}\n.tdimp .sqlpane .ln{display:block;padding:0 10px;white-space:pre}\n.tdimp .sqlpane .ln.removed{background:#fdecea;color:#8a1c14}\n.tdimp .sqlpane .ln.added{background:#e8f5e9;color:#1b5e20}\n.tdimp details.ex{border:1px solid var(--line);border-radius:10px;margin:8px 0;padding:0 12px}\n.tdimp details.ex summary{cursor:pointer;padding:9px 0;font-weight:600;color:var(--navy)}\n.tdimp details.ex[open] summary{border-bottom:1px solid var(--line);margin-bottom:6px}\n.tdimp details.ex td.old{color:#8a1c14}\n.tdimp details.ex td.new{color:#1b5e20}\n'

html_note

html_note(kind: str = 'sanity') -> str

The long note as an escaped, self-styled HTML block (works in light and dark pages).

md_note

md_note(kind: str = 'sanity') -> str

The long note as a Markdown quote.

_s

_s(v: Any) -> str

Text for any value: None is empty, lists are joined, dicts are dumped as JSON.

_list

_list(v: Any) -> List[Any]

_dict

_dict(v: Any) -> Dict[str, Any]

_int

_int(v: Any) -> int

_e

_e(v: Any) -> str

_md

_md(v: Any) -> str

_sev

_sev(v: Any) -> str

_severity_counts

_severity_counts(model: dict) -> Dict[str, int]

severity_counts when given; otherwise derived from the verdict counts (may_change is 0).

_targets_label

_targets_label(model: dict) -> str

_target_verdict

_target_verdict(model: dict) -> Dict[str, str]

_change_mode

_change_mode(model: dict) -> str

_when

_when(model: dict) -> str

_schema

_schema(model: dict) -> str

_features

_features(model: dict) -> List[Dict[str, Any]]

_explanations

_explanations(model: dict) -> Dict[tuple, str]

{(OBJECT, FEATURE): explanation} from the reading by dependent.

_dependents

_dependents(model: dict) -> List[Dict[str, Any]]

_reference

_reference(model: dict) -> Dict[str, Any]

The process's logged runs (efficiency.reference) and the measured seconds beside them (measure.reference): {row, text, measured, note}, empty when nothing is logged or measured.

_reference_line

_reference_line(model: dict) -> str

_efficiency

_efficiency(model: dict) -> Dict[str, Any]

_measure

_measure(model: dict) -> Dict[str, Any]

_sql_compare

_sql_compare(model: dict) -> Dict[str, Any]

{object, current, proposed, left, right, n_removed, n_added}; left / right are [(kind, line)] with kind same / removed / added, from a line diff (trailing spaces ignored).

_html_sql_pane

_html_sql_pane(title: str, lines: List[tuple], empty: str) -> str

_reader_rows

_reader_rows(model: dict) -> List[Dict[str, str]]

One row per (edited feature, affected object, affected feature). Without features, one row per downstream verdict (the object-level view).

_owner_groups

_owner_groups(model: dict) -> Dict[str, List[Dict[str, str]]]

Objects that may disfunction, grouped by owner. Owner = the reader's owner, else its kind. The fix is the reader's own fix when given, else a generic pointer to the steps.

_chain

_chain(model: dict) -> List[Dict[str, str]]

_unverified

_unverified(model: dict) -> List[Dict[str, str]]

_steps

_steps(model: dict) -> List[Dict[str, str]]

_limits

_limits(model: dict) -> List[str]

_agent

_agent(model: dict) -> Dict[str, Any]

_parse_limits

_parse_limits(model: dict) -> List[Dict[str, Any]]

_agrees_text

_agrees_text(rv: Dict[str, Any]) -> str

_review_rows

_review_rows(ag: Dict[str, Any]) -> List[List[Any]]

One row per review: object, why undecided, code verdict, opinion, confidence, agreement, reason, evidence.

_review_skipped

_review_skipped(ag: Dict[str, Any]) -> List[str]

_answer_cell

_answer_cell(text: Any) -> str

A consumer answer in one table cell: lines joined with ' / ', bold and code kept.

_slash

_slash(v: Any) -> str

_agent_view

_agent_view(ag: Dict[str, Any]) -> Dict[str, Any]

The assistant block as plain rows (no JSON, forward slashes): ledger, footprint, narrative bullets.

_html_footprint

_html_footprint(v: Dict[str, Any]) -> str

_md_footprint

_md_footprint(v: Dict[str, Any]) -> List[str]

_kpi

_kpi(label: str, value: Any, color: str = '') -> str

_html_table

_html_table(headers: List[str], rows: List[List[Any]], sev_col: int = -1) -> str

_html_examples

_html_examples(ex: Dict[str, Any]) -> str

One collapsed panel per differing column: the entity key, the current and the proposed value.

_html_body

_html_body(model: dict) -> str

_html_report

_html_report(model: dict) -> str

_md_table

_md_table(headers: List[str], rows: List[List[Any]]) -> str

_md_report

_md_report(model: dict) -> str

_csv_report

_csv_report(model: dict) -> str

render_impact_report

render_impact_report(model: dict, fmt: str = 'html') -> str

The impact model as 'html' (self-contained, scoped CSS, no script), 'md' or 'csv'.

Every value is escaped for its format. Optional keys that are missing are skipped, never raised on.

write_impact_report

write_impact_report(model: dict, path: str = None, fmt: str = 'html') -> str

Render and write the report; returns the absolute path. Without path the file goes under tdfs4ds.IMPACT_REPORT_DIR when set, else a temporary directory.