Beispiel #1
0
    def _create_game(self, players, columns, rows):
        error = Validators()._validate_board(players, columns, rows)
        if error:
            return error

        # This step is currently not needed. The players table is not used.
        # TODO: replace all player_name references with foreign_key on
        # primary_key
        player_ids = []
        for player in players:
            player_row = Players.query.filter_by(player_name=player).first()
            if player_row is None:
                new_player = Players(player_name=player)
                db.session.add(new_player)
                db.session.commit()
                player_row = Players.query.filter_by(
                    player_name=player).first()
            player_ids.append(player_row.player_name)
        player_ids = ','.join(map(str, player_ids))

        new_game = Games(players=str(player_ids),
                         game_columns=columns,
                         game_rows=rows,
                         game_state="IN_PROGRESS")
        db.session.add(new_game)
        db.session.commit()
        game_id = new_game.game_id
        return jsonify({"gameId": str(game_id)})
Beispiel #2
0
def add_player(gameID, name):
    team = (number_of_players(gameID) + 1) % 2
    db_game = Game_Data.query.filter_by(gid=gameID).first()
    db_game.deck, player_cards = Euchre.deal_cards(db_game.deck, 5)
    new_player = Players(name=name, cards=player_cards, gid=gameID, team=team)
    db.session.add(new_player)
    db.session.commit()
Beispiel #3
0
def newPlayer(team_id):
    team = session.query(Teams).filter_by(id=team_id).one()
    if request.method == 'POST':
        # Check csrf token
        if request.form['csrf_token'] != login_session.pop('csrf_token', None):
            return "You are not authorized to make changes"

        newPlayer = Players(name=request.form['name'],
                            position=request.form['position'],
                            number=request.form['number'],
                            handedness=request.form['handedness'],
                            team_id=team_id,
                            user_id=login_session['user_id'])
        session.add(newPlayer)
        session.commit()
        flash('Successfully added %s' % (newPlayer.name))
        return redirect(url_for('showRoster', team_id=team_id))
    else:
        if not google.authorized:
            return "You are not authorized to view this page. Please log in."
        else:
            # if owner
            if team.user_id == getUserID(login_session['email']):
                # Create and store csrf token before rendering template
                state = ''.join(
                    random.choice(string.ascii_uppercase + string.digits)
                    for x in range(32))
                login_session['csrf_token'] = state
                return render_template('newPlayer.html',
                                       team=team,
                                       team_id=team_id)
            # if not owner
            else:
                return "You are not the owner of the team or player."
Beispiel #4
0
def updatePlPlayers():
    session = CreateSession()
    p = session.query(Players).delete()
    bootstrapData = GetBootstrapData()
    playerData = bootstrapData['elements']
    for i in playerData:
        plyr = Players(jfpl=i['id'],
                       event_points=i['event_points'],
                       first_name=i['first_name'],
                       second_name=i['second_name'],
                       web_name=i['web_name'],
                       team=i['team'],
                       team_code=i['team_code'],
                       goals_scored=i['goals_scored'],
                       assists=i['assists'],
                       goals_conceded=i['goals_conceded'],
                       pen_saved=i['penalties_saved'],
                       pen_missed=i['penalties_missed'],
                       yellow_cards=i['yellow_cards'],
                       red_cards=i['red_cards'],
                       saves=i['saves'],
                       element_type=i['element_type'])
        session.add(plyr)
    session.commit()
    session.close()
Beispiel #5
0
def create_user_route():
	content = request.json

	current_game = Games.query.filter_by(live_game = 1).filter_by(join_code = content['join_code']).first()
	if current_game == None:
		return jsonify({
				'status' : 'error',
				'message' : 'Game code does not exist.'
			})

	current_user = Players.query.filter_by(game_id = current_game.id).filter_by(nickname = content['nickname']).first()
	if current_user != None:
		return jsonify({
				'status' : 'error',
				'message' : 'Player currently using that nickname. Please pick a different nickname.'
			})

	player_id = generate_random_string(10,30)
	new_player = Players(player_id, content['nickname'], current_game.id)
	db.session.add(new_player)
	db.session.commit()

	return jsonify({
			'status' : 'success',
			'id' : player_id,
			'game_id' : current_game.id
		})
