supercontest.models.models
The data schema for the application.
There are one-to-one, one-to-many, many-to-one, and many-to-many relationships below.
Columns have relationships, not tables, of course. For tables that are “simply” associated with
others, you can make the statements above in a “simple” sense - eg Season to Week is a
one-to-many relationship. But more specificity is required for tables the have relationships
across multiple columns - eg games and (2) contestants.
In the SQL layer, all FKs manifest as actual columns and all association tables manifest as actual tables (of course). All integer PKs have associated sequences and column defaults (to nextval) in postgres.
In the ORM layer, the relationships are all queryable as if they were real columns (of course). I have made every relationship bidirectional.
Observers are used for computed cols. In some cases, it’s a basic calculation (eg DOW from datetime). In others, it’s an FK and a relationship (eg coverer from games). All are stored, not virtual. They’re calculated when the observed cols (across tables) change, on write (not read). Important: Observers double as defaults and thus will run at insert time. So if a relation is observed, it needs to be passed at instantiation (rather than letting the ORM associate it with the FK after creation).
In general, this module flows from children -> parents, to make dependency readable + ordered.
Module Attributes
The cache object used to memoize query functions and cache view functions. |
|
The many-many relationship and its association table between User and Role. |
|
The many-many relationship and its association table between User and League. |
Classes
- class supercontest.models.models.Contestant(**kwargs)
Bases:
Model- coverage_id: Mapped[int]
- game_id: Mapped[int]
- get_line() float
Handles the sign of the line from the parent’s game obj, whether or not you’re the favorite or the underdog.
- Returns:
Signed line. Negative for favorite, positive for underdog, 0 for pickem.
- get_line_bucket() str
Groups lines into ranges for analysis with more appropriate precision.
- Returns:
String range where the value falls.
- get_opponent() Any
Don’t need it as an ID FK col, or a relationship, because then there are complications when creating this object (its opponent ID doesn’t exist yet and self-relationships can get messy) - so this convenience function just provides it when called.
- Returns:
The Contestant object for the opponent.
- Raises:
ValueError – If there’s not exactly 2 opponents in the game associated with this contestant.
- id: Mapped[int]
- location_id: Mapped[int]
- margin: Mapped[float]
- opponent_score: Mapped[int]
- prediction: Mapped[Prediction]
- prediction_id: Mapped[int]
- score: Mapped[int]
- set_coverage(*args, **kwargs)
- team_id: Mapped[int]
- class supercontest.models.models.Coverage(**kwargs)
Bases:
Model- contestants: Mapped[list[Contestant]]
- id: Mapped[int]
- name: Mapped[str]
- points: Mapped[float]
- class supercontest.models.models.Game(**kwargs)
Bases:
Model- contestants: Mapped[list[Contestant]]
- datetime: Mapped[datetime]
- get_contestants(by: str, fail: bool = True) tuple[Any, ...]
Returns the Contestant objects in the matchup, by various classifications.
- Parameters:
by – “prediction” or “location” or “coverage”
fail – If True, will error if pickem/neutral/push. Else, will return in order of contestants[0], contestants[1]
- Returns:
(favorite, underdog) or (home, visitor) or (coverer, noncoverer)
- Raises:
ValueError – If
fail=Trueand no favorite/home/coverer in this game.
- get_dow() str
Takes the datetime col of this instance and simply returns the day of the week.
- Returns:
DOW.
- id: Mapped[int]
- line: Mapped[float]
- status_id: Mapped[int]
- week_id: Mapped[int]
- class supercontest.models.models.League(**kwargs)
Bases:
Model- id: Mapped[int]
- name: Mapped[str]
- season_id: Mapped[int]
- class supercontest.models.models.Location(**kwargs)
Bases:
Model- contestants: Mapped[list[Contestant]]
- id: Mapped[int]
- name: Mapped[str]
- class supercontest.models.models.Pick(**kwargs)
Bases:
Model- contestant: Mapped[Contestant]
- contestant_id: Mapped[int]
- id: Mapped[int]
- user_id: Mapped[int]
- class supercontest.models.models.Prediction(**kwargs)
Bases:
Model- contestants: Mapped[list[Contestant]]
- id: Mapped[int]
- name: Mapped[str]
- class supercontest.models.models.Season(**kwargs)
Bases:
Model- id: Mapped[int]
- season: Mapped[int]
- season_end: Mapped[date]
- season_start: Mapped[date]
- class supercontest.models.models.Status(**kwargs)
Bases:
Model- abbv: Mapped[str]
- espn_abbv: Mapped[str]
- finished: Mapped[bool]
- id: Mapped[int]
- inprogress: Mapped[bool]
- name: Mapped[str]
- unstarted: Mapped[bool]
- class supercontest.models.models.Team(**kwargs)
Bases:
Model- abbv: Mapped[str]
- city: Mapped[str]
- contestants: Mapped[list[Contestant]]
- espn_city: Mapped[str]
- id: Mapped[int]
- name: Mapped[str]
- class supercontest.models.models.User(**kwargs)
Bases:
Model,UserMixin- active: Mapped[bool]
- email: Mapped[str]
- email_all_picks: Mapped[bool]
- email_confirmed_at: Mapped[datetime | None]
- email_when_picks_closing: Mapped[bool]
- email_when_picks_open: Mapped[bool]
- first_name: Mapped[str | None]
- id: Mapped[int]
- last_name: Mapped[str | None]
- password: Mapped[str]
- class supercontest.models.models.Week(**kwargs)
Bases:
Model- id: Mapped[int]
- season_id: Mapped[int]
- week: Mapped[int]
- week_end: Mapped[datetime]
- week_start: Mapped[datetime]
- supercontest.models.models.cache: Any = <flask_caching.Cache object>
The cache object used to memoize query functions and cache view functions.
- supercontest.models.models.league_user = Table('league_user_association', MetaData(), Column('league_id', Integer(), ForeignKey('leagues.id'), table=<league_user_association>, primary_key=True, nullable=False), Column('user_id', Integer(), ForeignKey('users.id'), table=<league_user_association>, primary_key=True, nullable=False), schema=None)
The many-many relationship and its association table between User and League.
- supercontest.models.models.role_user = Table('role_user_association', MetaData(), Column('role_id', Integer(), ForeignKey('roles.id'), table=<role_user_association>, primary_key=True, nullable=False), Column('user_id', Integer(), ForeignKey('users.id'), table=<role_user_association>, primary_key=True, nullable=False), schema=None)
The many-many relationship and its association table between User and Role.