Esempio n. 1
0
 def populate_competitions(self):
     challenge = Challenge.objects.all()[0]
     maps = list(Map.objects.all())
     competition = Competition()
     competition.type = 'friendly'
     competition.challenge = challenge
     competition.save()
     for map in maps:
         competition.maps.add(map)
Esempio n. 2
0
def populate_competitions():
    challenge = Challenge.objects.all()[0]
    maps = list(Map.objects.all())
    types = ['elim', 'league', 'double']
    for i in range(3):
        competition = Competition()
        competition.type = types[i]
        competition.challenge = challenge
        competition.save()
        for map in maps:
            competition.maps.add(map)
Esempio n. 3
0
    def test_create_new_league(self):
        challenge = Challenge.objects.all()[0]
        for team in Team.objects.all():
            participation = TeamParticipatesChallenge()
            participation.team = team
            participation.challenge = challenge
            participation.save()
        competition = Competition(challenge=challenge, type='league')
        competition.save()

        maps = list(Map.objects.all())
        for map in maps:
            competition.maps.add(map)

        competition.create_new_league(teams=Team.objects.all(), rounds_num=2)

        # expected result
        # 1 -> 3
        # 2 -> 4
        # 1 -> 4
        # 3 -> 2
        # 1 -> 2
        # 4 -> 3
        # 3 -> 1
        # 4 -> 2
        # 4 -> 1
        # 2 -> 3
        # 2 -> 1
        # 3 -> 4

        matches = list(Match.objects.all())

        self.assertEqual(matches[0].part1.object_id, 1)
        self.assertEqual(matches[0].part2.object_id, 3)
        self.assertEqual(matches[1].part1.object_id, 3)
        self.assertEqual(matches[1].part2.object_id, 2)
        self.assertEqual(matches[2].part1.object_id, 1)
        self.assertEqual(matches[2].part2.object_id, 2)
        self.assertEqual(matches[3].part2.object_id, 1)
        self.assertEqual(matches[3].part1.object_id, 3)
        self.assertEqual(matches[4].part2.object_id, 3)
        self.assertEqual(matches[4].part1.object_id, 2)
        self.assertEqual(matches[5].part2.object_id, 1)
        self.assertEqual(matches[5].part1.object_id, 2)
Esempio n. 4
0
    def create_new_double_elimination(self, request, queryset):
        teams = list(queryset)
        if len(teams) < 1:
            from django.contrib import messages
            messages.error(request, _('no selected teams!'))
            return

        first_challenge = teams[0].challenge
        for team in teams:
            if team.challenge != first_challenge:
                from django.contrib import messages
                messages.error(request, _('Only teams from one challenge!'))
                return
        new_competition = Competition(challenge=first_challenge, name=str(len(first_challenge.competitions.all()) + 1),
                                      type='double')
        new_competition.save()
        new_competition.create_new_double_elimination(
            [team.team for team in teams]
        )
        new_competition.save()
Esempio n. 5
0
    def test_create_new_double_elimination(self):
        challenge = Challenge.objects.all()[0]
        for team in Team.objects.all():
            participation = TeamParticipatesChallenge()
            participation.team = team
            participation.challenge = challenge
            participation.save()

        competition = Competition(challenge=challenge, type='double')
        competition.save()

        maps = list(Map.objects.all())
        for map in maps:
            competition.maps.add(map)

        competition.create_new_double_elimination(teams=Team.objects.all())

        # expected result
        # 1 -> 2
        # 3 -> 4
        # 1 -> 2
        # 1 -> 2
        # 4 -> 3
        # 5 -> 3
        # 5 -> 3
        #
        matches = list(Match.objects.all())
        self.assertEqual(matches[0].part1.object_id, 1)
        self.assertEqual(matches[0].part2.object_id, 2)
        self.assertEqual(matches[1].part1.object_id, 3)
        self.assertEqual(matches[1].part2.object_id, None)
        self.assertEqual(matches[2].part1.object_id, 1)
        self.assertEqual(matches[2].part2.object_id, 2)
        self.assertEqual(matches[3].part1.object_id, 1)
        self.assertEqual(matches[3].part2.object_id, 2)
        self.assertEqual(matches[4].part1.object_id, 4)
        self.assertEqual(matches[4].part2.object_id, 3)
        self.assertEqual(matches[5].part1.object_id, 3)
        self.assertEqual(matches[5].part2.object_id, 5)
        self.assertEqual(matches[6].part1.object_id, 3)
        self.assertEqual(matches[6].part2.object_id, 5)
Esempio n. 6
0
    def handle(self, *args, **options):
        challenge_id = options['challenge_id']
        try:
            challenge = Challenge.objects.get(id=challenge_id)
        except Challenge.DoesNotExist:
            raise CommandError('Challenge  "%s" does not exist.' % challenge_id)

        team_pcs = challenge.teams.all()

        try:
            dummy_team = TeamParticipatesChallenge.objects.get(
                id=options['test_team_pc_id']).team
        except TeamParticipatesChallenge.DoesNotExist:
            raise CommandError('Dummy team "%s" does not exist.' % options['test_team_pc_id'])

        group_size = options['group_size']
        if group_size < 1:
            raise CommandError('group_size should be more than 0')

        submitters = []
        for team_pc in team_pcs:
            if team_pc.has_submitted():
                if team_pc.team != dummy_team:
                    submitters.append(team_pc.team)

        shuffle(submitters)

        n = submitters.__len__()
        submitters += [dummy_team for i in range((group_size - n % group_size) % group_size)]
        n = submitters.__len__()

        groups = [[] for i in range(n // group_size)]

        for i in range(n):
            groups[i % (groups.__len__())].append(submitters[i])

        for i in range(groups.__len__()):
            competition = Competition(
                tag=options['tag'],
                challenge=challenge,
                type='league',
                name='گروه %d لیگ اولیه انتخابی' % (i+1)
            )
            competition.save()
            for map in Map.objects.filter(name__in=options['map_name']):
                competition.maps.add(map)
            competition.save()
            competition.create_new_league(groups[i], 1)
            competition.save()

        self.stdout.write(self.style.SUCCESS('Successfully created seeding league.'))