Exemplo n.º 1
0
def createTournament(name, set, entities, typeLiteral):

    type = getTypeFromLiteral(typeLiteral)

    newTournament = Tournament(name=name,
                               set_id=set,
                               date=date.today(),
                               type=type)
    db.session.add(newTournament)
    db.session.commit()

    for idx, pairing in enumerate(combinations(entities, 2)):

        newMatch = Match(tournament_id=newTournament.id)
        db.session.add(newMatch)
        db.session.commit()

        db.session.add(
            MatchParticipant(match_id=newMatch.id,
                             entity_id=pairing[0],
                             game_wins=0))
        db.session.add(
            MatchParticipant(match_id=newMatch.id,
                             entity_id=pairing[1],
                             game_wins=0))
        db.session.commit()

    rebuildStatistics(newTournament.id)
Exemplo n.º 2
0
def create_tournament():
    form = TournamentForm(request.form)
    picture_file = "None"
    if form.validate_on_submit():
        try:
            file = request.files['file']
        except:
            file = None
            flash('No file uploaded', 'info')
        if file != None:
            if file.filename == '':
                flash('No file selected!', 'error')
                return redirect(request.url)
            if file and allowed_file(file.filename):
                picture_file = save_picture(file, 'tournament')
                flash('File uploaded successfully!', 'success')
            elif file and not allowed_file(file.filename):
                flash('You can\'t upload that!', 'error')
        tournament = Tournament(name=form.name.data,
                                skill_lvl=form.skill_lvl.data,
                                description=form.description.data,
                                bracketlink=form.bracketlink.data,
                                image_file=picture_file,
                                contactinfo=form.contactinfo.data,
                                user_id=current_user.id)
        db.session.add(tournament)
        db.session.commit()
        flash('Tournament created!', 'success')
        return redirect(url_for('main.tournaments'))
    return render_template("create_tournament.html", form=form)
Exemplo n.º 3
0
    def POST(self):
        
        http_input = web.input(tournament_id=None)
        tournament_id = http_input.tournament_id

        if tournament_id is None:
            raise web.notfound() 

        tournament = Tournament.get(int(tournament_id), joined_attrs=["results"])

        if tournament is None:
            raise web.notfound()
        
        results_grid = tournament_forms.EditResultsGrid().bind(tournament.results, data=http_input)
        
        if results_grid.validate():
            # If the form was properly filled, updates the model and returns the standard table
            # Besides, we sort the results "from the outside" since they are directly returned (commit & no load)
            results_grid.sync()
            tournament.sort_results()
            results = config.views.results(tournament)
            statistics = config.views.statistics(tournament)
        else:
            # Otherwise, returns the editing grid
            results = config.views.results_admin(tournament, results_grid)
            statistics = None
        
        # Returns the dictionary
        return dict(results=results, statistics=statistics)
Exemplo n.º 4
0
    def test_get_tournament(self):

        # These tests work because a TournamentData has a similar structure to a Tournament
        # When Tournament.__eq__ is called, it compares the fields without caring of the parameters' actual types

        self.assertEquals(Tournament.get_tournament(1, 1), TournamentData.tournament_11)
        self.assertEquals(Tournament.get_tournament(1, 2), TournamentData.tournament_12)
        self.assertEquals(Tournament.get_tournament(1, 3), None)
        self.assertEquals(Tournament.get_tournament(1, 4), None)

        self.assertEquals(Tournament.get_tournament(2, 1), TournamentData.tournament_21)
        self.assertEquals(Tournament.get_tournament(2, 2), None)
        self.assertEquals(Tournament.get_tournament(2, 3), None)

        self.assertEquals(Tournament.get_tournament(42, 1), None)
        self.assertEquals(Tournament.get_tournament(42, 9), None)
Exemplo n.º 5
0
    def __init__(self):

        # Grid initialization
        super(EditTournamentsGrid, self).__init__(Tournament, Tournament.all(order_by_clause=Tournament.tournament_dt)) #@UndefinedVariable
        
        # Creation of a customized date field to edit the tournaments' date
        self.append(create_date_field("formatted_tournament_dt", "tournament_dt", DT_FORMAT))
        
        # Grid configuration
        inc = [SEASON_READONLY(self.season_id), POSITION_READONLY(self.position), FORMATTED_DT(self.formatted_tournament_dt), BUYIN(self.buyin)] 
        self.configure(include=inc)
Exemplo n.º 6
0
    def test_get_tournament(self):

        # These tests work because a TournamentData has a similar structure to a Tournament
        # When Tournament.__eq__ is called, it compares the fields without caring of the parameters' actual types

        self.assertEquals(Tournament.get_tournament(1, 1),
                          TournamentData.tournament_11)
        self.assertEquals(Tournament.get_tournament(1, 2),
                          TournamentData.tournament_12)
        self.assertEquals(Tournament.get_tournament(1, 3), None)
        self.assertEquals(Tournament.get_tournament(1, 4), None)

        self.assertEquals(Tournament.get_tournament(2, 1),
                          TournamentData.tournament_21)
        self.assertEquals(Tournament.get_tournament(2, 2), None)
        self.assertEquals(Tournament.get_tournament(2, 3), None)

        self.assertEquals(Tournament.get_tournament(42, 1), None)
        self.assertEquals(Tournament.get_tournament(42, 9), None)
Exemplo n.º 7
0
 def POST(self):
     
     # Reads the HTTP request parameters
     tournament_id = web.input().tournament_id
     status = web.input().status
     
     # Updates the status
     tournament = Tournament.get(int(tournament_id), joined_attrs=["results"])
     tournament.subscribe(config.session_manager.user, status)
     
     return dict(
         statistics=config.views.statistics(tournament),
         results=config.views.results(tournament)
     )
Exemplo n.º 8
0
def create_tournament():
    if not current_user.is_organizer():
        return abort(404)
    form = CreateTournamentForm()
    if form.validate_on_submit():
        tournament = Tournament()
        tournament.name = form.name.data
        tournament.category = form.category.data
        tournament.signups_open = form.signups_open.data
        tournament.signups_close = form.signups_close.data
        tournament.start_date = form.start_date.data
        tournament.end_date = form.end_date.data
        tournament.visible = form.visible.data
        db.session.add(tournament)
        db.session.commit()
        flash("%s has been created." % tournament.name)
        return redirect(url_for("tournaments"))
    return render_template("create_tournament.html",
                           title="Create Tournament",
                           form=form)
Exemplo n.º 9
0
    def GET(self):
        
        tournament_id = web.input(tournament_id=None).tournament_id
        
        if tournament_id is None:
            raise web.notfound()
        
        tournament = Tournament.get(int(tournament_id), joined_attrs=["results"])

        if tournament is None:
            raise web.notfound()
        
        results_grid = tournament_forms.EditResultsGrid().bind(tournament.results)
        
        return config.views.results_admin(tournament, results_grid)
Exemplo n.º 10
0
    def GET(self, season_id, position):
        
        tournament = Tournament.get_tournament(int(season_id), int(position))

        if tournament is None:
            raise web.notfound()

        return config.views.layout(
            config.views.tournament(
                tournament,
                config.views.statistics(tournament),
                config.views.results(tournament),
                config.views.comments(tournament, config.views.comment)
            )
        )
