Exemple #1
0
 def tearDown(self):
     """Rip out the database tables to have a 'clean slate' for the next test case."""
     db.session.remove()
     db.drop_all()
Exemple #2
0
from __init__ import db
db.drop_all()
db.create_all()
Exemple #3
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Exemple #4
0
def dropdb():
    if prompt_bool("Are you sure you want to lose all your data"):
        db.drop_all()
        print('Dropped the database')
Exemple #5
0
def populate():

    db.session.remove()
    db.drop_all()
    db.create_all()
    # db.session.commit()
    # sys.exit()

    # print(len(teams))
    # sys.exit()

    t = 1
    for team_id in teams:
        team = teams[team_id]

        team_entry = Team(
                name = str(team['last_name']),
                conference = team['conference'],
                division =  team['division'],
                site_name = team['site_name'],
                city = team['city'],
                state = team['state'],
                mascot = team['mascot'],
                twitter = team['twitter'],
                citation = team['citation'],
                google_maps = team['google_maps'],
            )
        db.session.add(team_entry)
        db.session.commit()
        print(t)
        t += 1

    # sys.exit()

    # i = 1
    # print(len(players))
    for player_name in players:
        player = players[player_name]
        player_career_stats = player['career_stats_avg_per_game']
        player_season_stats = player['stats_avg_per_game']
        # print(type(player_season_stats))
        print(player_name)
        # sys.exit()
        # print(player['current_team'][player['current_team'].rfind(" ") + 1:])
        # sys.exit()
        player_current_team = player['current_team'][player['current_team'].rfind(" ") + 1:]
        if(player_current_team == 'Blazers'):
            player_current_team = 'Trail Blazers'

        player_entry = Player(
                id = player['id'],
                name = player_name,
                picture = player['picture'],
                experience_years = player['experience_years'],
                draft_info = player['draft_info'],
                position = player['position'],
                player_number = player['player_number'],
                current_team = player['current_team'],
                college = player['college'],
                birth_info = player['birth_info'],
                weight = player['weight'],
                twitter = player['twitter'],
                age = player['age'],
                youtube_link_1 = player['youtube_links'][0],
                youtube_link_2 = player['youtube_links'][1],
                youtube_link_3 = player['youtube_links'][2],
                career_GS = player_career_stats['career_GS'],
                career_REB = player_career_stats['career_REB'],
                career_BLK = player_career_stats['career_BLK'],
                career_FT_PCT = player_career_stats['career_FT%'],
                career_DR = player_career_stats['career_DR'],
                career_MIN = player_career_stats['career_MIN'],
                career_FG_PCT = player_career_stats['career_FG%'],
                career_3PM_A = player_career_stats['career_3PM-A'],
                career_OR = player_career_stats['career_OR'],
                career_FGM_A = player_career_stats['career_FGM-A'],
                career_STL = player_career_stats['career_STL'],
                career_TO = player_career_stats['career_TO'],
                career_3PM_PCT = player_career_stats['career_3P%'],
                career_AST = player_career_stats['career_AST'],
                career_GP = player_career_stats['career_GP'],
                career_PF = player_career_stats['career_PF'],
                career_PTS = player_career_stats['career_PTS'],
                CAREER_FTM_A = player_career_stats['career_FTM-A'],
                season_TO = player_season_stats['TO'],
                season_GS = player_season_stats['GS'],
                season_FG_PCT = player_season_stats['FG%'],
                season__PTS = player_season_stats['PTS'],
                season_OR = player_season_stats['OR'],
                season_GP = player_season_stats['GP'],
                season_PF = player_season_stats['PF'],
                season_REB = player_season_stats['REB'],
                season_FTM_A = player_season_stats['FTM-A'],
                season_BLK = player_season_stats['BLK'],
                season_MIN = player_season_stats['MIN'],
                season_STL = player_season_stats['STL'],
                season_AST = player_season_stats['AST'],
                season_FT_PCT = player_season_stats['FT%'],
                season_FGM_A = player_season_stats['FGM-A'],
                season_3P_PCT = player_season_stats['3P%'],
                season_DR = player_season_stats['DR'],
                season_3PM_A = player_season_stats['3PM-A'],
                citation = player['citation'],
                team_name = player_current_team,
            )
        db.session.add(player_entry)
        db.session.commit()
        # print(i)
        # i += 1

    i = 1
    for game_id in nbaGames:
        game = nbaGames[game_id]
        if game['season'] == '2014':
            home_team_stats = findGameStats(game['game_id'], game['home_id'])
            # print(home_team_stats)
            # sys.exit()
            away_team_stats = findGameStats(game['game_id'], game['away_id'])
            # print(away_team_stats)
            # sys.exit()

            # print("game id: " + game_id + "   home team " + str(game['home_id']) + "  away team: " + str(game['away_id']))
            if not home_team_stats == None:
                game_entry = Game(
                        id = game['id'],
                        home_team = teams[str(game['home_id'])]['last_name'],
                        away_team = teams[str(game['away_id'])]['last_name'],
                        date = game['date'] * 1000,
                        date_string = game['date_string'],
                        home_score = game['home_score'],
                        away_score = game['away_score'],
                        home_box_fgm = home_team_stats['box_fgm'],
                        home_box_fga = home_team_stats['box_fga'],
                        home_box_fg3m = home_team_stats['box_fg3m'],
                        home_box_fg3a = home_team_stats['box_fg3a'],
                        home_box_ftm = home_team_stats['box_ftm'],
                        home_box_fta = home_team_stats['box_fta'],
                        home_box_oreb = home_team_stats['box_oreb'],
                        home_box_dreb = home_team_stats['box_dreb'],
                        home_box_ast = home_team_stats['box_ast'],
                        home_box_stl = home_team_stats['box_stl'],
                        home_box_blk = home_team_stats['box_blk'],
                        home_box_to = home_team_stats['box_to'],
                        home_box_pf = home_team_stats['box_pf'],
                        home_box_pts = home_team_stats['box_pts'],
                        home_box_plus_minus = home_team_stats['box_plus_minus'],
                        away_box_fgm = away_team_stats['box_fgm'],
                        away_box_fga = away_team_stats['box_fga'],
                        away_box_fg3m = away_team_stats['box_fg3m'],
                        away_box_fg3a = away_team_stats['box_fg3a'],
                        away_box_ftm = away_team_stats['box_ftm'],
                        away_box_fta = away_team_stats['box_fta'],
                        away_box_oreb = away_team_stats['box_oreb'],
                        away_box_dreb = away_team_stats['box_dreb'],
                        away_box_ast = away_team_stats['box_ast'],
                        away_box_stl = away_team_stats['box_stl'],
                        away_box_blk = away_team_stats['box_blk'],
                        away_box_to = away_team_stats['box_to'],
                        away_box_pf = away_team_stats['box_pf'],
                        away_box_pts = away_team_stats['box_pts'],
                        away_box_plus_minus = away_team_stats['box_plus_minus'],
                        youtube_link_1 = game['youtube_links'][0],
                        youtube_link_2 = game['youtube_links'][1],
                        youtube_link_3 = game['youtube_links'][2],
                )
                db.session.add(game_entry)
                db.session.commit()
        print(i)
        i += 1
