def test_schedule_generation(self):
     """Test quadruple round-robin schedule generation."""
     scheduler = QuadrupleRoundRobinScheduler(6)
     # Failed attempt
     random.seed(4)
     self.assertRaises(ScheduleGenerationFailed,
                       scheduler.generate_schedule, try_once=True)
     # Successful attempt
     random.seed(1)
     if PY2:
         expected_schedule = [
             [(5, 2), (6, 1), (4, 3)],
             [(1, 2), (3, 5), (4, 6)],
             [(5, 6), (3, 1), (4, 2)],
             [(4, 6), (1, 5), (2, 3)],
             [(2, 6), (5, 3), (4, 1)],
             [(2, 5), (3, 4), (6, 1)],
             [(4, 5), (2, 1), (3, 6)],
             [(2, 4), (1, 3), (6, 5)],
             [(3, 5), (2, 4), (1, 6)],
             [(2, 5), (4, 1), (3, 6)],
             [(5, 1), (6, 4), (3, 2)],
             [(4, 2), (5, 3), (1, 6)],
             [(1, 2), (4, 5), (6, 3)],
             [(2, 6), (1, 5), (4, 3)],
             [(6, 2), (3, 4), (5, 1)],
             [(5, 6), (3, 2), (1, 4)],
             [(5, 4), (6, 3), (2, 1)],
             [(5, 4), (1, 3), (6, 2)],
             [(3, 1), (5, 2), (6, 4)],
             [(2, 3), (6, 5), (1, 4)]
         ]
     elif PY3:
         expected_schedule = [
             [(6, 2), (5, 4), (3, 1)],
             [(5, 3), (2, 4), (1, 6)],
             [(1, 4), (6, 2), (5, 3)],
             [(6, 5), (1, 3), (4, 2)],
             [(1, 6), (3, 4), (5, 2)],
             [(1, 2), (5, 4), (3, 6)],
             [(2, 1), (6, 4), (3, 5)],
             [(4, 6), (5, 1), (3, 2)],
             [(5, 2), (3, 1), (4, 6)],
             [(2, 4), (5, 6), (1, 3)],
             [(5, 1), (2, 6), (3, 4)],
             [(6, 1), (2, 3), (4, 5)],
             [(4, 3), (2, 1), (6, 5)],
             [(3, 5), (6, 1), (4, 2)],
             [(1, 5), (2, 3), (6, 4)],
             [(1, 2), (6, 3), (4, 5)],
             [(2, 5), (4, 1), (6, 3)],
             [(1, 4), (3, 6), (2, 5)],
             [(3, 2), (4, 1), (5, 6)],
             [(1, 5), (2, 6), (4, 3)]
         ]
     schedule = scheduler.generate_schedule(try_once=True)
     self.assertListEqual(expected_schedule, schedule,
                          ('Wrong schedule created for '
                           'quadruple round-robin competition'))
 def test_schedule_generation(self):
     """Test quadruple round-robin schedule generation."""
     scheduler = QuadrupleRoundRobinScheduler(6)
     # Failed attempt
     random.seed(4)
     self.assertRaises(ScheduleGenerationFailed,
                       scheduler.generate_schedule,
                       try_once=True)
     # Successful attempt
     random.seed(1)
     if PY2:
         expected_schedule = [[(5, 2), (6, 1), (4, 3)],
                              [(1, 2), (3, 5), (4, 6)],
                              [(5, 6), (3, 1), (4, 2)],
                              [(4, 6), (1, 5), (2, 3)],
                              [(2, 6), (5, 3), (4, 1)],
                              [(2, 5), (3, 4), (6, 1)],
                              [(4, 5), (2, 1), (3, 6)],
                              [(2, 4), (1, 3), (6, 5)],
                              [(3, 5), (2, 4), (1, 6)],
                              [(2, 5), (4, 1), (3, 6)],
                              [(5, 1), (6, 4), (3, 2)],
                              [(4, 2), (5, 3), (1, 6)],
                              [(1, 2), (4, 5), (6, 3)],
                              [(2, 6), (1, 5), (4, 3)],
                              [(6, 2), (3, 4), (5, 1)],
                              [(5, 6), (3, 2), (1, 4)],
                              [(5, 4), (6, 3), (2, 1)],
                              [(5, 4), (1, 3), (6, 2)],
                              [(3, 1), (5, 2), (6, 4)],
                              [(2, 3), (6, 5), (1, 4)]]
     elif PY3:
         expected_schedule = [[(6, 2), (5, 4), (3, 1)],
                              [(5, 3), (2, 4), (1, 6)],
                              [(1, 4), (6, 2), (5, 3)],
                              [(6, 5), (1, 3), (4, 2)],
                              [(1, 6), (3, 4), (5, 2)],
                              [(1, 2), (5, 4), (3, 6)],
                              [(2, 1), (6, 4), (3, 5)],
                              [(4, 6), (5, 1), (3, 2)],
                              [(5, 2), (3, 1), (4, 6)],
                              [(2, 4), (5, 6), (1, 3)],
                              [(5, 1), (2, 6), (3, 4)],
                              [(6, 1), (2, 3), (4, 5)],
                              [(4, 3), (2, 1), (6, 5)],
                              [(3, 5), (6, 1), (4, 2)],
                              [(1, 5), (2, 3), (6, 4)],
                              [(1, 2), (6, 3), (4, 5)],
                              [(2, 5), (4, 1), (6, 3)],
                              [(1, 4), (3, 6), (2, 5)],
                              [(3, 2), (4, 1), (5, 6)],
                              [(1, 5), (2, 6), (4, 3)]]
     schedule = scheduler.generate_schedule(try_once=True)
     self.assertListEqual(expected_schedule, schedule,
                          ('Wrong schedule created for '
                           'quadruple round-robin competition'))
 def test_repeated_schedule_generation(self):
     """Test repeated quadruple round-robin schedule generation."""
     scheduler = QuadrupleRoundRobinScheduler(6)
     random.seed(4)
     if PY2:
         expected_schedule = [
             [(4, 1), (2, 6), (3, 5)],
             [(5, 2), (3, 6), (1, 4)],
             [(1, 5), (4, 6), (2, 3)],
             [(1, 3), (6, 5), (2, 4)],
             [(6, 2), (3, 4), (5, 1)],
             [(1, 2), (6, 3), (4, 5)],
             [(5, 2), (1, 6), (4, 3)],
             [(6, 1), (4, 2), (5, 3)],
             [(1, 3), (4, 5), (6, 2)],
             [(3, 2), (4, 6), (5, 1)],
             [(2, 6), (4, 3), (1, 5)],
             [(5, 6), (4, 1), (3, 2)],
             [(1, 4), (6, 5), (2, 3)],
             [(5, 6), (3, 1), (4, 2)],
             [(2, 1), (3, 6), (5, 4)],
             [(1, 6), (2, 4), (5, 3)],
             [(6, 3), (2, 1), (5, 4)],
             [(3, 4), (2, 5), (6, 1)],
             [(3, 5), (6, 4), (1, 2)],
             [(3, 1), (2, 5), (6, 4)]
         ]
     elif PY3:
         expected_schedule = [
             [(4, 6), (3, 2), (1, 5)],
             [(6, 2), (3, 4), (5, 1)],
             [(1, 4), (2, 5), (3, 6)],
             [(3, 1), (4, 2), (6, 5)],
             [(4, 1), (5, 2), (6, 3)],
             [(6, 1), (3, 5), (2, 4)],
             [(1, 3), (6, 2), (4, 5)],
             [(2, 5), (6, 4), (3, 1)],
             [(3, 4), (1, 2), (6, 5)],
             [(2, 3), (1, 6), (4, 5)],
             [(2, 4), (1, 3), (5, 6)],
             [(2, 1), (5, 4), (6, 3)],
             [(6, 4), (2, 1), (5, 3)],
             [(3, 2), (4, 6), (5, 1)],
             [(4, 1), (3, 6), (5, 2)],
             [(5, 6), (4, 3), (1, 2)],
             [(2, 3), (6, 1), (5, 4)],
             [(1, 5), (4, 3), (2, 6)],
             [(2, 6), (3, 5), (1, 4)],
             [(5, 3), (1, 6), (4, 2)]
         ]
     schedule = scheduler.generate_schedule()
     self.assertListEqual(expected_schedule, schedule,
                          ('Wrong schedule created for repeated '
                           'quadruple round-robin competition'))
 def test_repeated_schedule_generation(self):
     """Test repeated quadruple round-robin schedule generation."""
     scheduler = QuadrupleRoundRobinScheduler(6)
     random.seed(4)
     if PY2:
         expected_schedule = [[(4, 1), (2, 6), (3, 5)],
                              [(5, 2), (3, 6), (1, 4)],
                              [(1, 5), (4, 6), (2, 3)],
                              [(1, 3), (6, 5), (2, 4)],
                              [(6, 2), (3, 4), (5, 1)],
                              [(1, 2), (6, 3), (4, 5)],
                              [(5, 2), (1, 6), (4, 3)],
                              [(6, 1), (4, 2), (5, 3)],
                              [(1, 3), (4, 5), (6, 2)],
                              [(3, 2), (4, 6), (5, 1)],
                              [(2, 6), (4, 3), (1, 5)],
                              [(5, 6), (4, 1), (3, 2)],
                              [(1, 4), (6, 5), (2, 3)],
                              [(5, 6), (3, 1), (4, 2)],
                              [(2, 1), (3, 6), (5, 4)],
                              [(1, 6), (2, 4), (5, 3)],
                              [(6, 3), (2, 1), (5, 4)],
                              [(3, 4), (2, 5), (6, 1)],
                              [(3, 5), (6, 4), (1, 2)],
                              [(3, 1), (2, 5), (6, 4)]]
     elif PY3:
         expected_schedule = [[(4, 6), (3, 2), (1, 5)],
                              [(6, 2), (3, 4), (5, 1)],
                              [(1, 4), (2, 5), (3, 6)],
                              [(3, 1), (4, 2), (6, 5)],
                              [(4, 1), (5, 2), (6, 3)],
                              [(6, 1), (3, 5), (2, 4)],
                              [(1, 3), (6, 2), (4, 5)],
                              [(2, 5), (6, 4), (3, 1)],
                              [(3, 4), (1, 2), (6, 5)],
                              [(2, 3), (1, 6), (4, 5)],
                              [(2, 4), (1, 3), (5, 6)],
                              [(2, 1), (5, 4), (6, 3)],
                              [(6, 4), (2, 1), (5, 3)],
                              [(3, 2), (4, 6), (5, 1)],
                              [(4, 1), (3, 6), (5, 2)],
                              [(5, 6), (4, 3), (1, 2)],
                              [(2, 3), (6, 1), (5, 4)],
                              [(1, 5), (4, 3), (2, 6)],
                              [(2, 6), (3, 5), (1, 4)],
                              [(5, 3), (1, 6), (4, 2)]]
     schedule = scheduler.generate_schedule()
     self.assertListEqual(expected_schedule, schedule,
                          ('Wrong schedule created for repeated '
                           'quadruple round-robin competition'))
Ejemplo n.º 5
0
def generador(request):
    if request.user.is_superuser:
        if Jornadas.objects.all().exists():
            Jornadas.objects.all().delete()
        equipos = Equipos.objects.all().order_by('id_equipo')
        lista_equipos = equipos.values_list('nombre')
        lista_equipos = [
            lista_equipos[i][0] for i, v in enumerate(lista_equipos)
        ]
        scheduler = QuadrupleRoundRobinScheduler(lista_equipos)
        lista_partidos = scheduler.generate_schedule()
        for indice, partidos_jornada in enumerate(lista_partidos):
            if indice < 38:
                jornada = Jornadas.objects.create(num_jornada=indice + 1)
                for partido in partidos_jornada:
                    if None not in partido:
                        Partidos.objects.create(
                            equipo_local=Equipos.objects.get(
                                nombre=partido[0]),
                            equipo_visitante=Equipos.objects.get(
                                nombre=partido[1]),
                            jornada=jornada)
        return redirect('home/')