API¶
Conversions of game points into league points.
- league_ranker.calc_positions(zpoints: Mapping[league_ranker.TZone, league_ranker.TGamePoints], dsq_list: Container[league_ranker.TZone] = ()) Dict[league_ranker.RankedPosition, Set[league_ranker.TZone]] [source]¶
Calculate positions from a map of zones to in-game points.
- Parameters
zpoints (dict) – A mapping from some key (typically a zone or corner name) to game points (usually a numeric type, but can be any type that is comparable and usable as a key for dictionaries).
dsq_list (list) – If provided, is a
list
of keys of teams or zones that have been disqualified and are therefore considered below last place.
- Returns
A mapping from positions to an iterable of teams in that position.
- Return type
Note
In case of a tie, both teams are awarded the same position, as is usual in sport. That is, if team A has 3 points, team B has 3 points and team C has 1 point, then teams A and B are both awarded 1st, and C is awarded 3rd.
Examples
Some examples of usage are shown below:
>>> calc_positions({'A': 3, 'B': 3, 'C': 1}) {1: {'A', 'B'}, 3: {'C'}}
>>> calc_positions({'A': 3, 'B': 3, 'C': 0, 'D': 0}, ['A', 'C']) {1: {'B'}, 2: {'D'}, 3: {'A', 'C'}}
- league_ranker.calc_ranked_points(pos_map: Mapping[league_ranker.RankedPosition, Collection[league_ranker.TZone]], dsq_list: Sequence[league_ranker.TZone] = (), num_zones: int = 4) Dict[league_ranker.TZone, league_ranker.LeaguePoints] [source]¶
Calculate league points from a mapping of positions to teams.
The league points algorithm is documented in The League Points algorithm.
- Parameters
pos_map (dict) – A mapping from positions (integers indicating ending position, such as 1 for 1st, 3 for 3rd etc) to some iterable of teams or zones in that position.
dsq_list (list) – If provided, is a
list
of teams or zones that are considered to be disqualified.num_zones (int) – The overall number of zones. This is usually the same as the total number of zones/team provided in
pos_map
(and cannot be less than that), though may be more if there were empty zones during some given match.
- Returns
A mapping from zones/teams to league points.
- Return type
Examples
Uniquely placed teams in a four-zone arena would earn 8, 6, 4 and 2 points for first through fourth place respectively.
Three teams tied for first place in a four-zone arena will each earn 6 points (since this is
(8+6+4)/3
).Some examples of usage are shown below.
>>> calc_ranked_points({1: ['A'], 2: ['B'], 3: ['C'], 4: ['D']}) {'A': 8, 'B': 6, 'C': 4, 'D': 2}
>>> calc_ranked_points({1: ['A', 'B'], 2: ['C', 'D']}) Traceback (most recent call last): ... ValueError: Cannot have position 2 when position 1 is shared by 2 zones
>>> calc_ranked_points({1: ['A', 'B'], 3: ['C', 'D']}) {'A': 7, 'B': 7, 'C': 3, 'D': 3}
>>> calc_ranked_points({1: ['A', 'B']}, num_zones=3) {'A': 5, 'B': 5}
>>> calc_ranked_points({1: ['B'], 2: ['D'], 3: ['A', 'C']}, ['A', 'C']) {'A': 0, 'B': 8, 'C': 0, 'D': 6}
- league_ranker.get_ranked_points(zpoints: Mapping[league_ranker.TZone, league_ranker.TGamePoints], dsq: Sequence[league_ranker.TZone] = (), num_zones: int = 4) Dict[league_ranker.TZone, league_ranker.LeaguePoints] [source]¶
Compute, from a mapping of teams to game points, the teams’ league points.
This is a convenience wrapper around calc_positions and calc_rank_points.
Examples
An example of usage is shown below.
>>> get_ranked_points({'A': 1, 'B': 3, 'C': 3, 'D': 4}, ['A']) {'A': 0, 'B': 5, 'C': 5, 'D': 8}