Skip to content

betting_combat.store.rounds

Strategy 4 (rounds) tables in betting.betting_combat: the raw inputs (the UFCStats mirror verbatim, Wikipedia’s event list and card segments, MMADecisions judge scores, the Kalshi markets, minute and hourly candles and trades of the six series the round system reads, the static research files), fights_kalshi, the dataset tables (rounds_datasets, rounds_fight_frames, rounds_clock_years) and the card run’s records (sql/betting_combat_data.sql owns the DDL).

This module only moves rows. Building the research’s exact frames from them is services.rounds_inputs; fetching is services.rounds_data.

Classes

MirrorTable

Where one mirror file lives: its table, the column of each header cell (same order) and the columns that identify a row (plus dup).

RoundsStore

add_event_list

add_event_list(sha256: str, body: str, fetched_at: dt.datetime, source_url: str) -> None

One snapshot of the list (seeing the same snapshot again moves its fetched_at); only the latest EVENT_LISTS_KEPT snapshots are kept.

add_name_alias

add_name_alias(name: str, fighter_id: str, note: str | None = None) -> int

One alias; a second spelling that normalises like a stored one is refused.

add_upcoming_card

add_upcoming_card(row: Mapping[str, Any]) -> int

One assembled card (rounds_upcoming_cards); bouts, segments, excluded and findings as JSON-able values.

card_pages

card_pages() -> set[tuple[dt.date, str]]

card_segment_rows

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

clear_issues

clear_issues(kind: str, tickers: Sequence[str]) -> None

clock_year

clock_year(year: int) -> dict[str, Any] | None

clock_years

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

dataset_manifests

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

Every product’s row without its frame.

datasets

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

event_dates

event_dates() -> dict[str, str]

UFCStats event name (stripped) -> its date text.

event_list

event_list(sha256: str) -> dict[str, Any] | None

One stored snapshot of the list (None once it has aged out).

event_list_shas

event_list_shas() -> set[str]

exclusive

exclusive(name: str, wait_s: float = 0.0) -> AsyncIterator[bool]

A Postgres advisory lock named name for the block (session level, on one pooled connection held for the block and released on exit). Yields whether it was taken; it is tried every 0.2 s for wait_s seconds.

fight_frame_digests

fight_frame_digests() -> dict[str, str]

fight_frames

fight_frames(fight_ids: Sequence[str]) -> list[dict[str, Any]]

fights_kalshi_rows

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

Every row: event_ticker, card_date, cells (column -> CSV cell text), source.

fights_kalshi_tickers

fights_kalshi_tickers() -> set[str]

hourly_candle_tickers

hourly_candle_tickers() -> set[str]

hourly_candles

hourly_candles(tickers: Sequence[str]) -> dict[str, list[dict[str, Any]]]

ticker -> its hourly candles as Kalshi sent them (stored tickers only).

insert_fights_kalshi

insert_fights_kalshi(rows: Sequence[dict[str, Any]]) -> int

New fights_kalshi rows; a fight already stored keeps its row (a row is derived once and never rewritten). Returns the rows written.

judge_counts

judge_counts() -> dict[str, int]

judge_score_rows

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

judge_sources

judge_sources() -> set[str]

last_trades

last_trades(windows: Mapping[str, tuple[int, int] | None]) -> dict[str, dt.datetime]

ticker -> its last trade’s created_time within its window ((lo, hi) epoch seconds, lo <= created < hi: trade_tapes’ own bounds; None: the research-seeded trades, as trade_tapes(seeded=True) serves them). A ticker without a trade there is absent.

latest_event_list

latest_event_list() -> dict[str, Any] | None

market_counts

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

Per stored market: its series, event, result, whether its minute candles and trades were pulled and cover its whole life (open to close), and how many rows the pulls landed (from the pull records: no scan of the trade table).

minute_rows

minute_rows(series: str | None = None, tickers: Sequence[str] | None = None) -> pa.Table

Minute candles (ticker, ts, yes_bid, yes_ask, price_mean, volume, open_interest) of a series or of named tickers, ordered by ticker and time.

mirror_cells

mirror_cells(name: str) -> tuple[tuple[str, ...], list[tuple[str, ...]]]

(header, rows) of one mirror file as landed, rows in file order. The row count must be the one recorded with the snapshot.

mirror_files

mirror_files() -> dict[str, dict[str, Any]]

