def insert_pick(cursor, gameData): """ insert_pick formats collected gameData from query_wiki() and inserts it into the pick table of the competitiveGameData.db. Args: cursor (sqlite cursor): cursor used to execute commmands gameData (list(dict)): list of formatted game data from query_wiki() Returns: status (int): status = 1 if insert was successful, otherwise status = 0 """ status = 0 assert isinstance(gameData, list), "gameData is not a list" teams = ["blue", "red"] for game in gameData: tournament = get_tournament_data(game) vals = (tournament, game["tourn_game_id"]) gameId = get_game_id(cursor, game) # Check for existing entries in table. Skip if they already exist. cursor.execute("SELECT game_id FROM pick WHERE game_id=?", (gameId, )) result = cursor.fetchone() if result is not None: print( "Picks for game {} already exists in table.. skipping".format( result[0])) else: for k in range(len(teams)): picks = game["picks"][teams[k]] selectionOrder = 0 side = k for (pick, position) in picks: if pick in ["lossofpick", "none"]: # Special case if no pick was submitted to game (not really sure what that would mean # but being consistent with insert_pick()) pickId = None else: pickId = champion_id_from_name(pick) # If no such champion name is found, try looking for an alias if pickId is None: pickId = champion_id_from_name( convert_champion_alias(pick)) selectionOrder += 1 vals = (gameId, pickId, position, selectionOrder, side) cursor.execute( "INSERT INTO pick(game_id, champion_id, position_id, selection_order, side_id) VALUES(?,?,?,?,?)", vals) status = 1 return status
def insert_ban(cursor, gameData): """ insert_ban attempts to format collected gameData from query_wiki() and insert into the ban table in the competitiveGameData.db. Args: cursor (sqlite cursor): cursor used to execute commmands gameData (list(dict)): dictionary output from query_wiki() Returns: status (int): status = 1 if insert was successful, otherwise status = 0 """ status = 0 assert isinstance(gameData, list), "gameData is not a list" teams = ["blue", "red"] for game in gameData: tournament = get_tournament_data(game) vals = (tournament, game["tourn_game_id"]) gameId = get_game_id(cursor, game) # Check for existing entries in table. Skip if they already exist. cursor.execute("SELECT game_id FROM ban WHERE game_id=?", (gameId, )) result = cursor.fetchone() if result is not None: print("Bans for game {} already exists in table.. skipping".format( result[0])) else: for k in range(len(teams)): bans = game["bans"][teams[k]] selectionOrder = 0 side = k for ban in bans: if ban in ["lossofban", "none"]: # Special case if no ban was submitted in game banId = None else: # print("ban={}".format(ban)) banId = champion_id_from_name(ban) # If no such champion name is found, try looking for an alias if banId is None: banId = champion_id_from_name( convert_champion_alias(ban)) selectionOrder += 1 vals = (gameId, banId, selectionOrder, side) cursor.execute( "INSERT INTO ban(game_id, champion_id, selection_order, side_id) VALUES(?,?,?,?)", vals) status = 1 return status
def clean_champion_names(names): """ Takes a list of champion names and standarizes them by looking for possible aliases if necessary. Args: names (list(string)): list of champion names to be standardized Returns: cleanedNames (list(string)): list of standardized champion names """ cleanedNames = [] for name in names: if champion_id_from_name(name) is None: name = convert_champion_alias(name) cleanedNames.append(name) return cleanedNames