def initial_draw(self):

        tournament = Tournament.instance()
        if tournament.round != 0:
            raise TournamentStateException("Round must be 0 for initial draw to happen")

        teams = list(Team.objects.all())
        shuffle(teams)
        num_teams = len(teams)

        if num_teams < 4:
            raise TournamentStateException("Number of teams must be 4 or more")

        if num_teams%4 != 0:
            raise TournamentStateException("Number of teams must be a multiple of 4")

        num_debates = num_teams / 4
        debates = []

        for i in range(0,num_debates):
            debate = Debate()
            debate.round = 1
            debate.OG = teams[(i*4) +0]
            debate.OO = teams[(i*4) +1]
            debate.CG = teams[(i*4) +2]
            debate.CO = teams[(i*4) +3]

            debate.full_clean()
            debate.save()
            debates.append(debate)

        tournament.round = 1
        tournament.save()

        return debates
Beispiel #2
0
    def draw_from_pools(self, round, pools):
        debates = []
        for pool in pools.values():
            if len(pool) % 4 != 0:
                raise ValueError("Number of teams must be divisible by four")

            num_debates = len(pool) / 4

            for i in range(0, num_debates):
                debate = Debate(round=round)
                debate.OG = pool[(i * 4)]
                debate.OO = pool[(i * 4) + 1]
                debate.CG = pool[(i * 4) + 2]
                debate.CO = pool[(i * 4) + 3]
                debate.full_clean()
                debate.save()
                debates.append(debate)
        return debates