Skip to content

betting_combat.normalizers.ids

ids.py — our catalog in memory: every event, fighter, bout and market, each found by our id or by any vendor’s, merged as sources tell more, and new ones minted with our next id.

VENDOR_KEYS · VENDOR_LISTS the vendor id columns of each catalog table (one value / many)
Conflict a source telling a vendor id that is another row's, or a
different one where we hold one: never applied, kept to review
Ids the catalog: ``find`` / ``by_name`` / ``matcher``; ``merge`` a
fact in; ``correct`` a field known wrong; ``rekey`` a vendor id
the vendor moved; ``mint`` an id; ``changes`` what to write

The rules, in order: a vendor id already on a row answers at once (exact); a fact merges field by field, only the fields its source set (a default a source never stated never overwrites what another told; a value never erased by a missing one; a vendor id never replaced: a different one is a Conflict; lists of ids unioned); only a source with no id we know falls back to names (by_name, matcher), today’s rules, kept exactly.

Classes

Conflict

Ids

The catalog in memory, its vendor-id indexes, and what changed since it was loaded.

by_name

by_name(name: str, among: Iterable[str] | None = None) -> list[Fighter]

The fighters name is, by today’s levels (same name, then a spelling written otherwise), among among (fighter ids) or everyone. Several: ambiguous (the caller decides with more facts: the bout, the weight).

changes

changes() -> dict[str, list[Any]]

Every row merged or minted since the catalog was loaded (or last clear), by table, events before the fighters, bouts and markets that point at them; in each, the rows that gave a vendor id up first (released).

clear

clear() -> None

correct

correct(kind: Kind, our_id: str, **fields: Any) -> Any

Set fields on a held row as given, None included: what a source known to be right says over a value known to be wrong (merge never erases). Vendor ids are not set here.

find

find(kind: Kind, column: str, value: Any) -> Any

The row holding value in vendor column column (one value or a list’s).

get

get(kind: Kind, our_id: str) -> Any

market

market(venue: str, venue_key: str, venue_side: str = 'yes') -> Market | None

matcher

matcher(start: dt.date, end: dt.date) -> Matcher

Today’s bout matcher over the bouts dated start .. end (± the window).

merge

merge(kind: Kind, fact: T, source: str) -> T

Fold fact into its row (by its id): a value never erased by a missing one, a vendor id never replaced (a different one is a Conflict), lists of ids unioned. Returns the row as it now stands.

mint

mint(kind: Kind) -> str

Our next id of kind: never re-used, never re-derived.

rekey

rekey(kind: Kind, our_id: str, column: str, value: Any) -> Any

Point vendor id column of row our_id at value: the vendor re-identified its record (Cito relisting a fight under a new id, a live id changed, a fight moved to another card). A row that held value gives it up (released: written first, the unique index never sees it twice).

spellings

spellings(fighter_id: str) -> list[str]