Exemple #1
0
    def __init__(self, y, league, teams):
        self.teams = teams
        """A mapping of TLAs to :class:`.Team` instances."""

        self.match_periods = []
        """
        A list of the :class:`.MatchPeriod` s which contain the matches
        for the competition.
        """

        for e in y["match_periods"]["league"]:
            if "max_end_time" in e:
                max_end_time = e["max_end_time"]
            else:
                max_end_time = e["end_time"]

            period = MatchPeriod(e["start_time"], e["end_time"], max_end_time,
                                 e["description"], [], MatchType.league)
            self.match_periods.append(period)

        self._configure_match_slot_lengths(y)
        self.staging_times = self._get_staging_times(y)

        self._build_extra_spacing(y["league"]['extra_spacing'])
        self._build_delaylist(y["delays"])
        self._build_matchlist(league)

        self.timezone = gettz(y.get('timezone', 'UTC'))

        self.n_league_matches = self.n_matches()
def build_match_period(start,
                       end,
                       max_end=None,
                       desc=None,
                       matches=None,
                       type_=None):
    return MatchPeriod(start, end, max_end or end, desc, matches, type_)
Exemple #3
0
def test_period_str():
    start = datetime(2014, 1, 1, 13, 12, 14)
    end = datetime(2014, 1, 1, 20, 6, 35)
    period = MatchPeriod(start, end, None, "desc", None, None)

    string = str(period)

    assert "desc (13:12–20:06)" == string, "Wrong string"
    def add_knockouts(self):
        period = self.config["match_periods"]["knockout"][0]
        self.period = MatchPeriod(period["start_time"], period["end_time"],
                                  period["end_time"], period["description"],
                                  [], MatchType.knockout)

        knockout_conf = self.config["static_knockout"]

        for round_num in sorted(knockout_conf.keys()):
            self.knockout_rounds += [[]]
            rounds_remaining = len(knockout_conf.keys()) - round_num - 1
            for match_num in sorted(knockout_conf[round_num].keys()):
                match_info = knockout_conf[round_num][match_num]
                self._add_match(match_info, rounds_remaining, match_num)
Exemple #5
0
    def add_tiebreaker(self, scores, time):
        """
        Add a tie breaker to the league if required. Also set a ``tiebreaker``
        attribute if necessary.

        :param scores: The scores.
        :param time: The time.
        """

        finals_info = self.knockout_rounds[-1][0]
        finals_key = (finals_info.arena, finals_info.num)
        try:
            finals_positions = scores.knockout.game_positions[finals_key]
        except KeyError:
            return
        winners = finals_positions.get(1)
        if not winners:
            raise AssertionError('The only winning move is not to play.')
        if len(winners) > 1:  # Act surprised!
            # Start with the winning teams in the same order as in the finals
            tiebreaker_teams = [
                team if team in winners else None for team in finals_info.teams
            ]
            # Use a static permutation
            permutation = [3, 2, 0, 1]
            tiebreaker_teams = [
                tiebreaker_teams[permutation[n]] for n in permutation
            ]
            # Inject new match
            end_time = time + self.match_duration
            num = self.n_matches()
            arena = finals_info.arena
            match = Match(num=num,
                          display_name="Tiebreaker (#{0})".format(num),
                          arena=arena,
                          teams=tiebreaker_teams,
                          type=MatchType.tiebreaker,
                          start_time=time,
                          end_time=end_time,
                          use_resolved_ranking=False)
            slot = {arena: match}
            self.matches.append(slot)
            match_period = MatchPeriod(time, end_time, end_time, 'Tiebreaker',
                                       [slot], MatchType.tiebreaker)
            self.match_periods.append(match_period)

            self.tiebreaker = match
def test_tiebreaker():
    schedule = make_schedule()
    scores = make_finals_score({'AAA': 1, 'BBB': 1, 'CCC': 1, 'DDD': 0})

    schedule.add_tiebreaker(scores, datetime.datetime(2014, 4, 25, 13, 0))

    assert schedule.tiebreaker

    start_time = datetime.datetime(2014, 4, 25, 13, 0)
    end_time = datetime.datetime(2014, 4, 25, 13, 5)

    tiebreaker_match = {
        'A':
        Match(num=1,
              display_name='Tiebreaker (#1)',
              arena='A',
              teams=['BBB', 'AAA', None, 'CCC'],
              start_time=start_time,
              end_time=end_time,
              type=MatchType.tiebreaker,
              use_resolved_ranking=False)
    }

    eq_(schedule.matches[-1], tiebreaker_match)

    last_period = schedule.match_periods[-1]
    last_period_matches = last_period.matches

    assert last_period_matches == [tiebreaker_match
                                   ], "Wrong matches in last period"

    last_period_matches.pop()  # simplify the next comparison

    expected_period = MatchPeriod(start_time, end_time, end_time, 'Tiebreaker',
                                  [], MatchType.tiebreaker)

    assert last_period == expected_period, "Wrong last period"
    def add_knockouts(self):
        """Add the knockouts to the schedule."""

        period = self.config["match_periods"]["knockout"][0]

        self.period = MatchPeriod(period["start_time"], period["end_time"],
                                  period["end_time"], period["description"],
                                  [], MatchType.knockout)

        self.clock = MatchPeriodClock(self.period, self.schedule.delays)

        knockout_conf = self.config["knockout"]
        round_spacing = timedelta(seconds=knockout_conf["round_spacing"])

        self._add_first_round(conf_arity=knockout_conf.get('arity'))

        while len(self.knockout_rounds[-1]) > 1:

            # Add the delay between rounds
            self.clock.advance_time(round_spacing)

            # Number of rounds remaining to be added
            rounds_remaining = self.get_rounds_remaining(
                self.knockout_rounds[-1])

            if rounds_remaining <= knockout_conf["single_arena"]["rounds"]:
                arenas = knockout_conf["single_arena"]["arenas"]
            else:
                arenas = self.arenas

            if len(self.knockout_rounds[-1]) == 2:
                "Extra delay before the final match"
                final_delay = timedelta(seconds=knockout_conf["final_delay"])
                self.clock.advance_time(final_delay)

            self._add_round(arenas, rounds_remaining - 1)