def getCoachRating(team, year): df = pd.read_csv('./csv_Data/Coaching/1960-2019.csv', encoding = "ISO-8859-1") winPctDiff = [] teams = [] g = 0 fName = "Error" lName = "Error" for index, row in df.iterrows(): if (int(row["year"]) > year): break if (standardizeTeamName(row["school"],False) == team and year == int(row["year"])): if (int(row["games"]) > g): fName = row["first_name"] lName = row["last_name"] g = int(row["games"]) for index, row in df.iterrows(): if (int(row["year"]) == year): break if (fName == row["first_name"] and lName == row["last_name"]): if (standardizeTeamName(row["school"],False) not in teams): teams.append(standardizeTeamName(row["school"],False)) for a in teams: winPctHist = [] winPct = [] for index, row in df.iterrows(): if (int(row["year"]) == year): break if (standardizeTeamName(row["school"],False) == a and (fName != row["first_name"] or lName != row["last_name"])): winPctHist.append(int(row["wins"])/(int(row["losses"])+int(row["wins"]))) elif (standardizeTeamName(row["school"],False) == a and (fName == row["first_name"] and lName == row["last_name"])): winPct.append(int(row["wins"])/(int(row["losses"])+int(row["wins"]))) if (len(winPctHist) < 5): continue for bbb in winPct: winPctDiff.append(bbb - np.average(winPctHist)) if (len(winPctDiff) > 0): return (np.average(winPctDiff)) else: return 0
df = pd.read_csv('./new_csv_data/2021/StatsWeek1.csv', encoding = "ISO-8859-1") for w in range(2, weekMain): df = df.append(pd.read_csv('./new_csv_data/2021/StatsWeek' + str(w) + '.csv', encoding = "ISO-8859-1"), ignore_index=True) dropRows = [] for index, row in df.iterrows(): if (index > 0 and row["gameId"] == df.at[index-1,"gameId"]): dropRows.append(index) df = df.drop(dropRows) dict = {"Week":[],"Team":[],"Offense":{},"Defense":{}} subDictOff = {"Ppa":[],"Sr":[],"Exp":[],"PwrS":[],"Stuff":[],"SecLevel":[],"OpenField":[],"StDownPpa":[],"StDownSr":[],"StDownExp":[],"PassDownPpa":[],"PassDownSr":[],"PassDownExp":[],"RushPpa":[],"RushSr":[],"RushExp":[],"PassPpa":[],"PassSr":[],"PassExp":[]} subDictDef = {"Ppa":[],"Sr":[],"Exp":[],"PwrS":[],"Stuff":[],"SecLevel":[],"OpenField":[],"StDownPpa":[],"StDownSr":[],"StDownExp":[],"PassDownPpa":[],"PassDownSr":[],"PassDownExp":[],"RushPpa":[],"RushSr":[],"RushExp":[],"PassPpa":[],"PassSr":[],"PassExp":[]} for index, row in df.iterrows(): dict["Week"].append(row["week"]) dict["Team"].append(standardizeTeamName(row["team"], False)) dict["Week"].append(row["week"]) dict["Team"].append(standardizeTeamName(row["opponent"], False)) #Offense subDictOff["Ppa"].append(row["offense.ppa"]) subDictDef["Ppa"].append(row["defense.ppa"]) subDictOff["Ppa"].append(row["defense.ppa"]) subDictDef["Ppa"].append(row["offense.ppa"]) subDictOff["Sr"].append(row["offense.successRate"]) subDictDef["Sr"].append(row["defense.successRate"]) subDictOff["Sr"].append(row["defense.successRate"]) subDictDef["Sr"].append(row["offense.successRate"]) subDictOff["Exp"].append(row["offense.explosiveness"]) subDictDef["Exp"].append(row["defense.explosiveness"])
import pandas as pd import numpy as np import operator from cfbFcns import standardizeTeamName curElo = {} teamDf = pd.read_csv('./csv_Data/majorDivTeams.csv', encoding="ISO-8859-1") for index, row in teamDf.iterrows(): curElo[standardizeTeamName(row["school"], False)] = {"Elo": 1500, "G": 0} #Adding Idaho Manually since they are no longer FBS curElo["Idaho"] = {"Elo": 1500, "G": 0} #{Spread : Prob of Fav winning that spread} pDict = {} pChart = pd.read_csv('./csv_data/spreadProbChart.csv', encoding="ISO-8859-1") for index, row in pChart.iterrows(): pDict[float(row["spread"])] = float(row["fav win"].split("%")[0]) / 100 #k function is a complete gut call years = [] zzz = 1999 while (zzz <= 2019): years.append(zzz) zzz += 1 for year in years: print(year) incEloHome = [] incEloRoad = [] resEloHome = [] resEloRoad = [] eloLoss = 0 if (year >= 2002):
encoding="ISO-8859-1").drop(columns=["Unnamed: 0"]) for gamesIndex, gamesRow in games.iterrows(): if (gamesRow["Week"] == "Bowl" or int(gamesRow["Week"]) > week): break #Case that aggregates later weeks in season if (week == 999): if (int(gamesRow["Week"]) > 10): for col in games.columns: statsDict[col].append(gamesRow[col]) for statsIndex, statsRow in stats.iterrows(): if (statsRow["Week"] == "Year End" or int( statsRow["Week"]) > int(gamesRow["Week"])): break if (standardizeTeamName( gamesRow["Home Team"], False) == standardizeTeamName( statsRow["Team"], False)): if (not appendedHome): for col in stats.columns: if (col != "Week" and col != "Team"): statsDict["Home " + col].append( statsRow[col]) appendedHome = True else: for col in stats.columns: if (col != "Week" and col != "Team"): del statsDict["Home " + col][-1] statsDict["Home " + col].append( statsRow[col]) if (standardizeTeamName(
return sum(arr)/len(arr) return np.nan for year in years: df = pd.read_csv('./new_csv_data/advStatsGame/' + year + '.csv', encoding = "ISO-8859-1") dropRows = [] for index, row in df.iterrows(): if (index > 0 and row["gameId"] == df.at[index-1,"gameId"]): dropRows.append(index) df = df.drop(dropRows) dict = {"Week":[],"Team":[],"Offense":{},"Defense":{}} subDictOff = {"Ppa":[],"Sr":[],"Exp":[],"PwrS":[],"Stuff":[],"SecLevel":[],"OpenField":[],"StDownPpa":[],"StDownSr":[],"StDownExp":[],"PassDownPpa":[],"PassDownSr":[],"PassDownExp":[],"RushPpa":[],"RushSr":[],"RushExp":[],"PassPpa":[],"PassSr":[],"PassExp":[]} subDictDef = {"Ppa":[],"Sr":[],"Exp":[],"PwrS":[],"Stuff":[],"SecLevel":[],"OpenField":[],"StDownPpa":[],"StDownSr":[],"StDownExp":[],"PassDownPpa":[],"PassDownSr":[],"PassDownExp":[],"RushPpa":[],"RushSr":[],"RushExp":[],"PassPpa":[],"PassSr":[],"PassExp":[]} for index, row in df.iterrows(): dict["Week"].append(row["week"]) dict["Team"].append(standardizeTeamName(row["team"], False)) dict["Week"].append(row["week"]) dict["Team"].append(standardizeTeamName(row["opponent"], False)) #Offense subDictOff["Ppa"].append(row["offense.ppa"]) subDictDef["Ppa"].append(row["defense.ppa"]) subDictOff["Ppa"].append(row["defense.ppa"]) subDictDef["Ppa"].append(row["offense.ppa"]) subDictOff["Sr"].append(row["offense.successRate"]) subDictDef["Sr"].append(row["defense.successRate"]) subDictOff["Sr"].append(row["defense.successRate"]) subDictDef["Sr"].append(row["offense.successRate"]) subDictOff["Exp"].append(row["offense.explosiveness"]) subDictDef["Exp"].append(row["defense.explosiveness"])
ouNum = 0 spreadVol = 0 ouVol = 0 configuration = cfbd.Configuration() configuration.api_key[ 'Authorization'] = 'XBWTTfw3Jo8o/r/jmDnRA6SsnoHp0MKKPBEE0UGID/hPKqzKLV/+0Ljn06dCbQRS' configuration.api_key_prefix['Authorization'] = 'Bearer' api_instance = cfbd.GamesApi(cfbd.ApiClient(configuration)) year = 2021 api_response = api_instance.get_games(year=year, week=week, season_type="regular") for index, row in bets.iterrows(): for x in api_response: if (standardizeTeamName(x.home_team, False) == standardizeTeamName( row["Home Team"], False) and standardizeTeamName(x.away_team, False) == standardizeTeamName(row["Road Team"], False)): if (not pd.isnull(row["Spread Bet"])): spreadNum += 1 spreadVol += float(row["Spread Amt"]) if ('+' in row["Spread Bet"]): team = row["Spread Bet"].split(" +")[0] points = float(row["Spread Bet"].split(" +")[1]) if (team == standardizeTeamName(x.home_team, False)): if (float(x.home_points) + points > float( x.away_points)): spreadSum += float(row["Spread Amt"]) * ( float(row["Spread Odds"]) - 1) elif (float(x.home_points) + points < float(
Hadded = False Radded = False dict = {} for year in years: print(year) a = pd.read_csv('./csv_Data/advStatsSeason/' + str(year - 1) + '.csv', encoding="ISO-8859-1") for index, row in bigboy.iterrows(): Hadded = False Radded = False if (int(row["Year"]) > year): break elif (int(row["Year"]) < year): continue for i, r in a.iterrows(): if (row["HTeam"] == standardizeTeamName(r["team"], False)): Hadded = True for col in a.columns: if (col != "team" and col != "season" and col != "conference"): if ("offense" in col): letter = "o" else: letter = "d" if ("H" + letter + "_lastYear_" + col.split("ense.")[1] not in dict): dict["H" + letter + "_lastYear_" + col.split("ense.")[1]] = [] dict["H" + letter + "_lastYear_" + col.split("ense.")[1]].append(r[col]) elif (row["RTeam"] == standardizeTeamName(r["team"], False)):
import pandas as pd import numpy as np import operator from cfbFcns import standardizeTeamName import cfbd from cfbd.rest import ApiException curWeek = 5 curElo = {} teamDf = pd.read_csv('./csv_Data/majorDivTeams.csv', encoding = "ISO-8859-1") for index, row in teamDf.iterrows(): curElo[standardizeTeamName(row["school"],False)] = {"Elo":1500,"G":0} #Adding Idaho Manually since they are no longer FBS curElo["Idaho"] = {"Elo":1500,"G":0} #{Spread : Prob of Fav winning that spread} pDict = {} pChart = pd.read_csv('./csv_data/spreadProbChart.csv', encoding = "ISO-8859-1") for index, row in pChart.iterrows(): pDict[float(row["spread"])] = float(row["fav win"].split("%")[0])/100 #k function is a complete gut call years = [] zzz = 1999 while (zzz <= 2020): years.append(zzz) zzz += 1 for year in years: eloLoss = 0 if (year >= 2002 and year <= 2019): curYearDf = pd.read_csv('./csv_Data/BettingResults/' + str(year) + '.csv', encoding = "ISO-8859-1")
browser = webdriver.Chrome(executable_path='chromedriver.exe') browser.get("https://www.pinnacle.com/en/football/ncaa/matchups/#period:0") browser.maximize_window() time.sleep(5) for i in range(25): soup = BeautifulSoup(browser.page_source, 'html.parser') main = soup.find(class_="contentBlock square") games = main.find_all(class_="style_row__3q4g_ style_row__3hCMX") for game in games: dict["Week"].append(week) dict["Neutral Field"].append(0) dict["Home Team"].append( standardizeTeamName( game.find_all( class_= "ellipsis event-row-participant style_participant__H8-ku") [1].text, True)) dict["Road Team"].append( standardizeTeamName( game.find_all( class_= "ellipsis event-row-participant style_participant__H8-ku") [0].text, True)) spread = game.find(class_="style_buttons__XEQem") try: if (float(spread.find(class_="style_label__2KJur").text) < 0): dict["Favorite"].append( standardizeTeamName( game.find_all( class_=
"Neutral Field": [], "Night Game": [], "Postseason Game": [], "Favorite": [], "Spread": [], "O/U": [], "Home Score": [], "Road Score": [], "Spread Winner": [], "O/U Outcome": [] } idsUsed = [] for index, row in bets.iterrows(): if (row["id"] not in idsUsed): dict["Home Team"].append(standardizeTeamName((row["homeTeam"]), False)) dict["Road Team"].append(standardizeTeamName((row["awayTeam"]), False)) dict["Home Score"].append(row["homeScore"]) dict["Road Score"].append(row["awayScore"]) k = 0 curGame = row["id"] consensusFound = False while (k + index < len(bets.index) and bets.iat[k + index, 0] == curGame): if (bets.iat[k + index, 5] == "consensus"): consensusFound = True dict["O/U"].append(bets.iat[k + index, 6]) if (int(bets.iat[k + index, 2]) + int(bets.iat[k + index, 4]) > float(bets.iat[k + index, 6])): dict["O/U Outcome"].append("Over") elif (int(bets.iat[k + index, 2]) +
import CFBScrapy as cfb from cfbFcns import standardizeTeamName import pandas thisYear = 2015 t = cfb.get_team_talent(year=thisYear) t = t.drop(columns=["year"]) pwrRate = [] for i in range(len(t.index)): pwrRate.append(float(t.at[i,"talent"])/float(t.at[0,"talent"])) t["pwrRating"] = pwrRate dropRows = [] for i in range(len(t.index)): if (len(standardizeTeamName(t.at[i,"school"]).split("Error")) > 1): dropRows.append(i) else: t.at[i,"school"] = standardizeTeamName(t.at[i,"school"]) t = t.drop(dropRows) dropRows = [] a = pandas.read_csv("./csv_Data/AdvancedStatsSeason/2014.csv", encoding = "ISO-8859-1") for i in range(len(a.index)): if (len(standardizeTeamName(a.at[i,"team"]).split("Error")) > 1): dropRows.append(i) else: a.at[i,"team"] = standardizeTeamName(a.at[i,"team"]) a = a.drop(dropRows) print (t) print (a) for i in range(len(t.index)): for j in range(len(a.index)): if (t.at[i,"school"] == )
for year in years: dict[str(year)] = {} for w in weeks: try: a = pd.read_csv('./csv_Data/teamGameStats/' + str(year) + '_' + str(w) + '.csv', encoding="ISO-8859-1") except FileNotFoundError: continue print(year, w) if (path.exists('./csv_Data/teamGameStats/' + str(year) + '_' + str(w) + '.csv')): for index, row in a.iterrows(): #print (row, index) if (standardizeTeamName(row["school"], False) not in dict[str(year)]): dict[str(year)][standardizeTeamName(row["school"], False)] = {} if ("Week " + str(w) not in dict[str(year)][standardizeTeamName( row["school"], False)]): dict[str(year)][standardizeTeamName( row["school"], False)]["Week " + str(w)] = { "Points For": 0, "Points Against": 0, "Completions": 0, "Attempts": 0, "Opponent Completions": 0, "Opponent Attempts": 0, "TOP": 0,
0].split("-6ot")[0].split("-7ot")[0] else: teamString = teamString + " " + row[k].split( "-ot")[0].split("-OT")[0].split("#")[0].split( "-2ot")[0].split("-3ot")[0].split( "-4ot")[0].split("-5ot")[0].split( "-6ot")[0].split("-7ot")[0] k = k + 1 if (k == len(row)): getOut = True break if (getOut): j += 1 continue if (len( standardizeTeamName(teamString, True).split("Error: ")) > 1): print(standardizeTeamName(teamString, True)) if (len( standardizeTeamName( lines[i - 1].split(" (AT)")[0].split(" (P.A.T.)") [0].split(" (FT)")[0].split("\n")[0], True).split("Error: ")) > 1): print( standardizeTeamName( lines[i - 1].split(" (AT)")[0].split(" (P.A.T.)") [0].split(" (FT)")[0].split("\n")[0], True)) if (len(row[0].split("*")) == 2): NG = True else:
from cfbFcns import standardizeTeamName import pandas as pd print(standardizeTeamName("San José State", True)) str = "San José State" print(str.lower()) stats = pd.read_csv('./csv_Data/advStatsFwdLooking/2016.csv', encoding="ISO-8859-1").drop(columns=["Unnamed: 0"]) print(stats.iat[70, 1].lower())
bigboy = pd.read_csv('./new_csv_Data/bigboy.csv', encoding="ISO-8859-1") Fresh = [] Soph = [] Jun = [] Sen = [] added = False for index, row in bigboy.iterrows(): print(index) df = pd.read_csv('./csv_Data/Recruiting/' + str(row["Year"]) + '.csv', encoding="ISO-8859-1") added = False for indexx, roww in df.iterrows(): if (row["Team"] == standardizeTeamName(roww["team"], False)): Fresh.append(float(roww["points"])) added = True break if (not added): Fresh.append(0) df = pd.read_csv('./csv_Data/Recruiting/' + str(int(row["Year"]) - 1) + '.csv', encoding="ISO-8859-1") added = False for indexx, roww in df.iterrows(): if (row["Team"] == standardizeTeamName(roww["team"], False)): Soph.append(float(roww["points"])) added = True break if (not added):