Exemplo n.º 11
0
    def POST(self):
        
        # Reads the HTTP request parameters
        tournament_id = web.input().tournament_id
        comment = web.input().comment
        
        # Appends the comment
        # TODO: variables are ambiguous
        tournament = Tournament.get(int(tournament_id), joined_attrs=["comments"])
        added_comment = tournament.add_comment(config.session_manager.user, comment)
        
        # Registers an email notification
        http.register_hook(lambda: notify_via_email(added_comment, Events.NEW))

        # Returns the dictionary
        return config.views.comment(added_comment)
Exemplo n.º 12
0
 def make_tournament():
     t = Tournament(event_name="The Ultimate Go-ing Championship",
                    start_date=datetime.datetime.now(),
                    venue="LasVegas",
                    director="Donald J. Trump",
                    director_phone="555-5555",
                    director_email="*****@*****.**",
                    pairing="McMahon",
                    rule_set="AGA",
                    time_controls="required field",
                    basic_time="required field",
                    overtime_format="required field",
                    overtime_conditions="required field",
                    komi="7",
                    tie_break1="SOS",
                    tie_break2="SODOS")
     return t
Exemplo n.º 13
0
 def get_command(self):
     tournament_choosen = None
     if not self.all_tournaments:
         return NavigationCommand("mainpage",
                                  'There is no tournament in the database')
     while not tournament_choosen:
         self.print_table(
             ["id", "name"],
             [(str(tournament.id), tournament.name)
              for tournament in self.all_tournaments],
             "List of all the tournament in the data base:",
         )
         id = input("Tournament's id: ")
         if id.isdigit():
             tournament_choosen = Tournament.get(int(id))
             if tournament_choosen:
                 return ContinueCommand(tournament_choosen)
         print("Enter the tournament's id")
Exemplo n.º 14
0
def tournament_create():
    form = TournamentCreateForm()
    tasks = Task.query.order_by(Task.name.desc()).all()
    task_list = [(task.name, task.id) for task in tasks]
    if form.validate_on_submit():
        if request.form.get('tasks') is None:
            flash('Выберите хотя бы одно задание')
            return redirect(url_for('task.tournament_create'))
        set = Tournament.query.filter_by(name=form.name.data).first()
        if set:
            flash('Турнир с таким именем уже существует')
            return redirect(url_for('task.tournament_create'))
        tournament = Tournament(name=form.name.data)
        for task_id in request.form.getlist('tasks'):
            task = Task.query.filter_by(id=task_id).first()
            tournament.tasks.append(task)
        db.session.commit()
        flash('Вы создали турнир')
        return redirect(url_for('task.tournament_list'))
    return render_template('task/tournament_create.html', titile='Создать турнир', form=form, list=task_list)
Exemplo n.º 15
0
def admin_submit_teams(game_stage):
    groups = Tournament.helper_groups(game_stage)
    team_labels_list = []
    for group in groups:
        team_labels_list += groups[group]

    if game_stage == "group":
        form = GroupTeamForm()
    elif game_stage == "R16":
        form = R16TeamForm()
    elif game_stage == "QF":
        form = QFTeamForm()
    elif game_stage == "SF":
        form = SFTeamForm()
    elif game_stage == "F":
        form = FTeamForm()

    labels_and_form_items = zip(team_labels_list, form.teams)

    # Retrieve CL tournament
    tournaments = Tournament.query.all()
    if len(tournaments) != 0:
        cl = tournaments[0]
    else:
        cl = Tournament()
        db.session.add(cl)
    cl.calculate_points()
    db.session.commit()

    if form.validate_on_submit():
        teams_dict = {}
        for team_assignment in labels_and_form_items:
            teams_dict[team_assignment[0]] = team_assignment[1].data["team"]
        cl.set_teams(game_stage, teams_dict)
        print(teams_dict)
        db.session.commit()
        app.logger.info('Updated Tournament')
        return redirect(url_for('admin_submit_teams', game_stage=game_stage))
    posts = Post.query.order_by(desc('points')).all()
    return render_template('admin_submit_teams.html',
                           title='Admin',
                           form=form,
                           tournament=cl,
                           labels_and_form_items=labels_and_form_items)
Exemplo n.º 16
0
def index():
    form = TournamentForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            t = Tournament(event_name=form.event_name.data,
                           venue=form.venue.data,
                           venue_address=form.venue_address.data,
                           venue_state=form.venue_state.data,
                           venue_zip=form.venue_zip.data,
                           start_date=form.start_date.data,
                           end_date=form.end_date.data,
                           director=form.director.data,
                           director_phone=form.director_phone.data,
                           director_email=form.director_email.data,
                           director_address=form.director_address.data,
                           sponsor=form.sponsor.data,
                           sponsor_phone=form.sponsor_phone.data,
                           sponsor_email=form.sponsor_email.data,
                           sponsor_website=form.sponsor_website.data,
                           sponsor_address=form.sponsor_address.data,
                           convener=form.convener.data,
                           convener_phone=form.convener_phone.data,
                           convener_email=form.convener_email.data,
                           convener_website=form.convener_website.data,
                           convener_address=form.convener_address.data,
                           pairing=form.pairing.data,
                           rule_set=form.rule_set.data,
                           time_controls=form.time_controls.data,
                           basic_time=form.basic_time.data,
                           overtime_format=form.overtime_format.data,
                           overtime_conditions=form.overtime_conditions.data,
                           komi=form.komi.data,
                           tie_break1=form.tie_break1.data,
                           tie_break2=form.tie_break2.data,
                           submitted=form.submitted.data)
            db.session.add(t)
            db.session.commit()
            # flash("Tournament successfully created.")
            return redirect(url_for('.index'))
    tournaments = Tournament.query.all()
    return render_template('tournament_index.html', tournaments=tournaments)
Exemplo n.º 17
0
def create_tournament():
    form = CreateTournamentForm()
    if form.validate_on_submit():
        tournament = Tournament(name=form.name.data,
                                place=form.name.data,
                                federation=form.federation.data,
                                start_date=form.start_date.data,
                                end_date=form.end_date.data,
                                rounds=form.rounds.data,
                                play_system=form.play_system.data,
                                move_rate=form.move_rate.data,
                                chief_arbiter=form.chief_arbiter.data,
                                deputy_arbiter=form.deputy_arbiter.data,
                                organizer=current_user.id,
                                categories=form.categories.data,
                                information=form.information.data)
        db.session.add(tournament)
        db.session.commit()
        redirect(url_for('tournaments'))
    return render_template('create_tournament.html',
                           title='Create Tournament',
                           form=form)
