Exemple #1
0
 def get(self, request, round):
     template = loader.get_template('display/table.html')
     context = RequestContext(request, {
         'display_round' : int(round),
         'debates' : Debate.objects.all().filter(round=round),
         'max_round' : Tournament.instance().round,
         'all_rounds' : range(1, Tournament.instance().round+1)
     })
     return HttpResponse(template.render(context))
    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
Exemple #3
0
 def testRaiseExceptionIfRoundHasPassed(self):
     result = generate_objects.valid_result_with_debate()
     tournament = Tournament.instance()
     tournament.round = 2
     tournament.save()
     with self.assertRaises(TournamentStateException):
         result.full_clean()
    def results_entered_for_round(self, round):
        if round > Tournament.instance().round:
            raise TournamentStateException("Round has not yet been drawn")

        for debate in Debate.objects.filter(round=round):
            if not debate.has_result:
                return False
        return True
Exemple #5
0
    def create_pools(self, teams, max_round):
        if not self.resultsController.results_entered_for_round(Tournament.instance().round):
            raise TournamentStateException("All results for current round must be entered to draw")
        pools = self.create_blank_pools(max_round)

        for team in teams:
            points = self.pointsController.total_points_for_team(team, 1)
            pools[points].append(team)

        return pools
Exemple #6
0
    def get(self, request, round):

        if int(round) < 1 or int(round) > Tournament.instance().round:
            raise Http404

        points_controller = PointsController()

        debates = Debate.objects.filter(round=round)
        template = loader.get_template('results/results_table.html')
        context = RequestContext(request, {
            'round' : int(round),
            'debates' : debates,
            'max_round' : Tournament.instance().round,
            'all_rounds' : range(1, Tournament.instance().round+1),
            'points' : points_controller.team_points_map_for_round(Tournament.instance().round, Team.objects.all())

        })
        return HttpResponse(template.render(context))

        return HttpResponse(round)
Exemple #7
0
 def draw_next_round(self):
     tournament = Tournament.instance()
     next_round = tournament.round + 1
     pools = self.create_pools(Team.objects.all(), tournament.round)
     pools = self.remove_empty(pools)
     pools = self.shuffle_pools(pools)
     pools = self.balance_pools(pools)
     debates = self.draw_from_pools(next_round, pools)
     tournament.round = next_round
     tournament.save()
     mapper = VenueMapper()
     mapper.map_venues(next_round)
     return debates
Exemple #8
0
    def get(self, request):
        template = loader.get_template('draw/index.html')

        team_count = Team.objects.all().count()
        results_controller = ResultsController()
        tournament = Tournament.instance()

        context = RequestContext(request, {
            'teams_count' : Team.objects.all().count(),
            'teams_ok' : (team_count % 4 == 0) and (team_count >= 4),
            'rooms' : team_count / 4,
            'venues_ok' : Venue.objects.all().count() >= team_count/4,
            'tournament' : tournament,
            'this_round' : tournament.round,
            'next_round' : tournament.round + 1,
            'results_entered' : results_controller.results_entered_for_round(tournament.round)
        })
        return HttpResponse(template.render(context))
Exemple #9
0
 def total_speaker_sum(self):
     from results.controllers.PointsController import PointsController
     controller = PointsController()
     from draw.models import Tournament
     return sum(controller.speaker_points_for_team(self, Tournament.instance().round_with_results))
 def testRaisesExceptionForRoundNotDrawn(self):
     tournament = Tournament.instance()
     tournament.round = 1
     tournament.save()
     with self.assertRaises(TournamentStateException):
         self.resultController.results_entered_for_round(10)
Exemple #11
0
 def get(self, request):
     return HttpResponseRedirect('/results/round/' + str(Tournament.instance().round))
 def max_round_with_results(self):
     current_round = Tournament.instance().round
     if self.results_entered_for_round(current_round):
         return current_round
     else:
         return current_round - 1
Exemple #13
0
def check_round_not_passed(result):
    if result.debate.round < Tournament.instance().round:
        raise TournamentStateException("Can't save a result for a round that has already finished")
 def testThrows404ForTooHighRound(self):
     tournament = Tournament.instance()
     tournament.save()
     view = ResultsTableView()
     with self.assertRaises(Http404):
         view.get(None, 2)