supercontest.core.results
Calculations for the portions of views with results. Ordered by increasing complexity.
General scopes for the views:
view_matchups(): single season, single week, single userview_allpicks(): single season, single week, all usersview_progression(): single season, all weeks, all usersview_leaderboard(): single season, all weeks, all usersview_alltime_leaderboard(): all seasons, all weeks, users
And therefore we divide utilities into buckets:
_week_results: provides data to the matchups view and the allpicks view_season_results: provides data to the graph view and the leaderboard view_alltime_results: provides data to the alltime leaderboard view
General flows for each view:
query_: get the raw data, usually picks / matchups, scoped by the viewmap_: iterate over raw picks and key pick counts / points by season / week / usercalculate_: calculate / restructure as necessary to yield lists of user-result dictssort_: order those elements by the approprate keysinject_: some information can only be calculated post-sort (eg ranks, payouts) - add thosetoprow_: a final list of aggregations across a col (rather than row), for leaguewide results
Functions
Picks counts, rollups (points, total picks, etc) - data dictionaries for every user. |
|
Picks counts, rollups (points, total picks, etc) - data dictionaries for every user. |
|
Picks counts, rollups (points, total picks, etc) - data dictionaries for every user. |
|
For each season, sums the total points across all users and the total picks across all users to determine a league-wide percentage. |
|
Takes the season results by user and calculates the leaguewide perf. |
|
Takes all picks from all users and aggregates them into the top row for leaguewide pick counts for that week. |
|
Does the post-sort value injection. |
|
Does the post-sort value injection. |
|
Does the post-sort value injection. |
|
Takes a raw list of pick rows and iterates over them to create the maps of pick counts and point rollups, all by season/week/user. |
|
Sorts the alltime leaderboard. |
|
Sorts all user-week-point info. |
|
At the end of the day, only "total points" matters. |
|
The entry point for the allpicks view. |
|
The entry point for the alltimelb view. |
|
The entry point for the leaderboard view. |
|
The entry point for the matchups view. |
|
The entry point for the graph view. |
- supercontest.core.results.calc_alltime_results(pick_counts: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, int]]]], point_rollups: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, float]]]]) list[AlltimeResults]
Picks counts, rollups (points, total picks, etc) - data dictionaries for every user.
- Parameters:
pick_counts – The return from
map_picks().point_rollups – The return from
map_picks().
- Returns:
All aggregated results, an element per user.
- supercontest.core.results.calc_season_results(pick_counts: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, int]]]], point_rollups: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, float]]]], season: int) list[SeasonResults]
Picks counts, rollups (points, total picks, etc) - data dictionaries for every user.
- Parameters:
pick_counts – The return from
map_picks().point_rollups – The return from
map_picks().season – Which season to extract from the other inputs.
- Returns:
All results, an element per user.
- supercontest.core.results.calc_week_results(pick_counts: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, int]]]], point_rollups: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, float]]]], raw_picks: defaultdict[int, defaultdict[int, defaultdict[int, list[Any]]]], sorted_games: list[Game], season: int, week: int) list[WeekResults]
Picks counts, rollups (points, total picks, etc) - data dictionaries for every user. Uses the
sorted_scoresinput to sort the picked teams for each user; the left rollup on the allpicks view. First goes by status, then points, then mirrors the matchups sort (datetime then favoredteam name).- Parameters:
pick_counts – The return from
map_picks().point_rollups – The return from
map_picks().raw_picks – The return from
map_picks().sorted_games – The return from
get_scores().season – Which season to extract from the other inputs.
week – Which week to extract from the other inputs.
- Returns:
All results, an element per user.
- supercontest.core.results.get_toprow_alltime_results(pick_counts: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, int]]]], point_rollups: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, float]]]]) tuple[list[int | float], int | float]
For each season, sums the total points across all users and the total picks across all users to determine a league-wide percentage. Then combines across all seasons to determine an alltime league-wide %. This doesn’t filter by league, remember; it’s the free league (all users).
- Parameters:
pick_counts – The return from
map_picks().point_rollups – The return from
map_picks().
- Returns:
Leaguewide pick percentages per season.
- Returns:
Rollup for alltime pick percentage, all users, all seasons, all leagues, etc.
- supercontest.core.results.get_toprow_season_results(pick_counts: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, int]]]], point_rollups: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, float]]]], season: int) tuple[list[float | int | None], float | int | None]
Takes the season results by user and calculates the leaguewide perf. This is the top row of the leaderboard. Percentage per week, as well as overall percentage for the season.
- Parameters:
pick_counts – The return from
map_picks().point_rollups – The return from
map_picks().season – Season. Just used to find max week, padding the future ones with empty values.
- Returns:
Leaguewide pick percentages. Length is the number of weeks in the season. Elements are None for future weeks with no data.
- Returns:
Rollup for the whole league, whole season.
- supercontest.core.results.get_toprow_week_results(sorted_games: list[Game], week_results: list[WeekResults]) list[tuple[int, int]]
Takes all picks from all users and aggregates them into the top row for leaguewide pick counts for that week.
- Parameters:
sorted_games – The return from
get_scores().week_results – The return from
calc_week_results().
- Returns:
The picks counts for each team in each matchup that week.
- supercontest.core.results.inject_alltime_results(sorted_alltime_results: list[AlltimeResults], raw_picks: defaultdict[int, defaultdict[int, defaultdict[int, list[Any]]]]) list[AlltimeResults]
Does the post-sort value injection. In-place, returning the same list-of-dicts with some new keys. Just rank for this one.
- Parameters:
sorted_alltime_results – The return from
sort_alltime_results().raw_picks – The return from
map_picks().
- Returns:
The same as the argument list, with keys injected into each dict element.
- supercontest.core.results.inject_season_results(sorted_season_results: list[SeasonResults], point_rollups: defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, float]]]], season: int, league_id: int = 0) tuple[list[SeasonResults], int]
Does the post-sort value injection. The season views do a lot more than the week views. Rank, percentile are standards for free leagues. This function also handles the logic for paid leagues, adding the purse/bonus/payout keys.
- Parameters:
sorted_season_results – The return from
sort_season_results().point_rollups – The return from
map_picks().season – Season.
league_id – League ID.
- Returns:
The same as the argument list, with keys injected into each dict element.
- Returns:
The remaining party fund after paid league distributions (0 if free league).
- supercontest.core.results.inject_week_results(sorted_games: list[Game], sorted_week_results: list[WeekResults], toprow_week_results: list[tuple[int, int]]) list[WeekResults]
Does the post-sort value injection. For WEEK view this is rank and pick score/grade. Remember rank considers ONLY completed games (whereas full sort considers more). Note that this mutates the argument, the passed dict - and then returns it anyway to be explicit. Grade is the measure for how similar your picks are to other users (higher = you agreed with other users, lower = more users picked the opponent of your pick).
- Parameters:
sorted_games – The return from
get_scores().sorted_week_results – The return from
sort_week_results().toprow_week_results – The picks counts for each team in each matchup that week.
- Returns:
The same as the argument list, with keys injected into each dict element.
- supercontest.core.results.map_picks(picks: list[Pick]) tuple[defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, int]]]], defaultdict[int, defaultdict[int, defaultdict[int, defaultdict[str, float]]]], defaultdict[int, defaultdict[int, defaultdict[int, list[Any]]]]]
Takes a raw list of pick rows and iterates over them to create the maps of pick counts and point rollups, all by season/week/user. Is scoped by the picks that you pass it; not some manual logic of seasons/weeks/users. Therefore this function works for all views.
- Parameters:
picks – The return from pick obj fetch. Pick counts and point rollups.
- Returns:
Pick counts.
- Returns:
Point rollups.
- Returns:
Raw pick objects.
- supercontest.core.results.sort_alltime_results(alltime_results: list[AlltimeResults]) list[AlltimeResults]
Sorts the alltime leaderboard. Remember, rank is only dependent upon points (same as regular lb), but this sort considers more. It’s deterministic, because the frontend has to show row by row. There are no ties in the visual organization space. Sort logic:
Greater total points
Greater pick cover percentage
Fewer pushes (to weight covers more than pushes, for same points)
User ID (similar to tenure, just keeping the sort deterministic)
- Parameters:
alltime_results – The return from
calc_alltime_results().- Returns:
The same as the argument list, but sorted.
- supercontest.core.results.sort_season_results(season_results: list[SeasonResults]) list[SeasonResults]
Sorts all user-week-point info. This is the same as the weekly sort for the all-picks view, but because it’s for the leaderboard (and graph), it only considers COMPLETED games. Sort logic:
Greater total points COMPLETED
Greater pick cover percentage
Fewer pushes (to weight covers more than pushes, for same points)
User ID (basically tenure, just keeping the sort deterministic)
- Parameters:
season_results – The return from
calc_season_results().- Returns:
The same as the argument list, but sorted.
- supercontest.core.results.sort_week_results(week_results: list[WeekResults]) list[WeekResults]
At the end of the day, only “total points” matters. However, we must display the rows on the site in a specific order, so we make that deterministic with the following logic:
Greater total points COMPLETED
Greater covers COMPLETED
Fewer noncovers COMPLETED
Greater total points IN PROGRESS
Greater covers IN PROGRESS
Fewer noncovers IN PROGRESS
Greater number of total picks (give advantage to more active players)
User ID (basically tenure, just keeping the sort deterministic)
- Parameters:
week_results – The return from
calc_week_results().- Returns:
The same as the argument list, but sorted.
- supercontest.core.results.view_allpicks(season: int, week: int, league_id: int) tuple[list[Game], list[WeekResults], list[tuple[int, int]]]
The entry point for the allpicks view.
- Parameters:
season – Season.
week – Week.
league_id – League ID.
- Returns:
Sorted score objects.
- Returns:
The final/sorted/injected list of user:results dicts.
- Returns:
The leaguewide pick counts for each team, paired by matchups.
- Returns:
The map of points by team.
- supercontest.core.results.view_alltime_leaderboard() tuple[list[AlltimeResults], list[int | float], int | float]
The entry point for the alltimelb view.
- Returns:
The final/sorted/injected list of user:results dicts.
- Returns:
Leaguewide pick percentages per season.
- Returns:
Rollup for alltime pick percentage, all users, all seasons, all leagues, etc.
- supercontest.core.results.view_leaderboard(season: int, league_id: int) tuple[list[SeasonResults], list[float | int | None], float | int | None, int]
The entry point for the leaderboard view.
- Parameters:
season – Season.
league_id – League ID.
- Returns:
The final/sorted/injected list of user:results dicts.
- Returns:
Leaguewide pick percentages. Length is the number of weeks in the season. Elements are None for future weeks with no data.
- Returns:
Rollup for the whole league, whole season.
- Returns:
The remaining party fund after paid league distributions (0 if free league).
- supercontest.core.results.view_matchups(season: int, week: int, user_id: int) tuple[list[Game], list[str]]
The entry point for the matchups view.
- Parameters:
season – Season.
week – Week.
user_id – User ID.
- Returns:
Sorted score objects.
- Returns:
The names of the teams this user picked this week.
- supercontest.core.results.view_progression(season: int, league_id: int) list[SeasonResults]
The entry point for the graph view.
- Parameters:
season – Season.
league_id – League ID.
- Returns:
The sorted list of user:results dicts.