コード例 #1
0
def update_pstats_starter():
    db = dfm.create_nba_dbwrapper()
    queries = PStatsStarterUpdate(db.conn).create_queries()

    db_update = udb.DBUpdate(db)
    log_path = create_log_path('DB Update - starter')
    db_update.update(queries, log_path)
コード例 #2
0
def add_new_tstats():
    db = dfm.create_nba_dbwrapper()
    min_gd = db.query_scalar('SELECT MAX(gd) FROM teamstats')
    max_gd = datetime.datetime.today()
    queries = NewTStats(min_gd, max_gd).create_queries()

    db_update = udb.DBUpdate(db)
    log_path = create_log_path('DB Insert - TStats')
    db_update.update(queries, log_path)
コード例 #3
0
def update_pstats_tsid(season=None):
    db = dfm.create_nba_dbwrapper()
    queries = PStatsTSIDUpdate(db.conn, season).create_queries()

    db_update = udb.DBUpdate(db)
    if season:
        log_path = create_log_path('DB Update - tsid - {}'.format(season))
    else:
        log_path = create_log_path('DB Update - tsid')
    db_update.update(queries, log_path)
コード例 #4
0
    idx = row[idx_col]
    new_name = udb.clean_str_for_sql(row['new_name'])
    s = "UPDATE {} SET {} = '{}' WHERE {} = {}".format(table, name_field,
                                                       new_name, idx_col, idx)
    return s


to_update = [('SELECT * FROM injuries', 'injuries', 'player', 'id'),
             ('SELECT * FROM news', 'news', 'player', 'id'),
             ('SELECT * FROM playerstats WHERE season IN (2017, 2018)',
              'playerstats', 'player', 'id')]

all_queries = []
db = dfm.create_nba_dbwrapper()

# Build all queries.
for (sql, table, name_col, idx_col) in to_update:
    df = db.query_df(sql)
    df['new_name'] = df[name_col].apply(get_new_name)
    df = df[df['new_name'].notnull()]
    df['update_sql'] = df.apply(create_sql_name_update,
                                axis=1,
                                args=(idx_col, name_col, table))
    queries = df['update_sql'].tolist()
    all_queries = all_queries + queries

# Execute all queries.
db_update = udb.DBUpdate(db)
log_path = dfm.Folders.DFExperiments + 'update_names'
db_update.update(all_queries, log_path)