stats.py
stats.py — documate --stats: the documentation dashboard.
Overview
stats.py — documate --stats: the documentation dashboard.
What the repo's documentation looks like right now (coverage bars, doc-line
counts, page sizes), how it moved (+/− deltas), and what the model layer has
cost so far. Two append-only jsonl ledgers next to the graph carry the
history: stats.jsonl gets a snapshot whenever a docs run or --stats sees
the numbers change, spend.jsonl gets one line per --ai run (prose appends
it even on Ctrl-C — spent tokens must never vanish from the bill). Reading
either ledger degrades: absent or garbled lines render as "no history yet",
never a crash — the dashboard is a viewer, not a gate.
depends on src/documate/core.py, src/documate/docs.py, src/documate/ui.py · used by src/documate/cli.py, src/documate/docs.py, src/documate/prose.py
flowchart TD add_spend --> _dir
API
F_dir(ctx: Context) -> Path
The ledgers' home — the graph's directory, so one place holds every documate artifact (and one .gitignore keeps them all out of commits).
add_spend, record, runF_read(path: Path) -> list[dict]
Parse a jsonl ledger; a missing file or a garbled line reads as absent.
record, runFsnapshot(ctx: Context, model=None) -> dict
Measure the repo's documentation right now, as one flat dict.
Symbols/modules come from the docs model (pass the one docs.run just built to avoid a rebuild); doc_lines counts docstring/doc-comment lines living in source; the page numbers count the docs tree itself, split by stamp into generated and authored.
record, runF_changed(a: dict, b: dict) -> bool
True when two snapshots differ on any metric (timestamps don't count).
record, runFrecord(ctx: Context, model=None, snap: dict | None=None) -> None
Append the current snapshot to stats.jsonl — only when the numbers moved, so the ledger is a history of states, not of invocations.
run · calls _changed, _dir, _read, snapshotFadd_spend(ctx: Context, model: str, tokens: int, usd: float) -> None
Append one --ai run's measured bill to spend.jsonl; an unmeasured run (scripted stand-ins, a declined pre-flight) writes nothing.
_dirF_tok(n: int) -> str
A token count as a compact human number (874 → '874', 1934 → '1.9k').
_spend_rowsF_usd(x: float) -> str
Dollars with enough precision to show a sub-cent run without noise.
_spend_rows, runF_bar(done: int, total: int, width: int=22) -> str
A █/░ gauge; a started-but-unfinished count always shows ≥1 filled cell.
_coverage_rowsF_delta(n: int) -> tuple[str, str | None]
A +N/−N/±0 segment, colored by direction (documentation up = green).
_coverage_rowsF_hue(pct: int) -> str
The coverage traffic light shared with the docs summary line.
_coverage_rowsF_coverage_rows(snap: dict, prev: dict | None) -> list[list[tuple]]
The dashboard's top half: one gauge per coverage axis, one counted line per volume metric, each with its +/− vs the previous distinct snapshot.
run · calls _bar, _delta, _hueF_spend_rows(spends: list[dict]) -> list[list[tuple]]
The bill: all-time totals, then a per-model line when several ran.
run · calls _tok, _usdFrun(ctx: Context) -> int
documate --stats: render the dashboard and record today's snapshot.
Deltas compare against the most recent ledger snapshot that differs from now — i.e. what the latest round of work changed — and the first ever run says so instead of faking a zero delta. Read-only apart from the ledger append; never gates, always exits 0.
_changed, _coverage_rows, _dir, _read, _spend_rows, _usd, record, snapshot