name_aliases

name_aliases() -> dict[str, str]

normalised name (rounds.common.norm_name) -> UFCStats fighter id, in key order (one alias per normalised name: a unique index).

next_judge_position

next_judge_position() -> int

pull_issues

pull_issues(kind: str, tickers: Sequence[str] | None = None) -> dict[str, dict[str, Any]]

ticker -> why its kind pull is outstanding (reason, detail, attempts, …).

pulls

pulls(kind: str, series: str | None = None, tickers: Sequence[str] | None = None) -> dict[str, dict[str, Any]]

ticker -> its pull record (window_lo, window_hi, base_lo, base_hi, rows, source, pulled_at).

put_clock_years

put_clock_years(rows: Sequence[dict[str, Any]]) -> int

put_fight_frames

put_fight_frames(rows: Sequence[dict[str, Any]]) -> int

put_static_file

put_static_file(row: Mapping[str, Any]) -> int

One static research file (rounds_static_files), replacing a stored one.

record_issues

record_issues(kind: str, issues: Mapping[str, tuple[str, str, str]], at: dt.datetime) -> None

ticker -> (series, reason, detail): one more attempt on each.

replace_card_page

replace_card_page(event_date: dt.date, page: str, rows: Sequence[dict[str, Any]]) -> int

One event page’s segments, replacing that page’s stored rows (a re-scrape of a page whose card changed leaves no stale fight behind). Empty is refused: a page that parses to nothing keeps what was stored.

replace_datasets

replace_datasets(rows: Sequence[dict[str, Any]]) -> int

Swap every rounds_datasets row for one build’s, in one transaction.

replace_mirror

replace_mirror(cells: Mapping[str, Sequence[tuple[str, ...]]], files: Sequence[dict[str, Any]]) -> dict[str, int]

Swap the whole mirror snapshot in one transaction: the four file tables and their ufcstats_files rows. Returns rows per table.

results

results(tickers: Sequence[str]) -> dict[str, str | None]

ticker -> its stored result (‘yes’, ‘no’, ‘scalar’, … or None) for the tickers.

segment_counts

segment_counts() -> dict[dt.date, int]

series_markets

series_markets(series: str) -> list[dict[str, Any]]

A series’ markets as Kalshi sent them, in list order.

series_orders

series_orders(series: str) -> dict[str, int]

ticker -> list_order of a series’ stored markets.

series_tickers

series_tickers() -> dict[str, str]

ticker -> series, every stored market.

static_file

static_file(name: str) -> dict[str, Any] | None

surface_counts

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

Rows and latest time of every rounds surface.

trade_rows

trade_rows(tickers: Sequence[str], source: str | None = None) -> pa.Table

(ticker, created_time, yes_price, count, taker_side, is_block) of the tickers (of one source only when given: ‘research’ = the research-seeded tapes).

ufc_event_counts

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

Per UFCStats event (as named in the results file): bouts and round-stat rows.

upcoming_card

upcoming_card(card_date: dt.date, before: dt.datetime | None = None) -> dict[str, Any] | None

The card’s latest assembly (prepared before before when given).

upcoming_excluded

upcoming_excluded(since: dt.date) -> list[dict[str, Any]]

Every bout the loader excluded on cards from since on (the latest assembly of each card): card_date and the excluded entries.

upsert_hourly_candles

upsert_hourly_candles(rows: Sequence[dict[str, Any]]) -> int

upsert_judge_scores

upsert_judge_scores(rows: Sequence[dict[str, Any]]) -> int

upsert_minutes

upsert_minutes(rows: Sequence[dict[str, Any]]) -> int

upsert_pulls

upsert_pulls(rows: Sequence[dict[str, Any]]) -> int

upsert_series_markets

upsert_series_markets(rows: Sequence[dict[str, Any]]) -> int

upsert_trades

upsert_trades(rows: Sequence[dict[str, Any]]) -> int

winner_listings

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

(event_ticker, ticker, fighter) of every winner market — duplicate listings.

Functions

mirror_rows

mirror_rows(name: str, cells: Sequence[tuple[str, ...]]) -> list[dict[str, Any]]

One mirror file’s cells as rows of its table, numbered in file order.

numbered

numbered(keys: Iterable[tuple[Any, ...]]) -> list[int]

dup for each key: how many times the same key came before it (0 = first).