Exemplo n.º 18
0
def tournament_create(s, data):
    try:
        user = data['user']
        print(user)
        print(s)
        tournament = Tournament(
            title=data['title'],
            date_start=data['date_start'],
            date_deadline=data['date_deadline'],
            location=data['location'],
            max_users=data['max_users'],
            readme=data['readme'],
            owner_id=user.id,
        )

        s.db.session.add(tournament)
        s.db.session.commit()
    except Exception as e:
        print(str(e))
        if "UNIQUE constraint failed" in str(e):
            raise ErrDuplicate()
        raise ErrFatal()
    return tournament
    def setUp(self):
        super().setUp()
        self.tournament_endpoint = '/tournament/'
        self.tournament_1 = Tournament(
            event_name="The Ultimate Go-ing Chamionship",
            start_date=datetime.datetime.now(),
            venue="LasVegas",
            director="Donald J. Trump",
            director_phone="555-5555",
            director_email="*****@*****.**",
            pairing="McMahon",
            rule_set="AGA",
            time_controls="filler text",
            basic_time="filler text",
            overtime_format="filler text",
            overtime_conditions="filler text",
            komi="7",
            tie_break1="SOS",
            tie_break2="SODOS")
        db.session.add(self.tournament_1)
        db.session.commit()

        self.tournament_1_player = TournamentPlayer(
            name="Tester Testington",
            aga_num="12345",
            rating="100",
            affiliation="Joe's house of Go",
            state="AZ",
            address="1111 Main St.",
            email="*****@*****.**",
            phone="123-456-7890",
            citizenship="USA",
            dob="01/01/01",
            tournament_id=1)  #  tournament_1.id)

        db.session.add(self.tournament_1_player)
        db.session.commit()
Exemplo n.º 20
0
    def test_position(self):

        season_1 = config.orm.query(Season).filter(
            Season.id == 1).one()  #@UndefinedVariable
        season_2 = config.orm.query(Season).filter(
            Season.id == 2).one()  #@UndefinedVariable

        self.assertIsInstance(season_1.tournaments, OrderingList)
        self.assertIsInstance(season_2.tournaments, OrderingList)

        self.assertEqual(len(season_1.tournaments), 2)
        self.assertEqual(len(season_2.tournaments), 1)

        self.assertEqual(season_1.tournaments[0].position, 1)
        self.assertEqual(season_1.tournaments[1].position, 2)
        self.assertEqual(season_2.tournaments[0].position, 1)

        self.assertEqual(season_1.tournaments[0].tournament_dt,
                         datetime.date(2009, 9, 1))
        self.assertEqual(season_1.tournaments[1].tournament_dt,
                         datetime.date(2010, 1, 1))
        self.assertEqual(season_2.tournaments[0].tournament_dt,
                         datetime.date(2010, 8, 1))

        tournament_13 = Tournament()
        tournament_13.tournament_dt = datetime.date(2010, 2, 1)
        tournament_13.buyin = 10
        tournament_13.season_id = 1

        season_1.tournaments.append(tournament_13)
        season_1.reorder_tournaments()

        self.assertEqual(len(season_1.tournaments), 3)
        self.assertEqual(len(season_2.tournaments), 1)

        self.assertEqual(season_1.tournaments[0].position, 1)
        self.assertEqual(season_1.tournaments[1].position, 2)
        self.assertEqual(season_1.tournaments[2].position, 3)
        self.assertEqual(season_2.tournaments[0].position, 1)

        self.assertEqual(season_1.tournaments[0].tournament_dt,
                         datetime.date(2009, 9, 1))
        self.assertEqual(season_1.tournaments[1].tournament_dt,
                         datetime.date(2010, 1, 1))
        self.assertEqual(season_1.tournaments[2].tournament_dt,
                         datetime.date(2010, 2, 1))
        self.assertEqual(season_2.tournaments[0].tournament_dt,
                         datetime.date(2010, 8, 1))

        tournament_10 = Tournament()
        tournament_10.tournament_dt = datetime.date(2009, 8, 31)
        tournament_10.buyin = 10
        tournament_10.season_id = 1

        season_1.tournaments.append(tournament_10)
        season_1.reorder_tournaments()

        self.assertEqual(len(season_1.tournaments), 4)
        self.assertEqual(len(season_2.tournaments), 1)

        self.assertEqual(season_1.tournaments[0].position, 1)
        self.assertEqual(season_1.tournaments[1].position, 2)
        self.assertEqual(season_1.tournaments[2].position, 3)
        self.assertEqual(season_1.tournaments[3].position, 4)
        self.assertEqual(season_2.tournaments[0].position, 1)

        self.assertEqual(season_1.tournaments[0].tournament_dt,
                         datetime.date(2009, 8, 31))
        self.assertEqual(season_1.tournaments[1].tournament_dt,
                         datetime.date(2009, 9, 1))
        self.assertEqual(season_1.tournaments[2].tournament_dt,
                         datetime.date(2010, 1, 1))
        self.assertEqual(season_1.tournaments[3].tournament_dt,
                         datetime.date(2010, 2, 1))
        self.assertEqual(season_2.tournaments[0].tournament_dt,
                         datetime.date(2010, 8, 1))
Exemplo n.º 21
0
    def test_all(self):

        all_tournaments = Tournament.all()
        self.assertEqual(len(all_tournaments), 3)
Exemplo n.º 22
0
def submit_scores(game_stage, post_id):
    game_labels = Tournament.helper_game_labels(game_stage)

    if game_stage == "group":
        form = GroupStageForm()
    elif game_stage == "R16":
        form = R16StageForm()
    elif game_stage == "QF":
        form = QFStageForm()
    elif game_stage == "SF":
        form = SFStageForm()
    elif game_stage == "F":
        form = FStageForm()

    labels_and_form_items = zip(game_labels, form.games)

    # Retrieve CL tournament
    tournaments = Tournament.query.all()
    if len(tournaments) != 0:
        cl = tournaments[0]
    else:
        cl = Tournament()
        db.session.add(cl)
    cl.calculate_points()
    db.session.commit()

    games_info = {}
    teams_dict = cl.get_teams(game_stage)
    if teams_dict:
        for game_label in game_labels:
            temp = Tournament.helper_parse_game_label(game_label)
            games_info[game_label] = {
                "home_team": teams_dict[temp["home_team"]],
                "away_team": teams_dict[temp["away_team"]]
            }

    if form.validate_on_submit():
        if post_id:
            post = Post.query.filter_by(id=post_id).all()[0]
        else:
            post = Post(user_id=current_user.id, points=0)
        games_guess_dict = {}
        for game_guess in labels_and_form_items:
            games_guess_dict[game_guess[0]] = str(
                game_guess[1].data["home_result"]) + "vs" + str(
                    game_guess[1].data["away_result"])
            games_guess_dict[game_guess[0]] = {
                "result":
                str(game_guess[1].data["home_result"]) + "vs" +
                str(game_guess[1].data["away_result"]),
                "points":
                0
            }
        post.set_guess(game_stage, games_guess_dict)
        post.make_valid()
        cl.calculate_points_specific(post)
        db.session.add(post)
        db.session.commit()
        flash('Congratulations you submitted a bracket')
        app.logger.info('Congratulations you submitted a bracket')
        return redirect(
            url_for('submit_scores', game_stage=game_stage, post_id=post.id))

    return render_template('submit_scores.html',
                           title='Submit Group Stage',
                           form=form,
                           labels_and_form_items=labels_and_form_items,
                           games_info=games_info)