Beispiel #6
0
 def setUp(self):
     self.players = Players()
     self.players.add_player(models.Player('Erik'))
     self.players.add_player(models.Player('Erty'))
     self.players.add_player(models.Player('Alex'))
     self.game = game.Game(self.players)
     self.players.start_game()
Beispiel #7
0
def addplayer():
    if request.method == 'GET':
        last, number = [], []
        players = Players()
        last, number, player_id = players.get_players(current_user.id)
        return render_template('addplayer.html',
                               last=last,
                               player_id=player_id,
                               number=number,
                               username=str(current_user.username))
    if request.method == 'POST' and request.form.get('edit') == 'false':
        last = str(request.form.get('last'))
        number = str(request.form.get('number'))
        players = Players()
        players.add_player(last, number, current_user.id)
        first, last, number = [], [], []
        last, number, player_id = players.get_players(current_user.id)
        return render_template('addplayer.html',
                               last=last,
                               player_id=player_id,
                               number=number,
                               username=str(current_user.username))
    if request.method == 'POST' and request.form.get('edit') == 'true':
        name = str(request.form.get('name'))
        number = str(request.form.get('number'))
        player_id = str(request.form.get('id'))
        players = Players()
        players.edit_player(name, number, current_user.id, player_id)
        first, last, number = [], [], []
        last, number, player_id = players.get_players(current_user.id)
        return render_template('addplayer.html',
                               last=last,
                               player_id=player_id,
                               number=number,
                               username=str(current_user.username))
    if request.method == 'POST' and request.form.get('delete') == 'true':
        player_id = str(request.form.get('id'))
        players = Players()
        players.delete_player(player_id)
        first, last, number = [], [], []
        last, number, player_id = players.get_players(current_user.id)
        return render_template('addplayer.html',
                               last=last,
                               player_id=player_id,
                               number=number,
                               username=str(current_user.username))
Beispiel #8
0
def game_play(game, play, zone):
    if request.method == "GET":
        if zone == 'None':
            zone = None
        g = Game()
        players = Players()
        last, number, player_id = players.get_deleted_players(current_user.id)
        individual, ind_used = g.play_data(current_user.id, play, game,
                                           player_id, zone)
        zone_eff, zone_used = g.zones_plays(current_user.id, player_id, play,
                                            game)
        player_names, player_values, ind_names, ind_values, used_player_id, eff_player_id, eff_player_id, used_number, eff_number = [], [], [], [], [], [], [], [], []
        for key, value in sorted(individual.items(),
                                 key=lambda kv: kv[1],
                                 reverse=True):
            player_names.append(players.get_player(key))
            player_values.append(str(value))
            eff_player_id.append(key)
            eff_number.append(players.get_number(key))
        for key, value in sorted(ind_used.items(),
                                 key=lambda kv: kv[1],
                                 reverse=True):
            ind_names.append(players.get_player(key))
            ind_values.append(str(value))
            used_player_id.append(key)
            used_number.append(players.get_number(key))
        p = Plays()
        ng = NewGame()
        game_Name = ng.get_game_name(game)
        my_play = p.get_play(play)
        return render_template('game_play.html',
                               play=play,
                               game_Name=game_Name,
                               game=game,
                               my_play=my_play,
                               player_names=player_names,
                               player_values=player_values,
                               ind_names=ind_names,
                               ind_values=ind_values,
                               eff_player_id=eff_player_id,
                               used_player_id=used_player_id,
                               zone_eff=zone_eff,
                               zone_used=zone_used,
                               username=str(current_user.username),
                               used_number=used_number,
                               eff_number=eff_number,
                               zone=zone)
    if request.method == "POST" and request.form.get('zone') == 'false':
        player_id = str(request.form.get('player'))
        return redirect(
            url_for('game_play_player', game=game, play=play,
                    player=player_id))
    if request.method == "POST" and request.form.get('zone') != 'false':
        zone = str(request.form.get('zone'))
        return redirect(url_for('game_play', game=game, play=play, zone=zone))
