def test_reject_too_may_teams(self): # type: () -> None # self-check self.assertGreater(len(simple_pos), 2, "Need more than two entrants") with self.assertRaises(ValueError): ranker.calc_ranked_points(simple_pos, num_zones=2)
def combined_semis_ranked_poitions(scores, final_match_info): semi_1_key = (final_match_info.arena, final_match_info.num - 1) semi_2_key = (final_match_info.arena, final_match_info.num - 2) if final_match_info.type == MatchType.tiebreaker: # The actual final was at n-1, so we need to use n-2 and n-3 semi_1_key = (final_match_info.arena, final_match_info.num - 2) semi_2_key = (final_match_info.arena, final_match_info.num - 3) semis_keys = (semi_1_key, semi_2_key) semis_game_points = {} for key in semis_keys: semis_game_points.update( scores.knockout.game_points[key], ) semis_dsq = [ tla for key in semis_keys for tla, pts in scores.knockout.ranked_points[key].items() if pts == 0 ] positions = ranker.calc_positions(semis_game_points, semis_dsq) ranked_points = ranker.calc_ranked_points(positions, semis_dsq) return ranked_points
def make_finals_score(game_points): positions = calc_positions(game_points) ranked = calc_ranked_points(positions) ko_scores = mock.Mock() ko_scores.game_points = {('A', 0): game_points} ko_scores.game_positions = {('A', 0): positions} ko_scores.ranked_points = {('A', 0): ranked} scores = mock.Mock() scores.knockout = ko_scores return scores
def __init__(self, arena, game, scores, dsq=()): positions = calc_positions(scores, dsq) league_points = calc_ranked_points(positions, dsq) team_key = {} gp_key = {} rp_key = {} for team, gp in scores.items(): lp = league_points[team] team_key[team] = TeamScore(league=lp, game=gp) gp_key[team] = gp rp_key[team] = lp self.teams = team_key self.game_points = {(arena, game): gp_key} self.ranked_points = {(arena, game): rp_key} self.game_positions = {(arena, game): positions} self.positions = OrderedDict() for position, teams in positions.items(): for team in teams: self.positions[team] = position
def _load_resfile(self, fname): y = yaml_loader.load(fname) match_id = (y["arena_id"], y["match_number"]) if match_id in self.game_points: raise DuplicateScoresheet(match_id) game_points = get_validated_scores(self._scorer, y) self.game_points[match_id] = game_points # Build the disqualification dict dsq = [] for tla, scoreinfo in y["teams"].items(): # disqualifications and non-presence are effectively the same # in terms of league points awarding. if (scoreinfo.get("disqualified", False) or not scoreinfo.get("present", True)): dsq.append(tla) positions = ranker.calc_positions(game_points, dsq) self.game_positions[match_id] = positions self.ranked_points[match_id] = ranker.calc_ranked_points( positions, dsq)
def _load_resfile(self, fname): y = yaml_loader.load(fname) match_id = (y["arena_id"], y["match_number"]) if match_id in self.game_points: raise DuplicateScoresheet(match_id) game_points = get_validated_scores(self._scorer, y) self.game_points[match_id] = game_points # Build the disqualification dict dsq = [] for tla, scoreinfo in y["teams"].items(): # disqualifications and non-presence are effectively the same # in terms of league points awarding. if (scoreinfo.get("disqualified", False) or not scoreinfo.get("present", True)): dsq.append(tla) positions = ranker.calc_positions(game_points, dsq) self.game_positions[match_id] = positions self.ranked_points[match_id] = \ ranker.calc_ranked_points(positions, dsq, self._num_corners)
def test_two_teams_two_spare_zones(self): # type: () -> None points = ranker.calc_ranked_points(two_teams_pos, num_zones=4) self.assertEqual(two_teams_points_4_zones, points, "Wrong points")
def test_simple_no_dsq(self): # type: () -> None points = ranker.calc_ranked_points(simple_pos) self.assertEqual(simple_points, points, "Wrong points")
def test_simple_spare_zone(self): # type: () -> None points = ranker.calc_ranked_points(simple_pos, num_zones=5) self.assertEqual(simple_points_5_zones, points, "Wrong points")
def test_simple_no_dsq(self): points = ranker.calc_ranked_points(simple_pos) assert simple_points == points, "Wrong points"
def test_tie_no_dsq(self): points = ranker.calc_ranked_points(tie1_pos) assert tie1_points == points, "Wrong points"
def test_detects_lower_position_overlap_double_tie(self): # type: () -> None with self.assertRaises(ValueError): ranker.calc_ranked_points(to_ranks({1: ['A', 'B', 'C'], 3: ['D']}))
def test_dsq_tie_one_spare_zone(self): # type: () -> None points = ranker.calc_ranked_points(tie2_pos, tie2_dsq, num_zones=5) self.assertEqual(tie2_points_5_zones, points, "Wrong points")
def test_dsq_tie_one_spare_zone(self): points = ranker.calc_ranked_points(tie2_pos, tie2_dsq, num_zones=5) self.assertEqual(tie2_points_5_zones, points, "Wrong points")
def test_dsq_tie(self): points = ranker.calc_ranked_points(tie2_pos, tie2_dsq) self.assertEqual(tie2_points_4_zones, points, "Wrong points")
def test_tie_no_dsq(self): points = ranker.calc_ranked_points(tie1_pos) self.assertEqual(tie1_points_4_zones, points, "Wrong points")
def test_two_teams_two_spare_zones(self): points = ranker.calc_ranked_points(two_teams_pos, num_zones=4) self.assertEqual(two_teams_points_4_zones, points, "Wrong points")
def test_dsq_tie(self): points = ranker.calc_ranked_points(tie2_pos, tie2_dsq) assert tie2_points == points, "Wrong points"
def test_tie_no_dsq(self): # type: () -> None points = ranker.calc_ranked_points(tie1_pos) self.assertEqual(tie1_points_4_zones, points, "Wrong points")
def test_dsq_tie(self): # type: () -> None points = ranker.calc_ranked_points(tie2_pos, tie2_dsq) self.assertEqual(tie2_points_4_zones, points, "Wrong points")
def test_simple_spare_zone(self): points = ranker.calc_ranked_points(simple_pos, num_zones=5) self.assertEqual(simple_points_5_zones, points, "Wrong points")
def test_detects_position_overlap_single_tie(self): # type: () -> None with self.assertRaises(ValueError): ranker.calc_ranked_points(to_ranks({1: ['A', 'B'], 2: ['C', 'D']}))
def test_simple_no_dsq(self): points = ranker.calc_ranked_points(simple_pos) self.assertEqual(simple_points, points, "Wrong points")
def test_detects_position_overlap_single_tie(self): with self.assertRaises(ValueError): ranker.calc_ranked_points({1: ['A', 'B'], 2: ['C', 'D']})
def test_tie(self): points = ranker.calc_ranked_points(tie1_pos, []) assert tie1_points == points, "Wrong points"
def test_detects_lower_position_overlap_double_tie(self): with self.assertRaises(ValueError): ranker.calc_ranked_points({1: ['A', 'B', 'C'], 3: ['D']})
def test_reject_too_may_teams(self): # self-check self.assertGreater(len(simple_pos), 2, "Need more than two entrants") with self.assertRaises(ValueError): ranker.calc_ranked_points(simple_pos, num_zones=2)