Skip to content

betting_combat.features.base

base — what every feature table shares: the base’s facts read once (Base) and the table’s build / update / write (FeatureTable: upserted on its key into the features schema through common-db, the table created from the frame and widened as columns are added).

Base the base tables a build reads: fights (every completed fight, its card and how
it ended), upcoming (the fights on cards still to come), rounds (the official
lines), cards (the judges), fighters, their UFC.com pages, pedigrees, pro careers
bout_order each fight's place among its day's fights (the tables' time order: date, then
``bout_order``, then the round)
FeatureTable NAME, KEY, ``compute(base)``; ``build`` writes every row, ``update`` the rows
dated from ``since`` (a row holds only what was known on its date, so a new
fight never changes an older row), ``read`` the table back

Classes

Base

The base tables a feature build reads (read), or handed in (tests): the fights, their official rounds, the judges, the fights to come; the fighters, their UFC.com pages, pedigrees and pro careers.

read

read(db: DBClient, schema: str = 'ufc') -> Base

FeatureTable

One feature table: NAME in features, keyed on KEY, its rows from compute.

build

build(db: DBClient, base: Base | None = None) -> dict[str, int]

Every row.

compute

compute(base: Base) -> pd.DataFrame

read

read(db: DBClient, since: dt.date | None = None, columns: list[str] | None = None) -> pd.DataFrame

features.NAME back (the rows dated since on; columns: only those it has), in its key’s order; the numbers as floats (common-db stores a float as numeric, which Arrow cannot read back when its scale varies: a 1e-12 next to a 300).

update

update(db: DBClient, since: dt.date, base: Base | None = None) -> dict[str, int]

The rows dated since on (the history is recomputed: the sequential features, the ratings and the opponents’ as-of numbers, need all of it).

write

write(db: DBClient, rows: pd.DataFrame) -> dict[str, int]

Upsert rows on KEY into features.NAME, BATCH at a time (the table made from the frame when absent, new columns added); infinities stored as NULL.

Functions

bout_order

bout_order(fights: pd.DataFrame) -> pd.Series

Each fight’s place among its day’s fights, 1 the first fought: by the event’s start, then its card from the first prelim to the main event (card_pos 0); a fight without a place first. Give it every fight of the day (completed and to come) so the order never moves.

frame

frame(db: DBClient, q: str, params: dict[str, Any] | None = None) -> pd.DataFrame

A query’s rows as a pandas frame; a refused query raises.