def seed_2021_tournament():
    tournament = Tournament(year=2021,
                            region1='West',
                            region2='East',
                            region3='South',
                            region4='Midwest',
                            last_round_completed=0)
    db.session.add(tournament)
    db.session.commit()

    # West
    Gonzaga = College.query.filter(College.name == 'Gonzaga').one()
    gonzaga = March_Madness_Team(tournament_id=tournament.id,
                                 seed_number=1,
                                 region='West',
                                 college_id=Gonzaga.id)
    db.session.add(gonzaga)

    Norfolk_State = College.query.filter(College.name == 'Norfolk St.').one()
    norfolk_State = March_Madness_Team(tournament_id=tournament.id,
                                       seed_number=16,
                                       region='West',
                                       college_id=Norfolk_State.id)
    db.session.add(norfolk_State)

    Oklahoma = College.query.filter(College.name == 'Oklahoma').one()
    oklahoma = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=8,
                                  region='West',
                                  college_id=Oklahoma.id)
    db.session.add(oklahoma)

    Missouri = College.query.filter(College.name == 'Missouri').one()
    missouri = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=9,
                                  region='West',
                                  college_id=Missouri.id)
    db.session.add(missouri)

    Creighton = College.query.filter(College.name == 'Creighton').one()
    creighton = March_Madness_Team(tournament_id=tournament.id,
                                   seed_number=5,
                                   region='West',
                                   college_id=Creighton.id)
    db.session.add(creighton)

    UCSB = College.query.filter(College.name == 'UCSB').one()
    uCSB = March_Madness_Team(tournament_id=tournament.id,
                              seed_number=12,
                              region='West',
                              college_id=UCSB.id)
    db.session.add(uCSB)

    Virginia = College.query.filter(College.name == 'Virginia').one()
    virginia = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=4,
                                  region='West',
                                  college_id=Virginia.id)
    db.session.add(virginia)

    Ohio = College.query.filter(College.name == 'Ohio').one()
    ohio = March_Madness_Team(tournament_id=tournament.id,
                              seed_number=13,
                              region='West',
                              college_id=Ohio.id)
    db.session.add(ohio)

    USC = College.query.filter(College.name == 'USC').one()
    uSC = March_Madness_Team(tournament_id=tournament.id,
                             seed_number=6,
                             region='West',
                             college_id=USC.id)
    db.session.add(uSC)

    Drake = College.query.filter(College.name == 'Drake').one()
    drake = March_Madness_Team(tournament_id=tournament.id,
                               seed_number=11,
                               region='West',
                               college_id=Drake.id)
    db.session.add(drake)

    Kansas = College.query.filter(College.name == 'Kansas').one()
    kansas = March_Madness_Team(tournament_id=tournament.id,
                                seed_number=3,
                                region='West',
                                college_id=Kansas.id)
    db.session.add(kansas)

    Eastern_Washington = College.query.filter(
        College.name == 'Eastern Washington').one()
    eastern_Washington = March_Madness_Team(tournament_id=tournament.id,
                                            seed_number=14,
                                            region='West',
                                            college_id=Eastern_Washington.id)
    db.session.add(eastern_Washington)

    Oregon = College.query.filter(College.name == 'Oregon').one()
    oregon = March_Madness_Team(tournament_id=tournament.id,
                                seed_number=7,
                                region='West',
                                college_id=Oregon.id)
    db.session.add(oregon)

    VCU = College.query.filter(College.name == 'VCU').one()
    vCU = March_Madness_Team(tournament_id=tournament.id,
                             seed_number=10,
                             region='West',
                             college_id=VCU.id)
    db.session.add(vCU)

    Iowa = College.query.filter(College.name == 'Iowa').one()
    iowa = March_Madness_Team(tournament_id=tournament.id,
                              seed_number=2,
                              region='West',
                              college_id=Iowa.id)
    db.session.add(iowa)

    Grand_Canyon = College.query.filter(College.name == 'Grand Canyon').one()
    grand_Canyon = March_Madness_Team(tournament_id=tournament.id,
                                      seed_number=15,
                                      region='West',
                                      college_id=Grand_Canyon.id)
    db.session.add(grand_Canyon)

    # South
    Baylor = College.query.filter(College.name == 'Baylor').one()
    baylor = March_Madness_Team(tournament_id=tournament.id,
                                seed_number=1,
                                region='South',
                                college_id=Baylor.id)
    db.session.add(baylor)

    Hartford = College.query.filter(College.name == 'Hartford').one()
    hartford = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=16,
                                  region='South',
                                  college_id=Hartford.id)
    db.session.add(hartford)

    North_Carolina = College.query.filter(
        College.name == 'North Carolina').one()
    north_Carolina = March_Madness_Team(tournament_id=tournament.id,
                                        seed_number=8,
                                        region='South',
                                        college_id=North_Carolina.id)
    db.session.add(north_Carolina)

    Wisconsin = College.query.filter(College.name == 'Wisconsin').one()
    wisconsin = March_Madness_Team(tournament_id=tournament.id,
                                   seed_number=9,
                                   region='South',
                                   college_id=Wisconsin.id)
    db.session.add(wisconsin)

    Villanova = College.query.filter(College.name == 'Villanova').one()
    villanova = March_Madness_Team(tournament_id=tournament.id,
                                   seed_number=5,
                                   region='South',
                                   college_id=Villanova.id)
    db.session.add(villanova)

    Winthrop = College.query.filter(College.name == 'Winthrop').one()
    winthrop = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=12,
                                  region='South',
                                  college_id=Winthrop.id)
    db.session.add(winthrop)

    Purdue = College.query.filter(College.name == 'Purdue').one()
    purdue = March_Madness_Team(tournament_id=tournament.id,
                                seed_number=4,
                                region='South',
                                college_id=Purdue.id)
    db.session.add(purdue)

    North_Texas = College.query.filter(College.name == 'North Texas').one()
    north_Texas = March_Madness_Team(tournament_id=tournament.id,
                                     seed_number=13,
                                     region='South',
                                     college_id=North_Texas.id)
    db.session.add(north_Texas)

    Texas_Tech = College.query.filter(College.name == 'Texas Tech').one()
    texas_Tech = March_Madness_Team(tournament_id=tournament.id,
                                    seed_number=6,
                                    region='South',
                                    college_id=Texas_Tech.id)
    db.session.add(texas_Tech)

    Utah_State = College.query.filter(College.name == 'Utah State').one()
    Utah_State = March_Madness_Team(tournament_id=tournament.id,
                                    seed_number=11,
                                    region='South',
                                    college_id=Utah_State.id)
    db.session.add(Utah_State)

    Arkansas = College.query.filter(College.name == 'Arkansas').one()
    arkansas = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=3,
                                  region='South',
                                  college_id=Arkansas.id)
    db.session.add(arkansas)

    Colgate = College.query.filter(College.name == 'Colgate').one()
    colgate = March_Madness_Team(tournament_id=tournament.id,
                                 seed_number=14,
                                 region='South',
                                 college_id=Colgate.id)
    db.session.add(colgate)

    Florida = College.query.filter(College.name == 'Florida').one()
    florida = March_Madness_Team(tournament_id=tournament.id,
                                 seed_number=7,
                                 region='South',
                                 college_id=Florida.id)
    db.session.add(florida)

    Virginia_Tech = College.query.filter(College.name == 'Virginia Tech').one()
    virginia_Tech = March_Madness_Team(tournament_id=tournament.id,
                                       seed_number=10,
                                       region='South',
                                       college_id=Virginia_Tech.id)
    db.session.add(virginia_Tech)

    Ohio_State = College.query.filter(College.name == 'Ohio State').one()
    ohio_State = March_Madness_Team(tournament_id=tournament.id,
                                    seed_number=2,
                                    region='South',
                                    college_id=Ohio_State.id)
    db.session.add(ohio_State)

    Oral_Roberts = College.query.filter(College.name == 'Oral Roberts').one()
    Oral_Roberts = March_Madness_Team(tournament_id=tournament.id,
                                      seed_number=15,
                                      region='South',
                                      college_id=Oral_Roberts.id)
    db.session.add(Oral_Roberts)

    # Midwest
    Illinois = College.query.filter(College.name == 'Illinois').one()
    illinois = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=1,
                                  region='Midwest',
                                  college_id=Illinois.id)
    db.session.add(illinois)

    Drexel = College.query.filter(College.name == 'Drexel').one()
    drexel = March_Madness_Team(tournament_id=tournament.id,
                                seed_number=16,
                                region='Midwest',
                                college_id=Drexel.id)
    db.session.add(drexel)

    Loyola_Chicago = College.query.filter(
        College.name == 'Loyola Chicago').one()
    loyola_Chicago = March_Madness_Team(tournament_id=tournament.id,
                                        seed_number=8,
                                        region='Midwest',
                                        college_id=Loyola_Chicago.id)
    db.session.add(loyola_Chicago)

    Georgia_Tech = College.query.filter(College.name == 'Georgia Tech').one()
    georgia_Tech = March_Madness_Team(tournament_id=tournament.id,
                                      seed_number=9,
                                      region='Midwest',
                                      college_id=Georgia_Tech.id)
    db.session.add(georgia_Tech)

    Tennessee = College.query.filter(College.name == 'Tennessee').one()
    tennessee = March_Madness_Team(tournament_id=tournament.id,
                                   seed_number=5,
                                   region='Midwest',
                                   college_id=Tennessee.id)
    db.session.add(tennessee)

    Oregon_State = College.query.filter(College.name == 'Oregon State').one()
    oregon_State = March_Madness_Team(tournament_id=tournament.id,
                                      seed_number=12,
                                      region='Midwest',
                                      college_id=Oregon_State.id)
    db.session.add(oregon_State)

    Oklahoma_State = College.query.filter(
        College.name == 'Oklahoma State').one()
    oklahoma_State = March_Madness_Team(tournament_id=tournament.id,
                                        seed_number=4,
                                        region='Midwest',
                                        college_id=Oklahoma_State.id)
    db.session.add(oklahoma_State)

    Liberty = College.query.filter(College.name == 'Liberty').one()
    liberty = March_Madness_Team(tournament_id=tournament.id,
                                 seed_number=13,
                                 region='Midwest',
                                 college_id=Liberty.id)
    db.session.add(liberty)

    San_Diego_State = College.query.filter(
        College.name == 'San Diego State').one()
    san_Diego_State = March_Madness_Team(tournament_id=tournament.id,
                                         seed_number=6,
                                         region='Midwest',
                                         college_id=San_Diego_State.id)
    db.session.add(san_Diego_State)

    Syracuse = College.query.filter(College.name == 'Syracuse').one()
    syracuse = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=11,
                                  region='Midwest',
                                  college_id=Syracuse.id)
    db.session.add(syracuse)

    West_Virginia = College.query.filter(College.name == 'West Virginia').one()
    west_Virginia = March_Madness_Team(tournament_id=tournament.id,
                                       seed_number=3,
                                       region='Midwest',
                                       college_id=West_Virginia.id)
    db.session.add(west_Virginia)

    Morehead_State = College.query.filter(
        College.name == 'Morehead State').one()
    morehead_State = March_Madness_Team(tournament_id=tournament.id,
                                        seed_number=14,
                                        region='Midwest',
                                        college_id=Morehead_State.id)
    db.session.add(morehead_State)

    Clemson = College.query.filter(College.name == 'Clemson').one()
    clemson = March_Madness_Team(tournament_id=tournament.id,
                                 seed_number=7,
                                 region='Midwest',
                                 college_id=Clemson.id)
    db.session.add(clemson)

    Rutgers = College.query.filter(College.name == 'Rutgers').one()
    rutgers = March_Madness_Team(tournament_id=tournament.id,
                                 seed_number=10,
                                 region='Midwest',
                                 college_id=Rutgers.id)
    db.session.add(rutgers)

    Houston = College.query.filter(College.name == 'Houston').one()
    houston = March_Madness_Team(tournament_id=tournament.id,
                                 seed_number=2,
                                 region='Midwest',
                                 college_id=Houston.id)
    db.session.add(houston)

    Cleveland_State = College.query.filter(
        College.name == 'Cleveland State').one()
    Cleveland_State = March_Madness_Team(tournament_id=tournament.id,
                                         seed_number=15,
                                         region='Midwest',
                                         college_id=Cleveland_State.id)
    db.session.add(Cleveland_State)

    # East
    Michigan = College.query.filter(College.name == 'Michigan').one()
    michigan = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=1,
                                  region='East',
                                  college_id=Michigan.id)
    db.session.add(michigan)

    Texas_Southern = College.query.filter(
        College.name == 'Texas Southern').one()
    texas_Southern = March_Madness_Team(tournament_id=tournament.id,
                                        seed_number=16,
                                        region='East',
                                        college_id=Texas_Southern.id)
    db.session.add(texas_Southern)

    LSU = College.query.filter(College.name == 'LSU').one()
    lSU = March_Madness_Team(tournament_id=tournament.id,
                             seed_number=8,
                             region='East',
                             college_id=LSU.id)
    db.session.add(lSU)

    St_Bonaventure = College.query.filter(
        College.name == 'St. Bonaventure').one()
    st_Bonaventure = March_Madness_Team(tournament_id=tournament.id,
                                        seed_number=9,
                                        region='East',
                                        college_id=St_Bonaventure.id)
    db.session.add(st_Bonaventure)

    Colorado = College.query.filter(College.name == 'Colorado').one()
    colorado = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=5,
                                  region='East',
                                  college_id=Colorado.id)
    db.session.add(colorado)

    Georgetown = College.query.filter(College.name == 'Georgetown').one()
    georgetown = March_Madness_Team(tournament_id=tournament.id,
                                    seed_number=12,
                                    region='East',
                                    college_id=Georgetown.id)
    db.session.add(georgetown)

    Florida_State = College.query.filter(College.name == 'Florida State').one()
    florida_State = March_Madness_Team(tournament_id=tournament.id,
                                       seed_number=4,
                                       region='East',
                                       college_id=Florida_State.id)
    db.session.add(florida_State)

    UNC_Greensboro = College.query.filter(
        College.name == 'UNC Greensboro').one()
    uNC_Greensboro = March_Madness_Team(tournament_id=tournament.id,
                                        seed_number=13,
                                        region='East',
                                        college_id=UNC_Greensboro.id)
    db.session.add(uNC_Greensboro)

    BYU = College.query.filter(College.name == 'BYU').one()
    bYU = March_Madness_Team(tournament_id=tournament.id,
                             seed_number=6,
                             region='East',
                             college_id=BYU.id)
    db.session.add(bYU)

    UCLA = College.query.filter(College.name == 'UCLA').one()
    uCLA = March_Madness_Team(tournament_id=tournament.id,
                              seed_number=11,
                              region='East',
                              college_id=UCLA.id)
    db.session.add(uCLA)

    Texas = College.query.filter(College.name == 'Texas').one()
    texas = March_Madness_Team(tournament_id=tournament.id,
                               seed_number=3,
                               region='East',
                               college_id=Texas.id)
    db.session.add(texas)

    Abilene_Christian = College.query.filter(
        College.name == 'Abilene Christian').one()
    abilene_Christian = March_Madness_Team(tournament_id=tournament.id,
                                           seed_number=14,
                                           region='East',
                                           college_id=Abilene_Christian.id)
    db.session.add(abilene_Christian)

    UCONN = College.query.filter(College.name == 'UCONN').one()
    uCONN = March_Madness_Team(tournament_id=tournament.id,
                               seed_number=7,
                               region='East',
                               college_id=UCONN.id)
    db.session.add(uCONN)

    Maryland = College.query.filter(College.name == 'Maryland').one()
    maryland = March_Madness_Team(tournament_id=tournament.id,
                                  seed_number=10,
                                  region='East',
                                  college_id=Maryland.id)
    db.session.add(maryland)

    Alabama = College.query.filter(College.name == 'Alabama').one()
    alabama = March_Madness_Team(tournament_id=tournament.id,
                                 seed_number=2,
                                 region='East',
                                 college_id=Alabama.id)
    db.session.add(alabama)

    Iona = College.query.filter(College.name == 'Iona').one()
    iona = March_Madness_Team(tournament_id=tournament.id,
                              seed_number=15,
                              region='East',
                              college_id=Iona.id)
    db.session.add(iona)

    db.session.commit()

    game_1 = Game(game_num=1,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_1)
    game_2 = Game(game_num=2,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_2)
    game_3 = Game(game_num=3,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_3)
    game_4 = Game(game_num=4,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_4)
    game_5 = Game(game_num=5,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_5)
    game_6 = Game(game_num=6,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_6)
    game_7 = Game(game_num=7,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_7)
    game_8 = Game(game_num=8,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_8)
    game_9 = Game(game_num=9,
                  round_num=1,
                  winning_team_id=None,
                  tournament_id=tournament.id)
    db.session.add(game_9)
    game_10 = Game(game_num=10,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_10)
    game_11 = Game(game_num=11,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_11)
    game_12 = Game(game_num=12,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_12)
    game_13 = Game(game_num=13,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_13)
    game_14 = Game(game_num=14,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_14)
    game_15 = Game(game_num=15,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_15)
    game_16 = Game(game_num=16,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_16)
    game_17 = Game(game_num=17,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_17)
    game_18 = Game(game_num=18,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_18)
    game_19 = Game(game_num=19,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_19)
    game_20 = Game(game_num=20,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_20)
    game_21 = Game(game_num=21,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_21)
    game_22 = Game(game_num=22,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_22)
    game_23 = Game(game_num=23,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_23)
    game_24 = Game(game_num=24,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_24)
    game_25 = Game(game_num=25,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_25)
    game_26 = Game(game_num=26,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_26)
    game_27 = Game(game_num=27,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_27)
    game_28 = Game(game_num=28,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_28)
    game_29 = Game(game_num=29,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_29)
    game_30 = Game(game_num=30,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_30)
    game_31 = Game(game_num=31,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_31)
    game_32 = Game(game_num=32,
                   round_num=1,
                   winning_team_id=None,
                   tournament_id=tournament.id)
    db.session.add(game_32)

    db.session.commit()

    game_1_win_score = Game_Team_Score(game_id=game_1.id,
                                       team_id=gonzaga.id,
                                       score=None)
    game_1_lose_score = Game_Team_Score(game_id=game_1.id,
                                        team_id=norfolk_State.id,
                                        score=None)
    game_1.game_team_scores = [game_1_win_score, game_1_lose_score]

    game_2_win_score = Game_Team_Score(game_id=game_2.id,
                                       team_id=oklahoma.id,
                                       score=None)
    game_2_lose_score = Game_Team_Score(game_id=game_2.id,
                                        team_id=missouri.id,
                                        score=None)
    game_2.game_team_scores = [game_2_win_score, game_2_lose_score]

    game_3_win_score = Game_Team_Score(game_id=game_3.id,
                                       team_id=creighton.id,
                                       score=None)
    game_3_lose_score = Game_Team_Score(game_id=game_3.id,
                                        team_id=uCSB.id,
                                        score=None)
    game_3.game_team_scores = [game_3_win_score, game_3_lose_score]

    game_4_win_score = Game_Team_Score(game_id=game_4.id,
                                       team_id=virginia.id,
                                       score=None)
    game_4_lose_score = Game_Team_Score(game_id=game_4.id,
                                        team_id=ohio.id,
                                        score=None)
    game_4.game_team_scores = [game_4_win_score, game_4_lose_score]

    game_5_win_score = Game_Team_Score(game_id=game_5.id,
                                       team_id=uSC.id,
                                       score=None)
    game_5_lose_score = Game_Team_Score(game_id=game_5.id,
                                        team_id=drake.id,
                                        score=None)
    game_5.game_team_scores = [game_5_win_score, game_5_lose_score]

    game_6_win_score = Game_Team_Score(game_id=game_6.id,
                                       team_id=kansas.id,
                                       score=None)
    game_6_lose_score = Game_Team_Score(game_id=game_6.id,
                                        team_id=eastern_Washington.id,
                                        score=None)
    game_6.game_team_scores = [game_6_win_score, game_6_lose_score]

    game_7_win_score = Game_Team_Score(game_id=game_7.id,
                                       team_id=oregon.id,
                                       score=None)
    game_7_lose_score = Game_Team_Score(game_id=game_7.id,
                                        team_id=vCU.id,
                                        score=None)
    game_7.game_team_scores = [game_7_win_score, game_7_lose_score]

    game_8_win_score = Game_Team_Score(game_id=game_8.id,
                                       team_id=iowa.id,
                                       score=None)
    game_8_lose_score = Game_Team_Score(game_id=game_8.id,
                                        team_id=grand_Canyon.id,
                                        score=None)
    game_8.game_team_scores = [game_8_win_score, game_8_lose_score]

    game_9_win_score = Game_Team_Score(game_id=game_9.id,
                                       team_id=michigan.id,
                                       score=None)
    game_9_lose_score = Game_Team_Score(game_id=game_9.id,
                                        team_id=texas_Southern.id,
                                        score=None)
    game_9.game_team_scores = [game_9_win_score, game_9_lose_score]

    game_10_win_score = Game_Team_Score(game_id=game_10.id,
                                        team_id=lSU.id,
                                        score=None)
    game_10_lose_score = Game_Team_Score(game_id=game_10.id,
                                         team_id=st_Bonaventure.id,
                                         score=None)
    game_10.game_team_scores = [game_10_win_score, game_10_lose_score]

    game_11_win_score = Game_Team_Score(game_id=game_11.id,
                                        team_id=colorado.id,
                                        score=None)
    game_11_lose_score = Game_Team_Score(game_id=game_11.id,
                                         team_id=georgetown.id,
                                         score=None)
    game_11.game_team_scores = [game_11_win_score, game_11_lose_score]

    game_12_win_score = Game_Team_Score(game_id=game_12.id,
                                        team_id=florida_State.id,
                                        score=None)
    game_12_lose_score = Game_Team_Score(game_id=game_12.id,
                                         team_id=uNC_Greensboro.id,
                                         score=None)
    game_12.game_team_scores = [game_12_win_score, game_12_lose_score]

    game_13_win_score = Game_Team_Score(game_id=game_13.id,
                                        team_id=bYU.id,
                                        score=None)
    game_13_lose_score = Game_Team_Score(game_id=game_13.id,
                                         team_id=uCLA.id,
                                         score=None)
    game_13.game_team_scores = [game_13_win_score, game_13_lose_score]

    game_14_win_score = Game_Team_Score(game_id=game_14.id,
                                        team_id=texas.id,
                                        score=None)
    game_14_lose_score = Game_Team_Score(game_id=game_14.id,
                                         team_id=abilene_Christian.id,
                                         score=None)
    game_14.game_team_scores = [game_14_win_score, game_14_lose_score]

    game_15_win_score = Game_Team_Score(game_id=game_15.id,
                                        team_id=uCONN.id,
                                        score=None)
    game_15_lose_score = Game_Team_Score(game_id=game_15.id,
                                         team_id=maryland.id,
                                         score=None)
    game_15.game_team_scores = [game_15_win_score, game_15_lose_score]

    game_16_win_score = Game_Team_Score(game_id=game_16.id,
                                        team_id=alabama.id,
                                        score=None)
    game_16_lose_score = Game_Team_Score(game_id=game_16.id,
                                         team_id=iona.id,
                                         score=None)
    game_16.game_team_scores = [game_16_win_score, game_16_lose_score]

    game_17_win_score = Game_Team_Score(game_id=game_17.id,
                                        team_id=baylor.id,
                                        score=None)
    game_17_lose_score = Game_Team_Score(game_id=game_17.id,
                                         team_id=hartford.id,
                                         score=None)
    game_17.game_team_scores = [game_17_win_score, game_17_lose_score]

    game_18_win_score = Game_Team_Score(game_id=game_18.id,
                                        team_id=north_Carolina.id,
                                        score=None)
    game_18_lose_score = Game_Team_Score(game_id=game_18.id,
                                         team_id=wisconsin.id,
                                         score=None)
    game_18.game_team_scores = [game_18_win_score, game_18_lose_score]

    game_19_win_score = Game_Team_Score(game_id=game_19.id,
                                        team_id=villanova.id,
                                        score=None)
    game_19_lose_score = Game_Team_Score(game_id=game_19.id,
                                         team_id=winthrop.id,
                                         score=None)
    game_19.game_team_scores = [game_19_win_score, game_19_lose_score]

    game_20_win_score = Game_Team_Score(game_id=game_20.id,
                                        team_id=purdue.id,
                                        score=None)
    game_20_lose_score = Game_Team_Score(game_id=game_20.id,
                                         team_id=north_Texas.id,
                                         score=None)
    game_20.game_team_scores = [game_20_win_score, game_20_lose_score]

    game_21_win_score = Game_Team_Score(game_id=game_21.id,
                                        team_id=texas_Tech.id,
                                        score=None)
    game_21_lose_score = Game_Team_Score(game_id=game_21.id,
                                         team_id=Utah_State.id,
                                         score=None)
    game_21.game_team_scores = [game_21_win_score, game_21_lose_score]

    game_22_win_score = Game_Team_Score(game_id=game_22.id,
                                        team_id=arkansas.id,
                                        score=None)
    game_22_lose_score = Game_Team_Score(game_id=game_22.id,
                                         team_id=colgate.id,
                                         score=None)
    game_22.game_team_scores = [game_22_win_score, game_22_lose_score]

    game_23_win_score = Game_Team_Score(game_id=game_23.id,
                                        team_id=florida.id,
                                        score=None)
    game_23_lose_score = Game_Team_Score(game_id=game_23.id,
                                         team_id=virginia_Tech.id,
                                         score=None)
    game_23.game_team_scores = [game_23_win_score, game_23_lose_score]

    game_24_win_score = Game_Team_Score(game_id=game_24.id,
                                        team_id=ohio_State.id,
                                        score=None)
    game_24_lose_score = Game_Team_Score(game_id=game_24.id,
                                         team_id=Oral_Roberts.id,
                                         score=None)
    game_24.game_team_scores = [game_24_win_score, game_24_lose_score]

    game_25_win_score = Game_Team_Score(game_id=game_25.id,
                                        team_id=illinois.id,
                                        score=None)
    game_25_lose_score = Game_Team_Score(game_id=game_25.id,
                                         team_id=drexel.id,
                                         score=None)
    game_25.game_team_scores = [game_25_win_score, game_25_lose_score]

    game_26_win_score = Game_Team_Score(game_id=game_26.id,
                                        team_id=loyola_Chicago.id,
                                        score=None)
    game_26_lose_score = Game_Team_Score(game_id=game_26.id,
                                         team_id=georgia_Tech.id,
                                         score=None)
    game_26.game_team_scores = [game_26_win_score, game_26_lose_score]

    game_27_win_score = Game_Team_Score(game_id=game_27.id,
                                        team_id=tennessee.id,
                                        score=None)
    game_27_lose_score = Game_Team_Score(game_id=game_27.id,
                                         team_id=oregon_State.id,
                                         score=None)
    game_27.game_team_scores = [game_27_win_score, game_27_lose_score]

    game_28_win_score = Game_Team_Score(game_id=game_28.id,
                                        team_id=oklahoma_State.id,
                                        score=None)
    game_28_lose_score = Game_Team_Score(game_id=game_28.id,
                                         team_id=liberty.id,
                                         score=None)
    game_28.game_team_scores = [game_28_win_score, game_28_lose_score]

    game_29_win_score = Game_Team_Score(game_id=game_29.id,
                                        team_id=san_Diego_State.id,
                                        score=None)
    game_29_lose_score = Game_Team_Score(game_id=game_29.id,
                                         team_id=syracuse.id,
                                         score=None)
    game_29.game_team_scores = [game_29_win_score, game_29_lose_score]

    game_30_win_score = Game_Team_Score(game_id=game_30.id,
                                        team_id=west_Virginia.id,
                                        score=None)
    game_30_lose_score = Game_Team_Score(game_id=game_30.id,
                                         team_id=morehead_State.id,
                                         score=None)
    game_30.game_team_scores = [game_30_win_score, game_30_lose_score]

    game_31_win_score = Game_Team_Score(game_id=game_31.id,
                                        team_id=clemson.id,
                                        score=None)
    game_31_lose_score = Game_Team_Score(game_id=game_31.id,
                                         team_id=rutgers.id,
                                         score=None)
    game_31.game_team_scores = [game_31_win_score, game_31_lose_score]

    game_32_win_score = Game_Team_Score(game_id=game_32.id,
                                        team_id=houston.id,
                                        score=None)
    game_32_lose_score = Game_Team_Score(game_id=game_32.id,
                                         team_id=Cleveland_State.id,
                                         score=None)
    game_32.game_team_scores = [game_32_win_score, game_32_lose_score]

    db.session.commit()
