Exemplo n.º 1
0
def filterteams(request):
    torneosfiltrados = request.GET.get('torneos')
    dict = {'tournaments': Tournament.objects.filter(active="true"),
            'numberofteams': Team.objects.filter(tournament_id=torneosfiltrados).count(),
            'teams': Team.objects.filter(tournament_id=torneosfiltrados),
            'tournid': torneosfiltrados}

    #Crea los fixtures necesarios para poder crear los partidos. Si el numero de equipos es impar entonces
    #crea el mismo numero de fixtures para el numero de equipos. Si el numero de equipos es par entonces
    #crea el un fixture menos del numero de equipos solicitado.
    count = 1

    if dict['numberofteams'] > 0 and dict['numberofteams'] % 2 != 0:
        for item in range(dict['numberofteams']):
            fixture = Fixture()
            fixture.tournament = Tournament.objects.get(tournament_id=dict['tournid'])
            fixture.number = count
            fixture.Active = "true"
            count = count + 1
            fixture.save()

    elif dict['numberofteams'] > 0 and dict['numberofteams'] % 2 == 0:
        for item in range(dict['numberofteams'] - 1):
            fixture = Fixture()
            fixture.tournament = Tournament.objects.get(tournament_id=dict['tournid'])
            fixture.number = count
            fixture.Active = "true"
            count = count + 1
            fixture.save()

    return render_to_response('filter.html',
                              dict)
Exemplo n.º 2
0
def creatematches(request):
    myrequest = request.GET.get('equipolocal')
    torneosfiltrados = request.GET.get('torneos')
    fixturefiltrado = request.GET.get('jornada')
    dict = {     'tournaments': Tournament.objects.filter(active="true"),
                 'numberofteams' : Team.objects.filter(tournament_id=torneosfiltrados).count(),
                'teams': Team.objects.filter(tournament_id=torneosfiltrados),
                'unito': myrequest,
                'tournid':torneosfiltrados,
                'fixtures': Fixture.objects.filter(tournament_id=torneosfiltrados),

                'selected_tournament':Tournament.objects.get(tournament_id=torneosfiltrados)}


    #Crea los partidos de forma automatica, si es que el torneo es de ida y vuelta entonces crea permutaciones, si el partido
    # no es de ida y vuelta entonces crea combinaciones.

    count = 1

    if Tournament.objects.get(tournament_id=torneosfiltrados).home_and_away == 0:
         matches = list(itertools.combinations(dict['teams'],2))
         dict['partidos'] = matches
         home = list()
         visit = list()
         for i,j in matches:
          home.append(i)
          print "vs"
          visit.append(j)


         for i in range(len(home)):
          partidocreado = Match()
          fixture = Fixture()
          fixture.tournament = Tournament.objects.get(tournament_id=dict['tournid'])
          fixture.number = count +1
          fixture.Active = "true"
          count = count +1
          fixture.save()

          partidocreado.fixture = fixture
          partidocreado.home = Team.objects.get(team_id=home[i].team_id)
          partidocreado.away = Team.objects.get(team_id=visit[i].team_id)
          partidocreado.score_home = 0
          partidocreado.score_away = 0
          partidocreado.played = 0
          partidocreado.save()

         dict['local']=home[i]
         dict['visita']=visit[i]

    elif Tournament.objects.get(tournament_id=torneosfiltrados).home_and_away == 1:
         matches = list(itertools.permutations(dict['teams'],2))
         dict['partidos'] = matches
         home = list()
         visit = list()
         for i,j in matches:
          home.append(i)
          print "vs"
          visit.append(j)
          print "enter perm"

         for i in range(len(home)):
          partidocreado = Match()
          fixture = Fixture()
          fixture.tournament = Tournament.objects.get(tournament_id=dict['tournid'])
          fixture.number = count
          fixture.Active = "true"
          count = count + 1
          fixture.save()

          partidocreado.fixture = fixture
          partidocreado.home = Team.objects.get(team_id=home[i].team_id)
          partidocreado.away = Team.objects.get(team_id=visit[i].team_id)
          partidocreado.score_home = 0
          partidocreado.score_away = 0
          partidocreado.played = 0
          partidocreado.save()

         dict['local']=home[i]
         dict['visita']=visit[i]



    print list(itertools.permutations(dict['teams'],2))


    return render_to_response('matchmaker.html',
            dict)