Example #1
0
def create_teams():

    current_season = model.current_season()
    print current_season

    form = TeamCreateForm()

    team_members = model.session.query(model.TeamMember).\
          join(model.Team, model.Team.id == model.TeamMember.team_id).\
          join(model.SeasonCycle, model.Team.seasoncycle == current_season.id)

    if form.validate_on_submit():
        if team_members != None:
            for member in team_members:
                model.session.delete(member)

            model.session.commit()

        create_team.team_generate(int(form.team_num.data))

    return render_template('teams_create.html',
                           title='TeamCreate',
                           team_members=team_members,
                           form=form,
                           current_season=current_season)
def create_teams():

	current_season = model.current_season()
	teams = model.session.query(model.Team).\
				join(model.SeasonCycle, model.Team.seasoncycle == current_season.id).\
				all()


	form= TeamCreateForm()

	team_members = model.session.query(model.TeamMember).\
				   join(model.Team, model.Team.id == model.TeamMember.team_id).\
				   join(model.SeasonCycle, model.Team.seasoncycle == current_season.id)
	

	if form.validate_on_submit():
		if team_members != None:
			for member in team_members:
				model.session.delete(member)

			model.session.commit()

		test.team_generate(int(form.team_num.data))

	
	return render_template('teams_create.html',
							title='TeamCreate',
							team_members=team_members,
							form=form, 
							current_season=current_season,
							teams=teams)
Example #3
0
def homepage():
    # determine if registration is open
    open_registration = model.registration()

    season = model.current_season()

    if not season:
        season = None

    return render_template('index.html',
                           title='Homepage',
                           open_registration=open_registration,
                           season=season)
def homepage():
	# determine if registration is open
	open_registration = model.registration()

	season = model.current_season()
	
	if not season:
		season = None
	
	return render_template('index.html',
							title='Homepage',
							open_registration= open_registration,
							season= season)
def save_teams():
	# change flag for season to saved= True
	current_season = model.current_season()
	current_season.saved =True
	model.session.add(current_season)

	#add intital team ratings
	for team in model.current_teams():
		team.getRating()

	model.session.commit()

	# This will disable team name and creation button

	return redirect('team_create')
Example #6
0
def save_teams():
    # change flag for season to saved= True
    current_season = model.current_season()
    current_season.saved = True
    save_season = model.session.add(current_season)
    current_teams = model.current_teams()

    #add intital team ratings
    for team in current_teams:
        team.getRating()

    model.session.commit()

    # This will disable team name and creation button

    return redirect('team_create')
def team_generate(n_teams):
	#list of players
	registered_players = session.query(User).\
							 filter(User.user_registered == True).\
							 all()

	# list sorted lowest to highest
	sorted_rating = sorted(registered_players, key=lambda i: i.getRating())

	# create a matrix of n_teams with spaces for all registered players
	# list comprehension for parameters is better than multiplication
	# the plus 1 adds an additional space if registered players not evenly divisible by n_teams
	teams = [[None for l in range(len(sorted_rating)/n_teams+1)] for n in range(n_teams)]

	count=0
	team_spot= 0
	
	while sorted_rating:
		teams[count][team_spot] = sorted_rating.pop(0)
		count +=1

		if count == n_teams:
			# sort team rows from highest to lowest since I'm placing players on from lowest to highest
			teams[::-1] = sorted(teams, key=lambda x: [[sum([row.getRating() for row in team[:team_spot]])]for team in teams])
		
			#reset counters
		  	count= 0
		  	team_spot += 1
	
	current_cycle = model.current_season()

	team_names= session.query(Team).\
		   		join(SeasonCycle, Team.seasoncycle == current_cycle.id).\
		   		all()
	print team_names[0].id

	#Add players to teams in database
	count =0
	for team in teams:
		for player in team:
			if player != None:
				session.add(TeamMember(team_id=team_names[count].id,
								   	    player_id=player.id))
				session.commit()

		count +=1