Exemplo n.º 24
0
def admin_submit_scores(game_stage):
    game_labels = Tournament.helper_game_labels(game_stage)

    if game_stage == "group":
        form = AdminGroupStageForm()
    elif game_stage == "R16":
        form = AdminR16StageForm()
    elif game_stage == "QF":
        form = AdminQFStageForm()
    elif game_stage == "SF":
        form = AdminSFStageForm()
    elif game_stage == "F":
        form = AdminFStageForm()

    labels_and_form_items = zip(game_labels, form.games)

    # Retrieve CL tournament
    tournaments = Tournament.query.all()
    if len(tournaments) != 0:
        cl = tournaments[0]
    else:
        cl = Tournament()
        db.session.add(cl)
    cl.calculate_points()
    db.session.commit()

    games_info = {}
    teams_dict = cl.get_teams(game_stage)

    if teams_dict:
        for game_label in game_labels:
            temp = Tournament.helper_parse_game_label(game_label)
            games_info[game_label] = {
                "home_team": teams_dict[temp["home_team"]],
                "away_team": teams_dict[temp["away_team"]]
            }

    if form.validate_on_submit():
        games_dict = {}
        for game in labels_and_form_items:
            games_dict[game[0]] = {
                "result":
                str(game[1].data["home_result"]) + "vs" +
                str(game[1].data["away_result"]),
                "played": (game[1].data["home_result"] != None
                           and game[1].data["home_result"] != None)
            }
        print(games_dict)
        cl.set_games(game_stage, games_dict)
        db.session.commit()
        app.logger.info('Updated Tournament')
        return redirect(url_for('admin_submit_scores', game_stage=game_stage))
    else:
        print("form not valid")
    posts = Post.query.order_by(desc('points')).all()
    return render_template('admin_submit_scores.html',
                           title='Admin',
                           form=form,
                           tournament=cl,
                           labels_and_form_items=labels_and_form_items,
                           games_info=games_info,
                           game_stage=game_stage)