Beispiel #9
0
def game_player(game, player, zone):
    if request.method == "GET":
        if zone == 'None':
            zone = None
        play = Plays()
        playlist, play_id = play.get_deleted_plays(current_user.id)
        g = Game()
        individual, ind_used = g.player_data(current_user.id, player, game,
                                             play_id, zone)
        zone_eff, zone_used = g.zones_players(current_user.id, play_id, player,
                                              game)
        play_names, play_values, ind_names, ind_values, used_play_id, eff_play_id = [], [], [], [], [], []
        for key, value in sorted(individual.items(),
                                 key=lambda kv: kv[1],
                                 reverse=True):
            play_names.append(play.get_play(key))
            play_values.append(str(value))
            eff_play_id.append(key)
        for key, value in sorted(ind_used.items(),
                                 key=lambda kv: kv[1],
                                 reverse=True):
            ind_names.append(play.get_play(key))
            ind_values.append(str(value))
            used_play_id.append(key)
        p = Players()
        player_name = p.get_player(player)
        player_number = p.get_number(player)
        my_player = player_number + ' - ' + player_name
        ng = NewGame()
        game_name = ng.get_game_name(game)
        return render_template('game_player.html',
                               game=game,
                               game_name=game_name,
                               player=player,
                               my_player=my_player,
                               play_names=play_names,
                               play_values=play_values,
                               ind_names=ind_names,
                               ind_values=ind_values,
                               eff_play_id=eff_play_id,
                               used_play_id=used_play_id,
                               zone_eff=zone_eff,
                               zone_used=zone_used,
                               username=str(current_user.username),
                               zone=zone)
    if request.method == "POST" and str(request.form.get('zone')) == 'false':
        play_id = str(request.form.get('play'))
        return redirect(
            url_for('game_play_player', game=game, play=play_id,
                    player=player))
    elif request.method == "POST" and str(request.form.get('zone')) != 'false':
        zone = str(request.form.get('zone'))
        return redirect(
            url_for('season_player', game=game, player=player, zone=zone))
Beispiel #10
0
Datei: app.py Projekt: tonp/point
def postGame():
    try:
        # Add players
        addPlayer1 = Players(request.json['players'][0])
        addPlayer2 = Players(request.json['players'][1])
        db.session.add(addPlayer1)
        db.session.add(addPlayer2)

        # Add new Game
        newGame = Game('IN PROGRESS', '', request.json['columns'],
                       request.json['rows'])
        db.session.add(newGame)
        db.session.commit()

        # Star new game session
        session = GameSession(addPlayer1.id, addPlayer2.id, newGame.id)
        db.session.add(session)
        db.session.commit()

        return jsonify({'gameId': str(newGame.id)})
    except:
        return jsonify({"Error": "400"}), 400
Beispiel #11
0
def main():
    """
    Main method of seabattle game.
    """
    sb_field = create_field()
    p_name = input('Введите своё имя: ')
    player1 = Players(p_name, 1) if p_name else Players(queue=1)

    # player1 = Players('Pavel', 1)
    player2 = Players('Python', 2)
    print(f'   {player1.name}\'s field' + ' ' * sb_field.size_x * 5 + f'   {player2.name}\'s field')
    sb_field.draw()

    player1_ships = sb_field.setup()
    # player1_ships = sb_field.fast_setup()
    player2_ships = sb_field.fast_setup(shift=12)
    # for ship in player1_ships:
    #     print(ship)
    # for ship in player2_ships:
    #     print(ship)
    print(f'   {player1.name}\'s field' + ' ' * sb_field.size_x * 5 + f'   {player2.name}\'s field')
    sb_field.draw()
    game(player1, player2, player1_ships, player2_ships, sb_field)
Beispiel #12
0
def registerAction():
    if request.method == 'POST':
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        DOB = request.form['DOB']
        favourite_game = request.form['favourite_game']
        phonenumber = request.form['phonenumber']
        phonetype = request.form.get('phonetype')
        username = request.form['username']
        password = request.form['password']
        usr = Players(first_name, last_name, DOB, favourite_game, phonenumber, phonetype, username, password)
        db.session.add(usr)
        db.session.commit()
        session['username'] = username
    return render_template("hello.html", username = session['username'])
