Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
 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")
Ejemplo n.º 10
0
 def test_simple_no_dsq(self):
     # type: () -> None
     points = ranker.calc_ranked_points(simple_pos)
     self.assertEqual(simple_points, points, "Wrong points")
Ejemplo n.º 11
0
 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")
Ejemplo n.º 12
0
 def test_simple_no_dsq(self):
     points = ranker.calc_ranked_points(simple_pos)
     assert simple_points == points, "Wrong points"
Ejemplo n.º 13
0
 def test_tie_no_dsq(self):
     points = ranker.calc_ranked_points(tie1_pos)
     assert tie1_points == points, "Wrong points"
Ejemplo n.º 14
0
 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']}))
Ejemplo n.º 15
0
 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")
Ejemplo n.º 16
0
 def test_tie_no_dsq(self):
     points = ranker.calc_ranked_points(tie1_pos)
     assert tie1_points == points, "Wrong points"
Ejemplo n.º 17
0
 def test_simple_no_dsq(self):
     points = ranker.calc_ranked_points(simple_pos)
     assert simple_points == points, "Wrong points"
Ejemplo n.º 18
0
 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")
Ejemplo n.º 19
0
 def test_dsq_tie(self):
     points = ranker.calc_ranked_points(tie2_pos, tie2_dsq)
     self.assertEqual(tie2_points_4_zones, points, "Wrong points")
Ejemplo n.º 20
0
 def test_tie_no_dsq(self):
     points = ranker.calc_ranked_points(tie1_pos)
     self.assertEqual(tie1_points_4_zones, points, "Wrong points")
Ejemplo n.º 21
0
 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")
Ejemplo n.º 22
0
 def test_dsq_tie(self):
     points = ranker.calc_ranked_points(tie2_pos, tie2_dsq)
     assert tie2_points == points, "Wrong points"
Ejemplo n.º 23
0
 def test_tie_no_dsq(self):
     # type: () -> None
     points = ranker.calc_ranked_points(tie1_pos)
     self.assertEqual(tie1_points_4_zones, points, "Wrong points")
Ejemplo n.º 24
0
 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")
Ejemplo n.º 25
0
 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")
Ejemplo n.º 26
0
 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']}))
Ejemplo n.º 27
0
 def test_simple_no_dsq(self):
     points = ranker.calc_ranked_points(simple_pos)
     self.assertEqual(simple_points, points, "Wrong points")
Ejemplo n.º 28
0
 def test_detects_position_overlap_single_tie(self):
     with self.assertRaises(ValueError):
         ranker.calc_ranked_points({1: ['A', 'B'], 2: ['C', 'D']})
Ejemplo n.º 29
0
 def test_tie(self):
     points = ranker.calc_ranked_points(tie1_pos, [])
     assert tie1_points == points, "Wrong points"
Ejemplo n.º 30
0
 def test_tie(self):
     points = ranker.calc_ranked_points(tie1_pos, [])
     assert tie1_points == points, "Wrong points"
Ejemplo n.º 31
0
 def test_detects_lower_position_overlap_double_tie(self):
     with self.assertRaises(ValueError):
         ranker.calc_ranked_points({1: ['A', 'B', 'C'], 3: ['D']})
Ejemplo n.º 32
0
 def test_dsq_tie(self):
     points = ranker.calc_ranked_points(tie2_pos, tie2_dsq)
     assert tie2_points == points, "Wrong points"
Ejemplo n.º 33
0
    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)