Skip to content

betting_combat.rounds.identity.registry

The stored registry: our own ids for every fighter, bout and event, the bout’s own facts, and every source key bound to them. Every table only grows (a row is never changed or removed): a source’s id for something we know is a new key row, never an edit.

fighters fighter_uid ('F' + 5 digits), name (UFCStats' page name, else the first
spelling seen), how ('ufcstats': minted for a fighter-details page;
'no_page': for a bout name UFCStats had no page for; 'live': for a card's
debutant before the card)
fighter_keys (source, key) -> fighter_uid, how. Sources:
ufcstats the fighter-details URL id
name an EXTRA spelling (``norm_name``) a source uses for the
fighter: a page's own name is never stored (it is read from
the fighter table each time, so a namesake's new page makes
the name ambiguous at once), only a spelling that is no
page's name ('Zach Reese' for the page 'Zachary Reese')
kalshi the winner market's competitor id (``ufc_competitor``)
cito Cito's fighter id
One fighter per key; a fighter may hold several keys of one source.
bout_sides UFCStats bout side (ufcstats_fight_id, the name exactly as UFCStats writes
it on the bout) -> fighter_uid and how it was resolved ('pin', 'name',
'weight', 'alias', 'spelling', 'no_page', 'live', 'renamed'): resolved
once, never again, so a namesake appearing later cannot move a past bout;
keyed by the name, never by UFCStats' listing order (the winner first: an
overturned result may reorder a bout, never its fighters)
events event_uid ('E' + 5 digits), date (ISO), name and location as UFCStats
writes them, how ('ufcstats' / 'live')
event_keys (source, key) -> event_uid, how: 'ufcstats' (the event-details id),
'wikipedia' (the event page's title), 'cito' (Cito's event slug)
bouts bout_uid ('B' + 6 digits), event_uid, date, fighter_lo / fighter_hi (the two
fighter_uids, sorted), fighter_a, and the bout's facts as scheduled: rounds
(3 or 5; None where UFCStats lists no format, the 1990s), division
(``common.division_of``: 'Lightweight', ... 'Other'), women, title; how
('ufcstats': minted from the history; 'live': by the card run before it)
bout_keys (source, key) -> bout_uid, how: 'ufcstats' (the fight-details id),
'kalshi' (a winner event ticker: a fight Kalshi listed twice has two),
'cito' (Cito's bout id)
fighter_merges from_uid -> into_uid, how, evidence: a reviewed correction, the only
one there is (nothing is ever edited): the card run minted a fighter for a
name that was a fighter we know ('Patricio Pitbull', UFCStats' 'Patricio
Freire'); from then on ``from_uid`` IS ``into_uid`` in every lookup
(``canon``), his keys, sides and bouts with it

Fighter A is fighter_lo or fighter_hi by a hash of the bout_uid (a_slot_of): fixed when the bout is minted, the same in training and live, and independent of the result (UFCStats lists the winner first 60% of the time).

The tables are plain frames (CSV on disk for review, read / write); production keeps them in the database. Nothing here mints or resolves: that is build.extend (the history) and live (a card before it).

Classes

Identity

The eight stored tables (see the module doc) and their lookups, every fighter_uid they return canonical (canon: through the merges).

as_of_card

as_of_card(bout_uids: Iterable[str]) -> Identity

The registry as it stood at a card: bout_uids (its live bouts) without the UFCStats ids the history bound to them since, nor those bouts’ UFCStats sides and their event’s UFCStats id (a replay of the card rebuilds its rows exactly as the card run did).

bout

bout(source: str, key: str) -> str | None

The bout_uid a source key is bound to, else None.

canon

canon(uid: str) -> str

The fighter uid is (itself, unless merged into another: followed to the end).

empty

empty() -> Identity

event

event(source: str, key: str) -> str | None

The event_uid a source key is bound to, else None.

fighter

fighter(source: str, key: str) -> str | None

The fighter_uid a source key is bound to, else None.

next_uid

next_uid(kind: str, taken: int = 0) -> str

The next unused id of kind (‘fighter’ / ‘event’ / ‘bout’), taken more along.

of

of(**frames: pd.DataFrame) -> Identity

The registry of these frames, each typed (typed); a table not given is empty.

read

read(folder: Path) -> Identity

The registry as write left it in folder (one CSV per table).

replace

replace(**frames: pd.DataFrame) -> Identity

This registry with some tables replaced (typed).

write

write(folder: Path) -> None

Functions

a_slot_of

a_slot_of(bout_uid: str) -> int

1 or 2: fighter A is the bout’s lower (1) or higher (2) fighter_uid. A hash of the bout_uid, so fixed with the bout and independent of the result.

fighter_a_of

fighter_a_of(bout_uid: str, fighter_x: str, fighter_y: str) -> str

The bout’s fighter A of its two fighter_uids (in either order).

typed

typed(name: str, frame: pd.DataFrame) -> pd.DataFrame

frame with the table’s columns, in order and in their types (ints and flags nullable, the rest objects).