def registerAction():
    if request.method == 'POST':
        first_name = request.form['firstname']
        last_name = request.form['lastname']
        dob = request.form['dob']
        fav_game = request.form['favouritegame']
        contactnumber = request.form['phonenumber']
        phonetype = request.form.get('phonetype')
        usrname = request.form['username']
        pwd = request.form['password']
        usr = Players(first_name,last_name,dob, fav_game, contactnumber, phonetype, usrname, pwd)
        db.session.add(usr)
        db.session.commit()
        session['username'] = usrname
    return render_template("home.html", usrname = session['username'])
Beispiel #14
0
def home(username):
    if request.method == "GET":
        games, game_id = [], []
        game_list = NewGame()
        game = Game()
        players = Players()
        last, number, player_id = players.get_players(current_user.id)
        play = Plays()
        playList, play_id = play.get_plays(current_user.id)
        total, efficient, individual, ind_used = game.data(
            current_user.id, player_id, play_id, None)
        if (len(total) != 0):
            total = total.most_common(1)[0][0]
            total = play.get_play(total)
        else:
            total = "You haven't used any plays yet."
        if (len(efficient) != 0):
            efficient = efficient.most_common(1)[0][0]
            efficient = play.get_play(efficient)
        else:
            efficient = "You haven't used any plays yet."
        if (len(individual) != 0):
            eff_player = individual.most_common(1)[0][0]
            eff_number = players.get_number(eff_player)
            player_name = players.get_player(eff_player)
            eff_player = eff_number + ' - ' + player_name
        else:
            eff_player = "You haven't used any players yet."
        if (len(ind_used) != 0):
            used_player = ind_used.most_common(1)[0][0]
            used_number = players.get_number(used_player)
            player_name = players.get_player(used_player)
            used_player = used_number + ' - ' + player_name

        else:
            used_player = "You haven't used any players yet."

        data = []
        data.append(str(total))
        data.append(str(efficient))
        data.append(str(eff_player))
        data.append(str(used_player))
        return render_template('home.html', data=data, username=username)
    elif request.method == "POST":
        if (str(request.form.get('signout')) == 'true'):
            logout_user()
            return redirect(url_for('index'))
Beispiel #15
0
def season_play_player(play, player):
    if request.method == "GET":
        game = Game()
        zone_eff, zone_used = game.zones_both(current_user.id, play, player,
                                              None)
        players = Players()
        player_name = players.get_player(player)
        player_number = players.get_number(player)
        my_player = player_number + ' - ' + player_name
        p = Plays()
        my_play = p.get_play(play)
        return render_template('season_play_player.html',
                               my_player=my_player,
                               my_play=my_play,
                               zone_used=zone_used,
                               zone_eff=zone_eff,
                               username=str(current_user.username))
Beispiel #16
0
def add_player():
    name = request.args.get('name')
    club = request.args.get('club')
    age = request.args.get('age')
    nationality = request.args.get('nationality')
    appearances = request.args.get('appearances')
    goals = request.args.get('goals')
    assists = request.args.get('assists')
    player = Players(name=name,
                     club=club,
                     age=age,
                     nationality=nationality,
                     appearances=appearances,
                     goals=goals,
                     assists=assists)
    db.session.add(player)
    db.session.commit()
    return "Player added. player id={}".format(player.player_id)
Beispiel #17
0
def game_play_player(game, play, player):
    if request.method == "GET":
        g = Game()
        zone_eff, zone_used = g.zones_both(current_user.id, play, player, game)
        players = Players()
        player_name = players.get_player(player)
        player_number = players.get_number(player)
        my_player = player_number + ' - ' + player_name
        p = Plays()
        my_play = p.get_play(play)
        ng = NewGame()
        my_game = ng.get_game_name(game)
        return render_template('game_play_player.html',
                               my_game=my_game,
                               my_player=my_player,
                               my_play=my_play,
                               zone_used=zone_used,
                               zone_eff=zone_eff,
                               username=str(current_user.username))
