Skip to content

betting_combat.services.rounds_upcoming

The upcoming card for strategy 4’s live run: RoundsData.upcoming(card_date) (and history) on the rounds data layer, before any fight of the card has a result.

UFCStats itself (which lists a card’s bouts, with their fight ids, before it starts) is behind a JavaScript bot wall and is never bypassed; its Greco1899 mirror holds finished events only. So the card is assembled from what is readable before it starts:

Kalshi the card's fights (``services.markets.discover_card``): both fighters' names,
the live feed's scheduled rounds (``fight_length``), the 'ends before round k'
markets it lists (rounds 4 and 5 only for a five-round fight), whether the
feed has cancelled it
Wikipedia the event (its name and place in the stored 'List of UFC events') and its
page's fight card: running order (main event first), segment, weight class,
the champion marks and notes ('For the UFC Lightweight Championship'); the
page fetched now and stored, or its latest stored copy when Wikipedia
refuses it (``event_page_html``)
UFCStats the fighter table of the mirror (``ufcstats_fighter_tott``): each name to the
fighter-table name the feature library resolves to its UFCStats fighter id

Per bout (never a guess; anything else is excluded with a finding):

link each Kalshi fight to exactly one bout of the Wikipedia card (both fighters
sharing a name word, either order: ``trading.rounds.link_fights``' rule);
a Wikipedia bout without a Kalshi fight is kept for the card's context
names each fighter's name as the fighter table spells it: the Wikipedia name, else
Kalshi's, by the library's normalised name, else by the same letters without
spaces ('Alateng Heili' = 'Alatengheili'); several fighters under one name
are split by the library itself (weight class, then age: ``RawData``); a name
found nowhere is a debutant (the library's ``name:<name>`` id) unless the
table holds a fighter it resembles (a shared surname or two shared words, at
a weight within one division) — then the bout is excluded as ambiguous
weight UFCStats' text from Wikipedia's ('Women's Strawweight' -> "Women's Strawweight
Bout"; a champion's mark or 'For the ... Championship' -> 'UFC <class> Title
Bout', 'interim' -> 'UFC Interim <class> Title Bout'; 'Catchweight' -> 'Catch
Weight Bout'); any other class is excluded
rounds Kalshi's feed, Kalshi's rounds markets and the card (main event or title ->
5, else 3), which must agree wherever given; a Wikipedia-only bout takes the
card's rule
ids the fight id is not known before UFCStats lists the result: a stable
stand-in, the first 16 hex digits of SHA-256('<date>|<fighter id>|<fighter
id>') (sorted ids), and name_1 is the fighter with the smaller id. So the A/B
orientation (``a_slot_of``) is a fixed function of the card date and the two
fighters (a re-run after the card rebuilds the same rows) but is NOT the
research's, which hashed UFCStats' id over UFCStats' result-ordered names
event Wikipedia's name with the network prefix as UFCStats writes it ('UFC on ESPN:
X' -> 'UFC Fight Night: X') and letters folded to ASCII; the place as UFCStats
writes it (', U.S.' -> ', USA'); the event id 'upcoming<YYYYMMDD>'

A bout excluded leaves the card’s context columns (n_bouts, card position) counting the bouts kept; none of them is a model input.

Classes

CardEvent

The card’s event in Wikipedia’s list, in UFCStats’ spelling (ufcstats_event).

FighterTable

The mirror’s fighter table, indexed as the resolution reads it.

canon

canon(name: str) -> list[int]

The same name once suffixes go (‘Sean King III’ = ‘Sean King’).

compact

compact(name: str) -> list[int]

exact

exact(name: str) -> list[int]

near

near(name: str, division: str | None) -> list[int]

Fighters the name resembles: a shared last word, or two shared words, at a listed weight within NEAR_LBS of the division (any weight when either is unknown).

KalshiBout

One Kalshi fight of the card, as the loader reads it.

of

of(fight: Fight) -> KalshiBout

Resolution

What the loader made of a card: the card (None when nothing could be resolved), one row per bout kept (RESOLUTION_COLUMNS), every bout excluded with its reason, and the grouped findings.

StoreRoundsSource

trading.rounds.RoundsData on the rounds data layer: history = every stored input as it stood before the card; upcoming = load_upcoming’s card (its findings and excluded bouts kept in last and logged; the card stored in rounds_upcoming_cards, from which the forward check rebuilds it).

history

history(card_date: dt.date) -> UfcTables

upcoming

upcoming(card_date: dt.date) -> UpcomingCard | None

Functions

ascii_fold

ascii_fold(s: str) -> str

card_event

card_event(list_json: str, card_date: dt.date) -> tuple[CardEvent | None, str]

The card’s event in Wikipedia’s list (the scheduled or the past table): the one event on the card date, else the one a day either side; (None, why) otherwise.

card_from_row

card_from_row(row: Mapping[str, Any]) -> tuple[UpcomingCard, pd.DataFrame]

A stored card back as the live engine received it, and its resolution rows (fight_id, event_ticker, fighter_1, fighter_2, …).

card_row

card_row(res: Resolution, prepared_at: dt.datetime) -> dict[str, Any] | None

A resolved card as a rounds_upcoming_cards row (None without a card).

cito_rows

cito_rows(bouts: Sequence[CitoBout]) -> list[dict[str, Any]]

Cito’s card in the event page’s rows (parse_card_bouts): the bouts not cancelled, in Cito’s running order (card_order 1 = the main event), fighter_1 the red corner, fighter_2 the blue, a title bout’s notes saying so; with each bout’s Cito ids (cito_bout, and the corners’ fighter ids cito_1 / cito_2).

cito_segment

cito_segment(section: str | None) -> str | None

Our segment (‘main’, ‘prelim’, ‘early_prelim’) of Cito’s card section (‘Main Card’, ‘Prelims’, ‘Early Prelims’); None for one not mapped.

event_page_html

event_page_html(store: RoundsStore, fetcher: PacedFetcher, page: str, now: dt.datetime) -> tuple[str | None, Counter[str]]

The card’s event page and its findings. Fetched now, the page is stored (wiki_event_pages: the copy a later refusal falls back on; a copy without a fight card is not kept). When Wikipedia will not serve it (2026-10-22: 403s to the cluster’s address for hours) the latest stored copy is read instead, parsed by the same code, with a finding naming when it was fetched. With no copy stored: None, and the card is not traded, as before.

excluded_frame

excluded_frame(excluded: Sequence[Mapping[str, Any]]) -> pd.DataFrame

The excluded bouts as UpcomingCard.excluded: event_ticker (None for a Wikipedia bout no Kalshi fight was linked to), bout, reason.

fight_id_for

fight_id_for(card_date: dt.date, fighter_ids: Iterable[str]) -> str

The stand-in UFCStats fight id of an upcoming bout (16 hex digits, like UFCStats’).

fighter_rows

fighter_rows(store: RoundsStore, names: Iterable[str]) -> dict[str, list[list[str]]]

The fighter table’s rows (CSV cells) of names, by normalised name, as stored now.

kalshi_of_identity

kalshi_of_identity(identity: Identity) -> dict[str, str]

Kalshi competitor id -> what the name rules honour for it (resolve_spelling’s known_id): the fighter’s UFCStats page id, else ‘name:’ (a fighter UFCStats has no page for yet: minted live or ‘no_page’).

load_upcoming

load_upcoming(card_date: dt.date, store: RoundsStore, kalshi: KalshiRest, fetcher: PacedFetcher, tables: UfcTables | None = None, now: Callable[[], dt.datetime] = lambda: dt.datetime.now(dt.UTC), identity: Identity | None = None, source: CardSource = 'kalshi', cito: CardListings | None = None) -> Resolution

The card on card_date: Kalshi’s fights, the stored Wikipedia list, the event page fetched now (stored; the latest stored copy when Wikipedia refuses it: event_page_html), the fighter table as of the card. identity: our ids (the stored registry); then every fighter and bout of the card is one of ours (the Kalshi competitor ids read from it), else the legacy ids by name.

source ‘cito’ (settings.card_source): Kalshi’s fights are the card’s by their starts (cards.card_dates) and the card’s bouts are Cito’s (cito: its listing of the card a day either side, cito_link.card_bouts), each Kalshi fight on the bout whose two fighters it is (pair_kalshi), every other Kalshi fight left out; the Wikipedia list still names the event (UFCStats’ spelling) and Cito’s ids are bound to ours. Cito listing no card: no card (it is not traded).

pair_kalshi

pair_kalshi(kalshi: Sequence[KalshiBout], rows: Sequence[Mapping[str, Any]]) -> tuple[dict[str, tuple[int, bool]], dict[str, str]]

Each Kalshi fight’s bout on Cito’s card (cito_rows): the one bout whose two fighters are the Kalshi fight’s two (_alike: the one name rule, or a shared name word: Kalshi’s ‘Lupita Godinez’ is Cito’s ‘Loopy Godinez’, ‘Seok Hyun Ko’ its ‘Seokhyeon Ko’), with whether Kalshi’s fighter A is the bout’s fighter 1 (both ways round: the words decide, a tie is refused); one Kalshi fight per bout. Returns (event ticker -> (row index, A is fighter 1), event ticker -> why it is not on the card).

resolve_card

resolve_card(card_date: dt.date, kalshi: Sequence[KalshiBout], wiki: Sequence[Mapping[str, Any]] | None, event: CardEvent | None, tables: UfcTables, aliases: Mapping[str, str] | None = None, identities: Mapping[str, str] | None = None, identity: Identity | None = None, links: tuple[Mapping[str, tuple[int, bool]], Mapping[str, str]] | None = None) -> Resolution

The card from its sources (see the module doc). links: Cito’s card is wiki (cito_rows) and its pairing of the Kalshi fights (pair_kalshi) replaces the Wikipedia rule: a Kalshi fight not on it is left out, never the bouts it touches. tables: the UFC tables as they stood before the card (tables_before); aliases: normalised name -> fighter id (rounds_name_aliases); identity: our ids (rounds.identity) — then every fighter is one of ours (_on_ids) and identities is read from it; else identities: Kalshi competitor id -> fighter id (rounds_identity.kalshi_identities), each Kalshi spelling’s id honoured after the aliases.

resolve_name

resolve_name(table: FighterTable, spellings: Sequence[str], division: str | None, aliases: Mapping[str, str] | None = None, known_ids: Sequence[str | None] = ()) -> tuple[str | None, str]

(the name to list the fighter under, how it was found), or (None, why not), from ONE fighter’s spellings (Wikipedia’s, then Kalshi’s). Each spelling is resolved on its own (resolve_spelling) and they must agree — never a one-sided match:

  • both fighter-table names: the same name;
  • one a fighter-table name, the other refused as merely resembling it or a debutant: only when one spelling holds every word of the other (a compound surname, a suffix), else they are two different people (a late replacement, a stale source) and it is refused;
  • both debutants: the same name, or one holding every word of the other;
  • any spelling ambiguous or aliased to nothing usable: refused.

A fighter-table name also takes another spelling that is merely near or a debutant when the two are one fighter’s names (names.variant: ‘Chris’ / ‘Christopher Padilla’, ‘Su Mudaerji’ / ‘Sumudaerji’): two sources agreeing on the bout, one naming a table fighter exactly.

known_ids: per spelling, the fighter id its Kalshi competitor id is bound to (None: none; rounds_identity).

resolve_spelling

resolve_spelling(table: FighterTable, spelling: str, division: str | None, aliases: Mapping[str, str] | None = None, known_id: str | None = None) -> tuple[str | None, str, bool]

One spelling: (the name to list the fighter under, how it was found, whether it is a fighter-table name), or (None, why not, False).

An alias (rounds_name_aliases: a spelling -> the UFCStats fighter id, or ‘name:’ for a debutant) is honoured first: the fighter is listed under the fighter table’s name of that id (resolve_card checks the library resolves that id from it). Then the normalised name, then the letters without spaces, then the name without suffixes (‘Sean King III’ = ‘Sean King’: UFCStats’ own bouts drop them too); the hits of a method must all be one fighter-table name (several fighters under it are split by the library), else the name is ambiguous. A name found nowhere that resembles a table fighter is refused; one that resembles none is a debutant.

known_id: the UFCStats fighter id Kalshi’s competitor id of this spelling is bound to (rounds_identity), honoured like an alias after the stored ones.

spellings_of_identity

spellings_of_identity(identity: Identity) -> dict[str, str]

Normalised spelling -> its fighter (_target) for every stored spelling of the registry (the reviewed aliases, the spellings bound by UFCStats’ own bouts, a debutant’s from his card): the card loader takes them like the hand aliases.

strict_table_name

strict_table_name(table: FighterTable, spellings: Sequence[str], division: str | None) -> str | None

The one fighter-table name any of spellings is by names.strictly_same, listed within NEAR_LBS of the division (or without a weight); None when none or several.

title_of

title_of(bout: Mapping[str, Any]) -> tuple[bool, bool]

(a title bout, an interim title) from Wikipedia’s champion marks and notes.

ufcstats_event

ufcstats_event(name: str) -> str

Wikipedia’s event name as UFCStats writes it: footnotes removed, the broadcast-network prefix as ‘UFC Fight Night:’, letters folded to ASCII.

ufcstats_location

ufcstats_location(place: str) -> str

Wikipedia’s place as UFCStats writes it: a US place ends ’, USA’.

ufcstats_weight_class

ufcstats_weight_class(wiki: str, title: bool, interim: bool) -> str | None

UFCStats’ WEIGHTCLASS text from Wikipedia’s class; None for a class not mapped.