def add_tournament(date, tournament, team):
    t = Tournament(date=date, name=tournament.strip(), team=team.strip())
    db.session.add(t)
    db.session.commit()
Exemplo n.º 26
0
async def main1():
    # run_async is a helper function to run simple async Tortoise scripts.
    # run_async(init())
    await init()
    # await Tortoise.generate_schemas()
    await Tortoise.close_connections()
    print("===============")
    await init()

    tournament = Tournament(name='New Tournament 1')
    await tournament.save()

    # Or by .create()
    await Tournament.create(name='Another Tournament 1')

    # Now search for a record
    tour = await Tournament.filter(name__contains='Another').first()
    print(tour.name)

    # Or by .create()
    await Event.create(name='Without participants', tournament=tournament)
    event = await Event.create(name='Test', tournament=tournament)
    participants = []
    for i in range(2):
        team = await Team.create(name='Team {}'.format(i + 1))
        participants.append(team)

    # M2M Relationship management is quite straightforward
    # (look for methods .remove(...) and .clear())
    await event.participants.add(*participants)

    # You can query related entity just with async for
    async for team in event.participants:
        print(team)

    # After making related query you can iterate with regular for,
    # which can be extremely convenient for using with other packages,
    # for example some kind of serializers with nested support
    for team in event.participants:
        pass

    # Or you can make preemptive call to fetch related objects,
    # so you can work with related objects immediately
    selected_events = await Event.filter(participants=participants[0].id
                                         ).prefetch_related(
                                             'participants', 'tournament')
    for event in selected_events:
        print(event.tournament.name)
        print([t.name for t in event.participants])

    # Tortoise ORM supports variable depth of prefetching related entities
    # This will fetch all events for team and in those team tournament will be prefetched
    await Team.all().prefetch_related('events__tournament')

    # You can filter and order by related models too
    await Tournament.filter(
        events__name__in=['Test', 'Prod']
    ).order_by('-events__participants__name').distinct()

    events = await tournament.events.all()
    print(events)