def registerAction():
    if request.method == 'POST':
        username = request.form['username']
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        password = request.form['password']
        dob = request.form['dob']
        phone = request.form['phone']
        phone_type = request.form.get('phone_type')
        fav_game = request.form['fav_game']
        user = Players(first_name, last_name, username, password, dob, phone,
                       phone_type, fav_game)
        db.session.add(user)
        db.session.commit()
        session['username'] = username
    currentTime = datetime.now()
    return render_template("welcome.html",
                           username=session['username'],
                           current_login_time=currentTime)
Beispiel #19
0
def mahjong_game():
    valid_r = None
    valid_p = None
    id = request.form['researcher']
    player_id = request.form['player']

    if not ((id.isdigit() or id == '') and player_id.isdigit()):
        return redirect(url_for('mahjong_player_login_failed3'))

    valid_r = db.session.query(Researchers.r_id).filter_by(r_id=id).first()

    try:
        gID = request.form['useGenericID']
        if (gID == 'on'):
            valid_r = True
            id = 0
    except:
        pass

    if (valid_r == None):
        return redirect(url_for('mahjong_player_login_failed'))  #invalid case

    valid_p = db.session.query(
        Players.user_id).filter_by(user_id=player_id).first()

    try:
        add_new_player = request.form['addNewPlayer']
        if (add_new_player == 'on'):
            newPlayer = Players(user_id=player_id)
            db.session.add(newPlayer)
            db.session.commit()
            valid_p = True
    except:
        pass

    if (valid_p == None):
        return redirect(url_for('mahjong_player_login_failed2'))

    return render_template('Mahjong/game.html', user_id=player_id, r_id=id)
Beispiel #20
0
    def post_player(token):
        if type(token) == AuthError:
            print(token)
            abort(token.status_code)

        body = request.get_json()
        name = body.get('name', None)
        nationality = body.get('nationality', None)
        rating = body.get('rating', None)
        team_id = body.get('team_id', None)

        try:
            if rating <= 0 or rating >= 100:
                abort(422)
            new_player = Players(name=name,
                                 nationality=nationality,
                                 rating=rating,
                                 team_id=team_id)
            new_player.insert()
        except Exception as e:
            print(e)
            abort(422)

        return jsonify({"success": True, "player": new_player.long()}), 200
Beispiel #21
0
                    goals_scoredP = idx
                if x == 'minutes':
                    minutesP = idx
                if x == 'penalties_saved':
                    penalties_savedP = idx
                if x == 'red_cards':
                    red_cardsP = idx
                if x == 'saves':
                    savesP = idx
                if x == 'yellow_cards':
                    yellow_cardsP = idx

            print(f'Column names are {", ".join(row)}')
            line_count += 1
        else:
            print(row[yellow_cardsP])
            allPlayers = Players(first_name=row[first_nameP],
                                 second_name=row[second_nameP],
                                 assists=row[assistsP],
                                 clean_sheets=row[clean_sheetsP],
                                 form=row[formP],
                                 goals_conceded=row[goals_concededP],
                                 goals_scored=row[goals_scoredP],
                                 minutes=row[minutesP],
                                 penalties_saved=row[penalties_savedP],
                                 red_cards=row[red_cardsP],
                                 yellow_cards=row[yellow_cardsP])
            db.session.add(allPlayers)
            db.session.commit()
            line_count += 1
