def buildAllPlayerAverage(digits_to_round = 2): path = "../allPlayerAverage.csv" #taken from StatsGenerator (does not include non-numeric columns) columns = ["Name", "Margin", "Minutes", "FGA", "FGM", "3PA", "3PM", "Rebounds", "Assists", "Steals", "Blocks", "Turnovers", "Fouls", "Points"] playerNames = at.getPlayerNames() allPlayerAverage_dict = {} #feelin' loopy for name in playerNames: playerDataIndividual = {} for column in columns: if(column == "Name"): playerDataIndividual[column] = name else: average = at.getPlayerAverage(name, column, digits_to_round) playerDataIndividual[column] = average allPlayerAverage_dict[name] = playerDataIndividual with open(path, 'w', encoding='utf-8', newline='') as averageFile: averageFile.truncate(0) writer = csv.DictWriter(averageFile, fieldnames=columns) writer.writeheader() for name in playerNames: writer.writerow(allPlayerAverage_dict[name])
def plotSingleAxisTotal(Y, numNames=10, head=True, sizeX=10, sizeY=10, type_of_chart="bar"): dataframe = at.getAllPlayerTotalDataFrame().sort_values( Y, ascending=not head).head(numNames) dataframe.plot(x="Name", y=Y, figsize=(sizeX, sizeY), kind=type_of_chart)
def categoryToWin_PlayerCorrelation(playerName, C, N, over=True, win=True, basedOnWins=True): df = at.getPlayerDataFrame(playerName) totalPlayed = len(df) totalWins = len(df.loc[df['Margin'] > 0]) totalWins_withParams=categoryToWin_PlayerTotal(playerName, C, N, over=over, win=win) if(basedOnWins): return totalWins_withParams/totalWins else: return totalWins_withParams/totalPlayed
def categoryToWin_PlayerTotal(playerName, C, N, over=True, win=True): df = at.getPlayerDataFrame(playerName) #convoluted but the best way to do it - let's count! if(win): if(over): return len(df.loc[(df[C] > N) & (df['Margin'] > 0)]) else: return len(df.loc[(df[C] < N) & (df['Margin'] > 0)]) else: if(over): return len(df.loc[(df[C] > N) & (df['Margin'] < 0)]) else: return len(df.loc[(df[C] < N) & (df['Margin'] < 0)])
def replaceAllInPlayerData(subject, target): names = at.getPlayerNames() for name in names: path = "../player_data/" + name + ".csv" new_file_content = "" #read and create string with new file fin = open(path, "r+", encoding='utf8') for line in fin: stripped_line = line.strip() new_line = stripped_line.replace(subject, target).replace(" ", "") new_file_content += new_line + "\n" fin.close() #delete contents and write back fout = open(path, "w", encoding='utf8') fout.truncate(0) fout.write(new_file_content) fout.close()