Exemplo n.º 27
0
 def __init__(self):
     """Init."""
     super().__init__()
     self.title = "Choose a tournament to continue"
     self.all_tournaments = Tournament.all()
Exemplo n.º 28
0
    def test_all(self):

        all_tournaments = Tournament.all()
        self.assertEqual(len(all_tournaments), 3)
Exemplo n.º 29
0
    def test_position(self):

        season_1 = config.orm.query(Season).filter(Season.id == 1).one()  # @UndefinedVariable
        season_2 = config.orm.query(Season).filter(Season.id == 2).one()  # @UndefinedVariable

        self.assertIsInstance(season_1.tournaments, OrderingList)
        self.assertIsInstance(season_2.tournaments, OrderingList)

        self.assertEqual(len(season_1.tournaments), 2)
        self.assertEqual(len(season_2.tournaments), 1)

        self.assertEqual(season_1.tournaments[0].position, 1)
        self.assertEqual(season_1.tournaments[1].position, 2)
        self.assertEqual(season_2.tournaments[0].position, 1)

        self.assertEqual(season_1.tournaments[0].tournament_dt, datetime.date(2009, 9, 1))
        self.assertEqual(season_1.tournaments[1].tournament_dt, datetime.date(2010, 1, 1))
        self.assertEqual(season_2.tournaments[0].tournament_dt, datetime.date(2010, 8, 1))

        tournament_13 = Tournament()
        tournament_13.tournament_dt = datetime.date(2010, 2, 1)
        tournament_13.buyin = 10
        tournament_13.season_id = 1

        season_1.tournaments.append(tournament_13)
        season_1.reorder_tournaments()

        self.assertEqual(len(season_1.tournaments), 3)
        self.assertEqual(len(season_2.tournaments), 1)

        self.assertEqual(season_1.tournaments[0].position, 1)
        self.assertEqual(season_1.tournaments[1].position, 2)
        self.assertEqual(season_1.tournaments[2].position, 3)
        self.assertEqual(season_2.tournaments[0].position, 1)

        self.assertEqual(season_1.tournaments[0].tournament_dt, datetime.date(2009, 9, 1))
        self.assertEqual(season_1.tournaments[1].tournament_dt, datetime.date(2010, 1, 1))
        self.assertEqual(season_1.tournaments[2].tournament_dt, datetime.date(2010, 2, 1))
        self.assertEqual(season_2.tournaments[0].tournament_dt, datetime.date(2010, 8, 1))

        tournament_10 = Tournament()
        tournament_10.tournament_dt = datetime.date(2009, 8, 31)
        tournament_10.buyin = 10
        tournament_10.season_id = 1

        season_1.tournaments.append(tournament_10)
        season_1.reorder_tournaments()

        self.assertEqual(len(season_1.tournaments), 4)
        self.assertEqual(len(season_2.tournaments), 1)

        self.assertEqual(season_1.tournaments[0].position, 1)
        self.assertEqual(season_1.tournaments[1].position, 2)
        self.assertEqual(season_1.tournaments[2].position, 3)
        self.assertEqual(season_1.tournaments[3].position, 4)
        self.assertEqual(season_2.tournaments[0].position, 1)

        self.assertEqual(season_1.tournaments[0].tournament_dt, datetime.date(2009, 8, 31))
        self.assertEqual(season_1.tournaments[1].tournament_dt, datetime.date(2009, 9, 1))
        self.assertEqual(season_1.tournaments[2].tournament_dt, datetime.date(2010, 1, 1))
        self.assertEqual(season_1.tournaments[3].tournament_dt, datetime.date(2010, 2, 1))
        self.assertEqual(season_2.tournaments[0].tournament_dt, datetime.date(2010, 8, 1))
Exemplo n.º 30
0
 def make_tournament(self, data, **kwargs):
     return Tournament(**data)