Beispiel #22
0
def edit_game(game):
    if request.method == "GET":
        play, player, number = [], [], []
        g = Game()
        p = Plays()
        play_name, play_id_list = p.get_plays(current_user.id)
        pl = Players()
        player_name, player_number, player_id_list = pl.get_players(
            current_user.id)
        possession, play_id, player_id, zone, result = g.game_data(
            current_user.id, game)
        for i in play_id:
            play.append(p.get_play(i))
        for i in player_id:
            player.append(pl.get_player(i))
            number.append(pl.get_number(i))
        ng = NewGame()
        my_game = []
        game_name = ng.get_game_name(game)
        my_game.append(game_name)
        return render_template('edit_game.html',
                               game=game,
                               game_name=game_name,
                               my_game=my_game,
                               possession=possession,
                               play=play,
                               player=player,
                               zone=zone,
                               result=result,
                               play_id=play_id,
                               player_id=player_id,
                               player_name=player_name,
                               player_number=player_number,
                               player_id_list=player_id_list,
                               play_name=play_name,
                               play_id_list=play_id_list,
                               username=str(current_user.username),
                               number=number)
    if request.method == "POST" and str(request.form.get('add')) == 'false':
        possession = str(request.form.get('possession'))
        play = str(request.form.get('play'))
        player = str(request.form.get('player'))
        zone = str(request.form.get('zone'))
        result = str(request.form.get('result'))
        game = str(request.form.get('game'))
        g = Game()
        g.edit_possession(possession, play, player, zone, result, game)
        return redirect(url_for('edit_game', game=game))
    if request.method == "POST" and str(request.form.get('add')) == 'true':
        possession = str(request.form.get('possession'))
        play = str(request.form.get('play'))
        player = str(request.form.get('player'))
        zone = str(request.form.get('zone'))
        result = str(request.form.get('result'))
        g = Game()
        g.add_possession(game, possession, play, player, zone, result,
                         current_user.id)
        return redirect(url_for('edit_game', game=game))
    if request.method == "POST" and str(request.form.get('delete')) == 'true':
        game = str(request.form.get('game'))
        g = Game()
        ng = NewGame()
        g.delete_game(game)
        ng.delete_game(game)
        return redirect(url_for('games'))
Beispiel #23
0
def offense(game, possession):
    if request.method == "GET":
        last, number, plays, play_id, players, plays, numbers = [],[],[],[],[],[],[],
        p = Plays()
        playlist, play_id = p.get_plays(current_user.id)
        pl = Players()
        last, number, player_id = pl.get_players(current_user.id)
        gamereturn = []
        gamereturn.append(str(game))
        get_game = NewGame()
        game_id = get_game.get_game(game, current_user.id)
        g = Game()
        possessions, play_ids, player_ids, zones, results = g.game_data(
            current_user.id, game_id)
        for i in play_ids:
            plays.append(p.get_play(i))
        for i in player_ids:
            players.append(pl.get_player(i))
            numbers.append(pl.get_number(i))
        return render_template('offense.html',
                               last=last,
                               play=playlist,
                               player_id=player_id,
                               play_id=play_id,
                               player_ids=player_ids,
                               play_ids=play_ids,
                               game=gamereturn,
                               gameName=game,
                               game_id=game_id,
                               username=str(current_user.username),
                               number=number,
                               possession=possession,
                               possessions=possessions,
                               plays=plays,
                               players=players,
                               zones=zones,
                               results=results,
                               numbers=numbers)
    elif request.method == "POST" and request.form.get('edit') == 'false':
        playName = request.form.get('play')
        player = request.form.get('player')
        zone = request.form.get('zone')
        result = request.form.get('result')
        possession = request.form.get('possession')
        if possession == 'None':
            possession = '0'
        my_game = Game()
        get_game = NewGame()
        game_id = get_game.get_game(game, current_user.id)
        my_game.add_possession(str(game_id), str(possession), str(playName),
                               str(player), str(zone), str(result),
                               str(current_user.id))
        return redirect(
            url_for('offense', game=game, possession=str(int(possession) + 1)))
    elif request.method == "POST" and request.form.get('edit') == 'true':
        possession = str(request.form.get('possession'))
        possession1 = str(request.form.get('possession1'))
        play = str(request.form.get('play'))
        player = str(request.form.get('player'))
        zone = str(request.form.get('zone'))
        result = str(request.form.get('result'))
        get_game = NewGame()
        game_id = get_game.get_game(game, current_user.id)
        g = Game(game_id=game_id)
        g.edit_possession(possession, play, player, zone, result, game_id)
        return redirect(url_for('offense', game=game, possession=possession1))
