Exemplo n.º 1
0
    def _build_matchlist(self, yamldata):
        """Build the match list."""
        self.matches = []
        if yamldata is None:
            self.n_planned_league_matches = 0
            return

        match_numbers = sorted(yamldata.keys())
        self.n_planned_league_matches = len(match_numbers)

        if tuple(match_numbers) != tuple(range(len(match_numbers))):
            raise Exception("Matches are not a complete 0-N range")

        # Effectively just the .values(), except that it's ordered by number
        raw_matches = [yamldata[m] for m in match_numbers]

        match_n = 0

        for period in self.match_periods:
            # Fill this period with matches

            clock = MatchPeriodClock(period, self.delays)

            # No extra spacing for matches at the start of a period

            # Fill this match period with matches
            for start in clock.iterslots(self.match_duration):
                try:
                    arenas = raw_matches.pop(0)
                except IndexError:
                    # no more matches left
                    break

                m = {}

                end_time = start + self.match_duration
                for arena_name, teams in arenas.items():
                    teams = self.remove_drop_outs(teams, match_n)
                    display_name = 'Match {n}'.format(n=match_n)
                    match = Match(match_n,
                                  display_name,
                                  arena_name,
                                  teams,
                                  start,
                                  end_time,
                                  MatchType.league,
                                  use_resolved_ranking=False)
                    m[arena_name] = match

                period.matches.append(m)
                self.matches.append(m)

                match_n += 1

                extra_spacing = self._spacing.get(match_n)
                if extra_spacing:
                    clock.advance_time(extra_spacing)
Exemplo n.º 2
0
def test_slots_delay_after():
    period = build_match_period(0, 4)
    clock = MatchPeriodClock(period, [Delay(time=6, delay=2)])

    curr_time = clock.current_time
    assert 0 == curr_time, "Should start at the start of the period"

    slots = list(clock.iterslots(1))
    expected = list(range(5))
    assert expected == slots
def test_slots_delay_after():
    period = build_match_period(0, 4)
    clock = MatchPeriodClock(period, [Delay(time=6, delay=2)])

    curr_time = clock.current_time
    assert 0 == curr_time, "Should start at the start of the period"

    slots = list(clock.iterslots(1))
    expected = list(range(5))
    assert expected == slots
Exemplo n.º 4
0
    def _build_matchlist(self, yamldata):
        """Build the match list."""
        self.matches = []
        if yamldata is None:
            self.n_planned_league_matches = 0
            return

        match_numbers = sorted(yamldata.keys())
        self.n_planned_league_matches = len(match_numbers)

        if tuple(match_numbers) != tuple(range(len(match_numbers))):
            raise Exception("Matches are not a complete 0-N range")

        # Effectively just the .values(), except that it's ordered by number
        raw_matches = [yamldata[m] for m in match_numbers]

        match_n = 0

        for period in self.match_periods:
            # Fill this period with matches

            clock = MatchPeriodClock(period, self.delays)

            # No extra spacing for matches at the start of a period

            # Fill this match period with matches
            for start in clock.iterslots(self.match_duration):
                try:
                    arenas = raw_matches.pop(0)
                except IndexError:
                    # no more matches left
                    break

                m = {}

                end_time = start + self.match_duration
                for arena_name, teams in arenas.items():
                    teams = self.remove_drop_outs(teams, match_n)
                    display_name = 'Match {n}'.format(n=match_n)
                    match = Match(match_n, display_name, arena_name, teams,
                                  start, end_time, MatchType.league,
                                  use_resolved_ranking=False)
                    m[arena_name] = match

                period.matches.append(m)
                self.matches.append(m)

                match_n += 1

                extra_spacing = self._spacing.get(match_n)
                if extra_spacing:
                    clock.advance_time(extra_spacing)
def test_slots_extra_gap():
    period = build_match_period(0, 6)
    clock = MatchPeriodClock(period, [])
    slots = []
    first_time = True
    for start in clock.iterslots(2):
        slots.append(clock.current_time)
        if first_time:
            # Advance an extra 3 the first time
            clock.advance_time(3)
            # Now at 5
            first_time = False
    expected = [0, 5]
    assert expected == slots
Exemplo n.º 6
0
def test_slots_extra_gap():
    period = build_match_period(0, 6)
    clock = MatchPeriodClock(period, [])
    slots = []
    first_time = True
    for start in clock.iterslots(2):
        slots.append(clock.current_time)
        if first_time:
            # Advance an extra 3 the first time
            clock.advance_time(3)
            # Now at 5
            first_time = False
    expected = [0, 5]
    assert expected == slots
def test_slots_delay_during():
    period = build_match_period(0, 4, 5)
    clock = MatchPeriodClock(period, [Delay(time=1, delay=3)])
    slots = list(clock.iterslots(2))
    expected = [0, 5]
    assert expected == slots
def test_slots_no_delays_2():
    period = build_match_period(0, 4)
    clock = MatchPeriodClock(period, [])
    slots = list(clock.iterslots(2))
    expected = [0, 2, 4]
    assert expected == slots
def test_slots_no_delays_1():
    period = build_match_period(0, 4)
    clock = MatchPeriodClock(period, [])
    slots = list(clock.iterslots(1))
    expected = list(range(5))
    assert expected == slots
Exemplo n.º 10
0
def test_slots_delay_during():
    period = build_match_period(0, 4, 5)
    clock = MatchPeriodClock(period, [Delay(time=1, delay=3)])
    slots = list(clock.iterslots(2))
    expected = [0, 5]
    assert expected == slots
Exemplo n.º 11
0
def test_slots_no_delays_2():
    period = build_match_period(0, 4)
    clock = MatchPeriodClock(period, [])
    slots = list(clock.iterslots(2))
    expected = [0, 2, 4]
    assert expected == slots
Exemplo n.º 12
0
def test_slots_no_delays_1():
    period = build_match_period(0, 4)
    clock = MatchPeriodClock(period, [])
    slots = list(clock.iterslots(1))
    expected = list(range(5))
    assert expected == slots