supercontest.core.results

Calculations for the portions of views with results. Ordered by increasing complexity.

General scopes for the views:

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:

  1. query_: get the raw data, usually picks / matchups, scoped by the view

  2. map_: iterate over raw picks and key pick counts / points by season / week / user

  3. calculate_: calculate / restructure as necessary to yield lists of user-result dicts

  4. sort_: order those elements by the approprate keys

  5. inject_: some information can only be calculated post-sort (eg ranks, payouts) - add those

  6. toprow_: a final list of aggregations across a col (rather than row), for leaguewide results

Functions

calc_alltime_results

Picks counts, rollups (points, total picks, etc) - data dictionaries for every user.

calc_season_results

Picks counts, rollups (points, total picks, etc) - data dictionaries for every user.

calc_week_results

Picks counts, rollups (points, total picks, etc) - data dictionaries for every user.

get_toprow_alltime_results

For each season, sums the total points across all users and the total picks across all users to determine a league-wide percentage.

get_toprow_season_results

Takes the season results by user and calculates the leaguewide perf.

get_toprow_week_results

Takes all picks from all users and aggregates them into the top row for leaguewide pick counts for that week.

inject_alltime_results

Does the post-sort value injection.

inject_season_results

Does the post-sort value injection.

inject_week_results

Does the post-sort value injection.

map_picks

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.

sort_alltime_results

Sorts the alltime leaderboard.

sort_season_results

Sorts all user-week-point info.

sort_week_results

At the end of the day, only "total points" matters.

view_allpicks

The entry point for the allpicks view.

view_alltime_leaderboard

The entry point for the alltimelb view.

view_leaderboard

The entry point for the leaderboard view.

view_matchups

The entry point for the matchups view.

view_progression

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:
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_scores input 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:
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:
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:
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:

  1. Greater total points

  2. Greater pick cover percentage

  3. Fewer pushes (to weight covers more than pushes, for same points)

  4. 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:

  1. Greater total points COMPLETED

  2. Greater pick cover percentage

  3. Fewer pushes (to weight covers more than pushes, for same points)

  4. 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:

  1. Greater total points COMPLETED

  2. Greater covers COMPLETED

  3. Fewer noncovers COMPLETED

  4. Greater total points IN PROGRESS

  5. Greater covers IN PROGRESS

  6. Fewer noncovers IN PROGRESS

  7. Greater number of total picks (give advantage to more active players)

  8. 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.