def getSummonerName(region): RIOTConstant = riotConstant.RIOTConstant() api_key = RIOTConstant.api_key tier_div = RIOTConstant.tier_div df_summonerName = pd.DataFrame() print("current region is : " + region + " ") for column in tier_div: tier = column.split('_')[0] division = column.split('_')[1] print("Searching for summoners in : " + tier + "_" + division, end=' \r') summonerName = getSummonerIdByTierAndDivision(region, tier, division, api_key) new_column = pd.DataFrame(data={column: summonerName}) df_summonerName = pd.concat([df_summonerName, new_column], axis=1) path = './data/' + region + 'summonerName.csv' df_summonerName.to_csv(path, index=False) return 0
def dataSort(language, region, championName, tier): # pd.options.mode.chained_assignment = None RIOTConstant = riotConstant.RIOTConstant() RIOTConstant.setLanguage(language) championId = RIOTConstant.getChampionId(championName) data = readData(language, region, championName, tier) # Changin the combination of spells in ascending order to check frequency print(data[['spell1Id', 'spell2Id']].head(5)) spell_combination = data[['spell1Id', 'spell2Id']] for i, spells in spell_combination.iterrows(): if (spells['spell1Id'] > spells['spell2Id']): data.loc[i, ['spell1Id', 'spell2Id']] = [ spells['spell2Id'], spells['spell1Id'] ] print(data[['spell1Id', 'spell2Id']].head(5)) print(data[['item0', 'item1', 'item2', 'item3', 'item4', 'item5', 'item6']].head(5)) item_combination = data[[ 'item0', 'item1', 'item2', 'item3', 'item4', 'item5', 'item6' ]] for i, items in item_combination.iterrows(): sorted_items = items.sort_values(ascending=False) data.loc[ i, ['item0', 'item1', 'item2', 'item3', 'item4', 'item5', 'item6' ]] = sorted_items.to_numpy() print(data[['item0', 'item1', 'item2', 'item3', 'item4', 'item5', 'item6']].head(5)) print(data[['perkPrimaryStyle', 'perk0', 'perk1', 'perk2', 'perk3']].head(5)) prime_run_combination = data[[ 'perkPrimaryStyle', 'perk0', 'perk1', 'perk2', 'perk3' ]] for i, prime_runes in prime_run_combination.iterrows(): sorted_prime_runes = prime_runes.sort_values(ascending=True) data.loc[i, ['perkPrimaryStyle', 'perk0', 'perk1', 'perk2', 'perk3' ]] = sorted_prime_runes.to_numpy() print(data[['perkPrimaryStyle', 'perk0', 'perk1', 'perk2', 'perk3']].head(5)) print(data[['perkSubStyle', 'perk4', 'perk5']].head(5)) sub_run_combination = data[['perkSubStyle', 'perk4', 'perk5']] for i, sub_runes in sub_run_combination.iterrows(): sorted_sub_runes = sub_runes.sort_values(ascending=True) data.loc[ i, ['perkSubStyle', 'perk4', 'perk5']] = sorted_sub_runes.to_numpy() print(data[['perkSubStyle', 'perk4', 'perk5']].head(5)) data.to_csv('./data/finalData/' + region + "/" + tier + "/champion_" + str(championId) + ".csv") return
def readData(language, region, championName, tier): RIOTConstant = riotConstant.RIOTConstant() RIOTConstant.setLanguage(language) championId = RIOTConstant.getChampionId(championName) data = pd.read_csv('./data/finalData/' + region + "/" + tier + "/champion_" + str(championId) + ".csv") return data
def getFinalData(region): RIOTConstant = riotConstant.RIOTConstant() api_key = RIOTConstant.api_key filepath = "./data/" + region + 'matchId.csv' df_matchId = pd.read_csv(filepath) for column in df_matchId.columns: tier = column.split('_')[0] matchId_list = df_matchId[column].dropna(axis=0) print("Trying to get match info from " + region + " server, " + column) for matchId in matchId_list: getMatchInfo(region, tier, int(matchId), api_key)
def getAccountId(region): RIOTConstant = riotConstant.RIOTConstant() api_key = RIOTConstant.api_key tier_div = RIOTConstant.tier_div df_accnt = pd.DataFrame(columns=[ 'IRON_I', 'IRON_II', 'IRON_III', 'IRON_IV', 'BRONZE_I', 'BRONZE_II', 'BRONZE_III', 'BRONZE_IV', 'SILVER_I', 'SILVER_II', 'SILVER_III', 'SILVER_IV', 'GOLD_I', 'GOLD_II', 'GOLD_III', 'GOLD_IV', 'PLATINUM_I', 'PLATINUM_II', 'PLATINUM_III', 'PLATINUM_IV', 'DIAMOND_I', 'DIAMOND_II', 'DIAMOND_III', 'DIAMOND_IV', 'MASTER_I', 'GRANDMASTER_I', 'CHALLENGER_I' ]) # Get the dataframe of summoner name file_path_orig = "./data/" + region + "summonerName.csv" df_smmnr = pd.read_csv(file_path_orig) # Prepare the output file file_path_dest = "./data/" + region + "accountId.csv" df_accnt = pd.DataFrame() print("Start gathering account id of " + region + " Server.") for column in tier_div: # Get the summoner names in each tier / division print("Getting " + column + " user account Id ") smmnr_name = df_smmnr[column].dropna(axis=0) # Get total number & counter for process status total = len(smmnr_name) count = 1 # Prepare list to store the account ID accountIdList = [] # Start iterating through summoner name for name in smmnr_name: accountId = getAccntId(region, name, api_key) print("Getting account id : " + str(count) + " out of " + str(total), end=' \r') accountIdList.append(accountId) count = count + 1 new_column = pd.DataFrame(data={column: accountIdList}) df_accnt = pd.concat([df_accnt, new_column], axis=1) df_accnt.to_csv(file_path_dest, index=False)
def getMatchId(region): RIOTConstant = riotConstant.RIOTConstant() api_key = RIOTConstant.api_key # Read account ID file per region file_path_accnt = './data/' + region + "accountId.csv" df_accntId = pd.read_csv(file_path_accnt) # Create a new dataframe to store match ID df_matchId = pd.DataFrame() # For each tier / division for column in df_accntId.columns: # Get the list of account ID, and create list to store match ID accntIdList = df_accntId[column].dropna(axis=0) matchIdList = [] # Create variable to track process of getting data total = len(accntIdList) count = 1 # For each account ID for accntId in accntIdList: # Get the match ID played by each account ID matchidListByPlayer = getMatchIdByPlayer(region, accntId, api_key) print("Collecting match history : " + str(count) + " out of " + str(total), end='\r') count = count + 1 # Add the match ID to the list matchIdList.extend(matchidListByPlayer) # Once iterate through all account ID in each tier / division, # check for duplicate, create a dataframe column and concatenate with previous dataframe matchIdList = list(dict.fromkeys(matchIdList)) new_column = pd.DataFrame(data={column: matchIdList}) df_matchId = pd.concat([df_matchId, new_column], axis=1) df_matchId.to_csv('./data/' + region + "matchId.csv", index=False)
def main(): RIOTConstant = riotConstant.RIOTConstant() region_id = RIOTConstant.regions # createDataFrame() for region in region_id: # Get Sumoner Names # summonerName.getSummonerName( region ) # Get Account ID for each summoner name # accountId.getAccountId( region ) # Get Match ID (ARAM) played by each account ID # matchId.getMatchId( region ) # Get Match Info and store it as final data matchInfo.getFinalData(region) return 0
def createDataFrame(): RIOTConstant = riotConstant.RIOTConstant() champs_id = RIOTConstant.getChampion().keys() region_id = RIOTConstant.regions tierDiv_list = [ 'IRON', 'BRONZE', 'SILVER', 'GOLD', 'PLATINUM', 'DIAMOND', 'MASTER', 'GRANDMASTER', 'CHALLENGER' ] df_column = [ 'win', 'spell1Id', 'spell2Id', 'perkPrimaryStyle', 'perk0', 'perk1', 'perk2', 'perk3', 'perkSubStyle', 'perk4', 'perk5', 'item0', 'item1', 'item2', 'item3', 'item4', 'item5', 'item6' ] df_matchInfo = pd.DataFrame(columns=[df_column]) for region in region_id: for tierDiv in tierDiv_list: for champ_id in champs_id: filepath = "./data/finalData/" + region + "/" + tierDiv + "/champion_" + champ_id + ".csv" df_matchInfo.to_csv(filepath, index=False)