Metric registry
The metric registry: one YAML file of metric definitions, resolved to its effective form and rendered to TypeScript for the web apps. The metric registry guide explains the schema.
Analytics
load_metric_registry
load_metric_registry() -> 'list[dict[str, Any]]'
The validated entries of the packaged metrics.yaml, in file order.
Returns
one dict per base metric carrying exactly KEYS -- key, label, short, axis, format, polarity, family, qualifier, glossary_slug and variants.
Raises
| Exception | Description |
|---|---|
ValueError | If the file fails parse or validation -- a missing or unexpected key, an unknown format / polarity / family / qualifier, a duplicate key, or a variants value naming an unknown metric. |
Example
from sportsdataverse.registry import load_metric_registry
by_key = {e["key"]: e for e in load_metric_registry()}
by_key["EPAplay"]["variants"] # {'total': 'TEPA', 'per_play': 'EPAplay', ...}
parse
parse(text: 'str') -> 'list[dict[str, Any]]'
Entries from the constrained YAML metrics.yaml is written in.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | the file's contents. |
Returns
one dict per - key: entry, in file order; a variants: block becomes a nested dict[str, str].
Raises
| Exception | Description |
|---|---|
ValueError | If a line is not a comment, a blank, an entry opener - key: NAME, a two-space field: value or a four-space row of an open variants: block; if a field repeats within an entry; or if a value is not a plain scalar (quoted, null, {}, or a bare string that does not start with # / a YAML indicator) -- the reader never guesses at a construct it was not written for. |
Example
from sportsdataverse.registry import parse
parse("- key: TEPA\n label: Total EPA\n variants:\n total: TEPA\n")
# [{'key': 'TEPA', 'label': 'Total EPA', 'variants': {'total': 'TEPA'}}]
render_ts
render_ts(entries: 'list[dict[str, Any]]', *, target: "Literal['gop', 'web']") -> 'str'
The registry as a deterministic TypeScript module.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
entries | list[dict[str, Any]] | what load_metric_registry returned. | |
target | Literal['gop', 'web'] | "gop" (4-space indent, Game on Paper's astro style) or "web" (2-space, the platform's prettier style). The exported shape is identical: METRICS: Record<string, MetricEntry> and resolveMetric(column), mirroring resolve. |
Returns
the module, headed by three comment lines -- // generated by sportsdataverse.registry, the sdv-py version + target, and // sha256: of the BODY (everything after those three lines). A consumer verifies its copy against that digest, not the whole file; the version line changes on every sdv-py bump, so a consumer's sync test regenerating then is by design.
Raises
| Exception | Description |
|---|---|
ValueError | If target is not "gop" or "web". |
Example
from sportsdataverse.registry import load_metric_registry, render_ts
ts = render_ts(load_metric_registry(), target="gop")
ts.splitlines()[0] # '// generated by sportsdataverse.registry'
resolve
resolve(column: 'str') -> 'dict[str, Any] | None'
The registry entry behind a published column, with the column's parts.
The grammar is base [_off|_def|_margin] [_pass|_rush] [_rank|_pct|_n|_pos_pct|_conf_pct]. The exact column is tried before any
suffix is peeled, so a registered X_pct is its own entry. Only the
adjusted family also accepts the prefix / infix spellings its columns
use (adj_off_epa, adj_def_epa, net_adj_epa,
off_strength_faced).
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
column | str | a published column name, e.g. "EPAplay_off_pass_rank". |
Returns
dict | None: the entry's ten keys plus side, phase, suffix (each None when absent) and the EFFECTIVE polarity -- _def flips the base's, a _margin is always higher (every producer margin is good-minus-bad), anything else keeps it. label and short are rewritten for a phase (EPA/Play -> EPA/DB / EPA/Rush, SR% -> Pass SR%) but carry no Off / Def / Net side prefix -- Game on Paper prepends that itself. None for an unknown column.
Raises
| Exception | Description |
|---|---|
ValueError | If the packaged metrics.yaml fails validation on the first call (it is loaded lazily, see load_metric_registry). |
Example
from sportsdataverse.registry import resolve
r = resolve("EPAplay_off_pass_rank")
(r["key"], r["side"], r["phase"], r["suffix"], r["short"])
# ('EPAplay', 'off', 'pass', '_rank', 'EPA/DB')
resolve("havoc_def")["polarity"] # 'higher' (lower, flipped by _def)