Exemple #6
0
def recreate_db():
    """Recreates a database."""
    db.drop_all()
    db.create_all()
    db.session.commit()
Exemple #7
0
def db_drop_and_create_all():
    db.session.close()
    db.drop_all()
    db.create_all()
Exemple #8
0
def db_drop_and_create_all():
    db.drop_all()
    db.create_all()
Exemple #9
0
def setup_for_testing():
    db.drop_all()
    db.create_all()
    log('DB created')
    p = Pilot('junu_k', 'junu', '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
    p.is_admin = True
    p.id_confirmed = True
    p.level = 50
    p.gen = 10
    db.session.add(p)

    gn = GameNight()
    from datetime import datetime
    gn.date = datetime.now()
    db.session.add(gn)

    ps = []
    for i in range(20):
        p = Pilot('junu_k' + str(i), 'junu' + str(i), '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
        p.is_admin = False
        p.id_confirmed = True
        p.level = 12 + i
        p.gen = 2
        ps.append(p)
        db.session.add(p)
        # db.session.commit()
    db.session.commit()

    # team with currently 4 members
    import controllers.team_controller
    tc = controllers.team_controller.TeamController()
    t = add_team('Team1', ps[1])
    add_pilot(t, ps[2], False)
    add_pilot(t, ps[3], False)
    add_pilot(t, ps[4], False)
    add_pilot(t, ps[16], False)
    
    t1id = t.id

    r1 = Roster()
    r1.members = t.members
    r1.team_id = t.id
    r1.game_night_id = gn.id

    db.session.add(r1)
    db.session.commit()

    #team with currently 3 members
    t = add_team('Team2', ps[5])
    add_pilot(t, ps[6], False)
    add_pilot(t, ps[7], False)
    add_pilot(t, ps[14], False)
    add_pilot(t, ps[15], False)

    t2id = t.id

    r1 = Roster()
    r1.members = t.members
    r1.team_id = t.id
    r1.game_night_id = gn.id

    db.session.add(r1)
    db.session.commit()

    #team with currently 5 members
    t = add_team('Team3', ps[8])
    add_pilot(t, ps[9], False)
    add_pilot(t, ps[11], False)
    add_pilot(t, ps[12], False)
    add_pilot(t, ps[13], True)

    t3id = t.id

    r1 = Roster()
    r1.members = t.members
    r1.team_id = t.id
    r1.game_night_id = gn.id

    db.session.add(r1)
    db.session.commit()

    m1 = Match()
    m1.game_night_id = gn.id
    m1.winner_team_id = t1id
    m1.loser_team_id = t2id
    m1.winner_points = 10
    m1.loser_points = 9
    game_type = "capture the flag"

    db.session.add(m1)
    db.session.commit()

    mp1 = MatchParticipant()
    mp1.match_id = m1.id
    mp1.team_id = t1id

    mp2 = MatchParticipant()
    mp2.match_id = m1.id
    mp2.team_id = t2id

    log('DB setup completed')

    


    # p1 = Pilot('junu_k', 'junu', '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
    # db.session.add(p1)
    # p2 = Pilot('junu_k2', 'junu2', '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
    # db.session.add(p2)

    # p3 = Pilot('junu_k3', 'junu3', '6d9b643bb4a0057328ec6e76884b168bcac868cc5e5d261d1d209c0b5297a18587cc4274ed264059ac6718eeb5ca7d276ffd147eebfb71b9098468f5b520cc0c', '655f3080cbe94b6688bbd71740baebe5', 'PC-ALL')
    # db.session.add(p3)

    # p1.is_admin = True
    # p1.id_confirmed = True
    # p1.level = 12
    # p1.gen = 2

    # p2.id_confirmed = True
    # p2.level = 32
    # p2.gen = 1

    # p3.id_confirmed = True
    # p3.level = 50
    # p3.gen = 10
    # db.session.commit()
    # import controllers.team_controller

    # tc = controllers.team_controller.TeamController()
    # t = add_team('Conquest and Kittens', p1)
    # add_pilot(t, p2, False)
    # add_pilot(t, p3, True)

    db.session.commit()
Exemple #10
0
def dropdb():
    if prompt_bool("Are you sure you want to drop your database?"):
        db.drop_all()
        print('Dropped the Database')
Exemple #11
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Exemple #12
0
def create_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
Exemple #13
0
 def tearDown(self):
     with app.test_request_context():
         db.drop_all()