Beispiel #24
0
def game(game, zone):
    if request.method == "GET":
        if zone == 'None':
            zone = None
        g = Game()
        players = Players()
        last, number, player_id = players.get_deleted_players(current_user.id)
        total, efficient, individual, ind_used = g.individual_data(
            current_user.id, game, player_id, zone)
        play = Plays()
        zone_eff, zone_used = g.zones_plays(current_user.id, player_id, None,
                                            game)
        most_used, most_efficient, used_name, efficient_name, player_names, player_values, ind_names, ind_values, used_play_id, used_player_id, eff_play_id, eff_player_id, used_number, eff_number = [], [], [], [], [], [], [], [], [], [], [], [], [], []
        for key, value in sorted(efficient.items(),
                                 key=lambda kv: kv[1],
                                 reverse=True):
            most_efficient.append(play.get_play(key))
            efficient_name.append(str(value))
            eff_play_id.append(str(key))
        for key, value in sorted(total.items(),
                                 key=lambda kv: kv[1],
                                 reverse=True):
            most_used.append(play.get_play(key))
            used_name.append(str(value))
            used_play_id.append(str(key))
        for key, value in sorted(individual.items(),
                                 key=lambda kv: kv[1],
                                 reverse=True):
            player_names.append(players.get_player(key))
            player_values.append(str(value))
            eff_player_id.append(key)
            eff_number.append(players.get_number(key))
        for key, value in sorted(ind_used.items(),
                                 key=lambda kv: kv[1],
                                 reverse=True):
            ind_names.append(players.get_player(key))
            ind_values.append(str(value))
            used_player_id.append(key)
            used_number.append(players.get_number(key))
        ng = NewGame()
        my_game = []
        game_Name = ng.get_game_name(game)
        my_game.append(game_Name)
        return render_template('gameList.html',
                               game=game,
                               game_Name=game_Name,
                               my_game=my_game,
                               most_used=most_used,
                               most_efficient=most_efficient,
                               used_name=used_name,
                               efficient_name=efficient_name,
                               player_names=player_names,
                               player_values=player_values,
                               ind_names=ind_names,
                               ind_values=ind_values,
                               used_play_id=used_play_id,
                               eff_player_id=eff_player_id,
                               eff_play_id=eff_play_id,
                               used_player_id=used_player_id,
                               zone_eff=zone_eff,
                               zone_used=zone_used,
                               username=str(current_user.username),
                               used_number=used_number,
                               eff_number=eff_number,
                               zone=zone)
    elif request.method == "POST" and str(
            request.form.get('player')) == 'false':
        play_id = str(request.form.get('play'))
        return redirect(
            url_for('game_play', game=game, play=play_id, zone='None'))
    elif request.method == "POST" and str(request.form.get('play')) == 'false':
        player_id = str(request.form.get('player'))
        return redirect(
            url_for('game_player', game=game, player=player_id, zone='None'))
    elif request.method == "POST" and str(
            request.form.get('play')) == 'fals' and str(
                request.form.get('player')) == 'fals':
        zone = str(request.form.get('zone'))
        return redirect(url_for('game', game=game, zone=zone))
engine = create_engine('sqlite:///baseball.db')
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
session = DBSession()

# Populate baseball.db with teams and players

# Team Scorpions
scorpions = Teams(name="Scorpions")
session.add(scorpions)
session.commit()

# Scorpions Roster
gutierrez = Players(name="Randal Gutierrez", position="1B", number="44",
                    handedness="L", teams=scorpions)
session.add(gutierrez)
session.commit()

walsh = Players(name="Horace Walsh", position="2B", number="12",
                handedness="R", teams=scorpions)
session.add(walsh)
session.commit()

jones = Players(name="Steve Jones", position="3B", number="71", handedness="R",
                teams=scorpions)
session.add(jones)
session.commit()

houston = Players(name="Joel Houston", position="SS", number="3",
                  handedness="R", teams=scorpions)
Beispiel #26
0
import os
from app import db
from models import Players

PLAYERS = [{
    'username': '******',
    'password': '******'
}, {
    'username': '******',
    'password': '******'
}, {
    'username': '******',
    'password': '******'
}]

for user in PLAYERS:
    p = Players(username=user['username'], password=user['password'])
    db.session.add(p)
db.session.commit()