Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from timeit import default_timer as timer
- import csv
- totalstart = timer()
- finalscores = []
- matchcount = 1
- gamesinweek = 0
- correctcount = 0
- totalpenaltyyards = 0
- season = '2019'
- weekstart = 1
- weekend = 1
- gamesplayed = 100000
- totalcorrectcount = 0
- totalgamesinweek = 0
- f = open("outcomes.csv", "w")
- f.truncate()
- f.close()
- def header():
- global start
- start = timer()
- with open('outcomes.csv', 'a', newline='') as csvFile:
- writer = csv.writer(csvFile)
- writer.writerow(['Winning Team', 'Win Percent','Correct', 'Home Team', 'Away Team', 'Home Team Avg Score', 'Away Team Avg Score', 'Home Team Win Count', 'Away Team Win Count'])
- def statsreset():
- global gamestats
- global gamesplayed
- global offset
- global totalstats
- global totalscores
- global atstats
- global htstats
- offset = (gamesplayed / 100)
- scores = {hometeam:0, awayteam:0}
- totalscores = {hometeam:0, awayteam:0}
- totalstats = {'totalrunplays':0, 'totalpassplays':0, 'totalpuntplays':0, 'totalfieldgoalplays':0, 'totalrushyards':0, 'totalpassyards':0, 'totalpuntyards':0, 'totalcompletions':0, 'cointosswinner '+str(hometeam):0, 'cointosswinner '+str(awayteam):0}
- htstats = {'totalrunplays':0, 'totalpassplays':0, 'totalpuntplays':0, 'totalfieldgoalplays':0, 'totalrushyards':0, 'totalpassyards':0, 'totalpuntyards':0, 'totalcompletions':0, 'cointosswinner '+str(hometeam):0}
- atstats = {'totalrunplays':0, 'totalpassplays':0, 'totalpuntplays':0, 'totalfieldgoalplays':0, 'totalrushyards':0, 'totalpassyards':0, 'totalpuntyards':0, 'totalcompletions':0, 'cointosswinner '+str(awayteam):0}
- gamestats = {'games':0, 'gametime':60, 'possession':None, 'halftimepossession':0, 'ballposition':0, 'down':0, 'seriesyards':0, 'htwincount':0, 'atwincount':0}
- def teamstats():
- global htoffense
- global atoffense
- global htdefense
- global atdefense
- global htKicking_Punting
- global atKicking_Punting
- global htreturning
- global atreturning
- global gamesinweek
- with open('offense.csv', newline='') as csvfile:
- offenses = csv.DictReader(csvfile)
- for row in offenses:
- if row['Tm'] == hometeam:
- htoffense = row
- if row['Tm'] == awayteam:
- atoffense = row
- with open('defense.csv', newline='') as csvfile:
- defenses = csv.DictReader(csvfile)
- for row in defenses:
- if row['Tm'] == hometeam:
- htdefense = row
- if row['Tm'] == awayteam:
- atdefense = row
- with open('Kicking_Punting.csv', newline='') as csvfile:
- Kicking_Punting = csv.DictReader(csvfile)
- for row in Kicking_Punting:
- if row['Tm'] == hometeam:
- htKicking_Punting = row
- if row['Tm'] == awayteam:
- atKicking_Punting = row
- with open('returning.csv', newline='') as csvfile:
- returning = csv.DictReader(csvfile)
- for row in returning:
- if row['Tm'] == hometeam:
- htreturning = row
- if row['Tm'] == awayteam:
- atreturning = row
- def cointoss():
- global gamestats
- global scores
- #print('cointoss')
- gamestats['gametime'] = 60
- scores = {hometeam:0, awayteam:0}
- cointossresult = random.randint(0, 2)
- if cointossresult == 1:
- gamestats['possession'] = hometeam
- gamestats['halftimepossession'] = awayteam
- totalstats['cointosswinner '+str(awayteam)] += 1
- atstats['cointosswinner '+str(awayteam)] += 1
- else:
- gamestats['possession'] = awayteam
- gamestats['halftimepossession'] = hometeam
- totalstats['cointosswinner '+str(hometeam)] += 1
- htstats['cointosswinner '+str(hometeam)] += 1
- #print(gamestats['halftimepossession'], ' chooses to defer, ', gamestats['possession'], 'will receieve')
- def halftime():
- global gamestats
- global scores
- #print('Halftime!')
- if gamestats['ballposition'] >= 4000:
- fieldgoalplayexecute()
- gamestats['possession'] = gamestats['halftimepossession']
- #print(gamestats['halftimepossession'], ' chooses to defer and will receieve')
- kickoff()
- def endgame():
- global gamestats
- global scores
- if gamestats['ballposition'] >= 4000:
- #print('Final play of the game!')
- fieldgoalplayexecute()
- gamestats['possession'] = gamestats['halftimepossession']
- def kickoff():
- global gamestats
- gamestats['ballposition'] = 0
- returnteam = gamestats['possession']
- kickofftd = random.randint(0, 100)
- gamestats['gametime'] -= random.uniform(.2, .6)
- if kickofftd <= 1:
- scores[returnteam] += 6
- #print('Kickoff td!')
- turnover()
- extrapointexecute()
- kickoff()
- else:
- if gamestats['possession'] == hometeam:
- gamestats['ballposition'] = float(htreturning['Kick Returns Y/Rt']) * 95
- if gamestats['possession'] == awayteam:
- gamestats['ballposition'] = float(atreturning['Kick Returns Y/Rt']) * 95
- gamestats['down'] = 1
- kickoffbigplay = random.randint(0, 100)
- if kickoffbigplay <= 5:
- gamestats['ballposition'] += random.randint(1000, 2500)
- #print('Kickoff returned to ', int((gamestats['ballposition'] / 100)))
- def chooseplay():
- global gamestats
- global playchoice
- offense = gamestats['possession']
- if gamestats['possession'] == hometeam:
- if gamestats['down'] < 4:
- playodds = random.randint(1, 100)
- #print('playodds', playodds, 'play num', int((100 * (int(htoffense['Rushing Att']) / int(htoffense['Tot Ply'])))))
- if playodds >= (int((100 * (int(htoffense['Rushing Att']) / int(htoffense['Tot Ply']))))):
- playchoice = 'passplay'
- else:
- playchoice = 'runplay'
- else:
- if gamestats['ballposition'] > 5300:
- playchoice = 'fieldgoalplay'
- else:
- playchoice = 'puntplay'
- if gamestats['possession'] == awayteam:
- if gamestats['down'] < 4:
- playodds = random.randint(1, 100)
- if playodds >= (int((100 * (int(atoffense['Rushing Att']) / int(atoffense['Tot Ply']))))):
- playchoice = 'passplay'
- else:
- playchoice = 'runplay'
- else:
- if gamestats['ballposition'] > 5300:
- playchoice = 'fieldgoalplay'
- else:
- playchoice = 'puntplay'
- def passplayexecute():
- global gamestats
- global totalstats
- global htstats
- global atstats
- totalstats['totalpassplays'] += 1
- completionchace = random.randint(1,100)
- if gamestats['possession'] == hometeam:
- htstats['totalpassplays'] += 1
- if completionchace <= int(100 * (((int(htoffense['Passing Cmp']) / int(htoffense['Passing Att'])) + (int(atdefense['Passing Cmp']) / int(atdefense['Passing Att']))) / 2)):
- passcomplete = 'complete'
- else:
- passcomplete = 'incomplete'
- if gamestats['possession'] == awayteam:
- atstats['totalpassplays'] += 1
- if completionchace <= int(100 * (((int(atoffense['Passing Cmp']) / int(atoffense['Passing Att'])) + (int(htdefense['Passing Cmp']) / int(htdefense['Passing Att']))) / 2)):
- passcomplete = 'complete'
- else:
- passcomplete = 'incomplete'
- if passcomplete == 'complete':
- totalstats['totalcompletions'] += 1
- gamestats['down'] += 1
- if gamestats['possession'] == hometeam:
- htstats['totalcompletions'] += 1
- passmod = (100 * ((int(htoffense['Passing Yds']) / int(htoffense['Passing Cmp'])) + (int(atdefense['Passing Yds']) / int(atdefense['Passing Cmp']))) / 2)
- passyards = passmod + random.uniform(-(passmod + 200), passmod + 200)
- htstats['totalpassyards'] += passyards
- if gamestats['possession'] == awayteam:
- atstats['totalcompletions'] += 1
- passmod = (100 * ((int(atoffense['Passing Yds']) / int(atoffense['Passing Cmp'])) + (int(htdefense['Passing Yds']) / int(htdefense['Passing Cmp']))) / 2)
- passyards = passmod + random.uniform(-(passmod + 200), passmod + 200)
- atstats['totalpassyards'] += passyards
- totalstats['totalpassyards'] += passyards
- gamestats['ballposition'] += passyards
- gamestats['seriesyards'] += passyards
- #print('Pass complete for', round((passyards / 100), 1), ' yards. Ball is at', int((gamestats['ballposition'] / 100)), 'Down is ', gamestats['down'])
- if gamestats['ballposition'] >= 10000:
- scores[gamestats['possession']] += 6
- #print("Passing TD", scores)
- extrapointexecute()
- touchdown = 'yes'
- turnover()
- kickoff()
- if gamestats['seriesyards'] >= 1000:
- gamestats['down'] = 1
- gamestats['seriesyards'] = 0
- #print('First Down')
- if passcomplete == 'incomplete':
- gamestats['down'] += 1
- #print('Pass incomeplete, down ', gamestats['down'])
- def runplayexecute():
- global gamestats
- global totalstats
- global htstats
- global atstats
- totalstats['totalrunplays'] += 1
- if gamestats['possession'] == hometeam:
- nonpossession = awayteam
- htstats['totalrunplays'] += 1
- runmod = ((100 * float(htoffense['Rushing YPC'])) + (100 * float(atdefense['Rushing YPC']))) / 2
- runresult = runmod + random.uniform(-(runmod + 300), (runmod + 300))
- htstats['totalrushyards'] += runresult
- if gamestats['possession'] == awayteam:
- nonpossession = hometeam
- atstats['totalrunplays'] += 1
- runmod = ((100 * float(htoffense['Rushing YPC'])) + (100 * float(atdefense['Rushing YPC']))) / 2
- runresult = runmod + random.uniform(-(runmod + 300), (runmod + 300))
- atstats['totalrushyards'] += runresult
- gamestats['down'] += 1
- gamestats['ballposition'] += runresult
- gamestats['seriesyards'] += runresult
- atstats['totalrushyards'] += 1
- #print('Rush for', round((runresult / 100), 1), ' yards. Ball is at', int((gamestats['ballposition'] / 100)), 'Down is ', gamestats['down'])
- if gamestats['ballposition'] >= 10000:
- scores[gamestats['possession']] += 6
- extrapointexecute()
- turnover()
- kickoff()
- if gamestats['seriesyards'] >= 1000:
- gamestats['down'] = 1
- gamestats['seriesyards'] = 0
- #print('First Down!')
- totalstats['totalrushyards'] += runresult
- if gamestats['ballposition'] <= 0:
- scores[nonpossession] += 2
- #print("Safety", scores)
- puntplayexecute()
- def puntplayexecute():
- global gamestats
- puntteam = gamestats['possession']
- if puntteam == hometeam:
- returnteam = awayteam
- else: returnteam = hometeam
- punttd = random.randint(0, 1000)
- if punttd <= 8:
- scores[returnteam] += 6
- #print('Punt TD')
- turnover()
- extrapointexecute()
- kickoff()
- else:
- if puntteam == hometeam:
- #print(gamestats['ballposition'], 'Starting position')
- gamestats['ballposition'] += ((float(htKicking_Punting['Punting Y/P']) * 100) /3) + random.uniform(-((float(htKicking_Punting['Punting Y/P']) * 100) /2), (float(htKicking_Punting['Punting Y/P']) * 100))
- #print(gamestats['ballposition'], 'punt')
- if gamestats['ballposition'] >= 10000:
- gamestats['ballposition'] = 8000
- else:
- gamestats['ballposition'] -= (float(atreturning['Punt Returns Y/R']) + random.uniform(-(float(atreturning['Punt Returns Y/R'])), float(atreturning['Punt Returns Y/R'])) * 100)
- #print(gamestats['ballposition'], 'return')
- if puntteam == awayteam:
- #print(gamestats['ballposition'], 'starting')
- gamestats['ballposition'] += ((float(atKicking_Punting['Punting Y/P']) * 100) /2) + random.uniform(-((float(atKicking_Punting['Punting Y/P']) * 100) /2), (float(atKicking_Punting['Punting Y/P']) * 100))
- #print(gamestats['ballposition'], 'punt')
- if gamestats['ballposition'] >= 10000:
- gamestats['ballposition'] = 8000
- else:
- gamestats['ballposition'] -= (float(htreturning['Punt Returns Y/R']) + random.uniform(-(float(htreturning['Punt Returns Y/R'])), float(htreturning['Punt Returns Y/R'])) * 100)
- #print(gamestats['ballposition'], 'return')
- #print(gamestats['ballposition'], 'before turnover')
- turnover()
- #print(gamestats['ballposition'], 'final position')
- gamestats['down'] = 1
- def fieldgoalplayexecute():
- global scores
- global totalfieldgoalplays
- global gamestats
- gamestats['ballposition'] = int(gamestats['ballposition'])
- totalstats['totalfieldgoalplays'] += 1
- if 4000 <= gamestats['ballposition'] <= 4999:
- if gamestats['possession'] == hometeam:
- fgmod = ((float(htKicking_Punting['50 FGM']) / float(htKicking_Punting['50 FGA'])) * 100)
- if gamestats['possession'] == awayteam:
- fgmod = ((float(htKicking_Punting['50 FGM']) / float(htKicking_Punting['50 FGA'])) * 100)
- if 5000 <= gamestats['ballposition'] <= 5999:
- if gamestats['possession'] == hometeam:
- fgmod = ((float(htKicking_Punting['40-49 FGM']) / float(htKicking_Punting['40-49 FGA'])) * 100)
- if gamestats['possession'] == awayteam:
- fgmod = ((float(htKicking_Punting['40-49 FGM']) / float(htKicking_Punting['40-49 FGA'])) * 100)
- if 6000 <= gamestats['ballposition'] <= 6999:
- if gamestats['possession'] == hometeam:
- fgmod =((float(htKicking_Punting['30-39 FGM']) / float(htKicking_Punting['30-39 FGA'])) * 100)
- if gamestats['possession'] == awayteam:
- fgmod = ((float(htKicking_Punting['30-39 FGM']) / float(htKicking_Punting['30-39 FGA'])) * 100)
- if 7000 <= gamestats['ballposition'] <= 7999:
- if gamestats['possession'] == hometeam:
- fgmod = (float(htKicking_Punting['20-29 FGM']) / float(htKicking_Punting['20-29 FGA'])) * 100
- if gamestats['possession'] == awayteam:
- fgmod = (float(htKicking_Punting['20-29 FGM']) / float(htKicking_Punting['20-29 FGA'])) * 100
- if gamestats['ballposition'] >= 8000:
- fgmod = 99
- fgchance = random.randint(0, 100)
- if fgchance <= fgmod:
- scores[gamestats['possession']] += 3
- turnover()
- kickoff()
- else:
- turnover()
- def extrapointexecute():
- global scores
- if gamestats['possession'] == hometeam:
- xpmod = float(htKicking_Punting['Scoring XP%'])
- if gamestats['possession'] == awayteam:
- xpmod = float(atKicking_Punting['Scoring XP%'])
- xpchance = random.randint(0, 100)
- #print('xp', xpmod, xpchance)
- if xpchance <= xpmod:
- scores[gamestats['possession']] += 1
- def interceptioncheck():
- global gamestats
- global hometeam
- global awayteam
- global playchoice
- interceptionchance = random.randint(0, 100)
- if gamestats['possession'] == hometeam:
- interceptionodds = (((float(htoffense['Int']) / float(htoffense['Passing Att'])) + (float(atdefense['Passing Int']) / float(atdefense['Passing Att'])) / 2) * 100)
- nonpossession = awayteam
- if gamestats['possession'] == awayteam:
- interceptionodds = (((float(atoffense['Int']) / float(atoffense['Passing Att'])) + (float(htdefense['Passing Int']) / float(htdefense['Passing Att'])) / 2) * 100)
- nonpossession = hometeam
- if interceptionodds >= interceptionchance:
- playchoice = 'interception happened'
- pick6chance = random.randint(0, 100)
- if pick6chance >= 99:
- scores[nonpossession] += 6
- turnover()
- extrapointexecute()
- turnover()
- kickoff()
- else:
- turnover()
- def fumblecheck():
- global gamestats
- global hometeam
- global awayteam
- global playchoice
- fumblechance = random.randint(0, 100)
- if gamestats['possession'] == hometeam:
- fumbleodds = (((float(htoffense['FL']) / float(htoffense['Rushing Att'])) + (float(atdefense['FL']) / float(atdefense['Rushing Att'])) / 2) * 100)
- nonpossession = awayteam
- if gamestats['possession'] == awayteam:
- fumbleodds = (((float(atoffense['FL']) / float(atoffense['Rushing Att'])) + (float(htdefense['FL']) / float(htdefense['Rushing Att'])) / 2) * 100)
- nonpossession = hometeam
- if fumbleodds >= fumblechance:
- playchoice = 'fumble happened'
- fumble6chance = random.randint(0, 100)
- if fumble6chance >= 99:
- scores[nonpossession] += 6
- turnover()
- extrapointexecute()
- kickoff()
- else:
- turnover()
- def penaltycheck():
- global gamestats
- global totalpenaltyyards
- global scores
- global playchoice
- offensepenaltychance = random.randint(0, 100)
- defensepenaltychance = random.randint(0, 100)
- if gamestats['possession'] == hometeam:
- offensepenaltyodds = ((float(htoffense['Pen Ct']) / float(htoffense['Tot Ply'])) * 100)
- offensepenaltyyards = ((float(htoffense['Pen Yds']) / float(htoffense['Pen Ct'])) * 100)
- defensepenaltyodds = ((float(atdefense['Pen Ct']) / float(atdefense['Ply'])) * 100)
- defensepenaltyyards = ((float(atdefense['Pen Yds']) / float(atdefense['Pen Ct'])) * 100)
- if offensepenaltychance <= offensepenaltyodds:
- gamestats['gametime'] += random.uniform(.2, .6)
- gamestats['ballposition'] -= offensepenaltyyards
- gamestats['seriesyards'] -= offensepenaltyyards
- totalpenaltyyards += offensepenaltyyards
- playchoice = 'penaltyhappened'
- if defensepenaltychance <= defensepenaltyodds:
- gamestats['gametime'] += random.uniform(.2, .6)
- gamestats['ballposition'] += offensepenaltyyards
- gamestats['seriesyards'] += offensepenaltyyards
- totalpenaltyyards += offensepenaltyyards
- playchoice = 'penaltyhappened'
- if gamestats['possession'] == awayteam:
- offensepenaltyodds = ((float(atoffense['Pen Ct']) / float(atoffense['Tot Ply'])) * 100)
- offensepenaltyyards = ((float(atoffense['Pen Yds']) / float(atoffense['Pen Ct'])) * 100)
- defensepenaltyodds = ((float(htdefense['Pen Ct']) / float(htdefense['Ply'])) * 100)
- defensepenaltyyards = ((float(htdefense['Pen Yds']) / float(htdefense['Pen Ct'])) * 100)
- if offensepenaltychance <= offensepenaltyodds:
- gamestats['gametime'] += random.uniform(.2, .6)
- gamestats['ballposition'] -= offensepenaltyyards
- gamestats['seriesyards'] -= offensepenaltyyards
- totalpenaltyyards += offensepenaltyyards
- playchoice = 'penaltyhappened'
- if defensepenaltychance <= defensepenaltyodds:
- gamestats['gametime'] += random.uniform(.2, .6)
- gamestats['ballposition'] += offensepenaltyyards
- gamestats['seriesyards'] += offensepenaltyyards
- totalpenaltyyards += offensepenaltyyards
- playchoice = 'penaltyhappened'
- if gamestats['seriesyards'] >= 1000:
- gamestats['down'] = 1
- gamestats['seriesyards'] = 0
- def sackcheck():
- global playchoice
- global gamestats
- global scores
- sackchance = random.randint(0, 100)
- if gamestats['possession'] == hometeam:
- nonpossession = awayteam
- sackodds = ((((float(htoffense['Sk']) / float(htoffense['Passing Att'])) * 100) + ((float(atdefense['Sk']) / float(atdefense['Passing Att'])) * 100)) / 2)
- sackyards = ((((float(htoffense['Sk Yds']) / float(htoffense['Sk'])) * 100) + ((float(atdefense['Sk Yds']) / float(atdefense['Sk'])) * 100)) / 2)
- if gamestats['possession'] == awayteam:
- nonpossession = hometeam
- sackodds = ((((float(atoffense['Sk']) / float(atoffense['Passing Att'])) * 100) + ((float(htdefense['Sk']) / float(htdefense['Passing Att'])) * 100)) / 2)
- sackyards = ((((float(atoffense['Sk Yds']) / float(atoffense['Sk'])) * 100) + ((float(htdefense['Sk Yds']) / float(htdefense['Sk'])) * 100)) / 2)
- if sackchance <= sackodds:
- playchoice = 'sackhappened'
- gamestats['ballposition'] -= sackyards
- gamestats['seriesyards'] -= sackyards
- gamestats['down'] += 1
- if gamestats['ballposition'] <= 0:
- scores[nonpossession] += 2
- puntplayexecute()
- def turnover():
- global gamestats
- gamestats['down'] = 1
- gamestats['ballposition'] = abs(gamestats['ballposition'] - 10000)
- if gamestats['possession'] == hometeam:
- gamestats['possession'] = awayteam
- else:
- gamestats['possession'] = hometeam
- gamestats['seriesyards'] = 0
- def executeplay():
- global playchoice
- global gamestats
- gamestats['gametime'] -= random.uniform(.2, .6)
- #print('The ball is at the ', int((gamestats['ballposition'] / 100)), 'Time remaining is ', round(gamestats['gametime'], 2))
- #print(gamestats['possession'], ' Playchoice is', playchoice)
- penaltycheck()
- if playchoice == 'runplay':
- fumblecheck()
- if playchoice == 'runplay':
- runplayexecute()
- if playchoice == 'passplay':
- sackcheck()
- if playchoice == 'passplay':
- interceptioncheck()
- if playchoice == 'passplay':
- passplayexecute()
- if playchoice == 'fieldgoalplay':
- fieldgoalplayexecute()
- if playchoice == 'puntplay':
- puntplayexecute()
- def game():
- cointoss()
- kickoff()
- while gamestats['gametime'] >= 30:
- chooseplay()
- executeplay()
- halftime()
- while gamestats['gametime'] >= 0:
- chooseplay()
- executeplay()
- endgame()
- global wins
- winner = max(scores.keys(), key=(lambda k: scores[k]))
- if winner == hometeam:
- gamestats['htwincount'] += 1
- if winner == awayteam:
- gamestats['atwincount'] += 1
- global totalscores
- totalscores[hometeam] += scores[hometeam]
- totalscores[awayteam] += scores[awayteam]
- def printstats():
- global totalpassplays
- global totalpassyards
- global totalcompletions
- global end
- global start
- global gamesplayed
- global finalscores
- global matchcount
- global totalscores
- global gamestats
- global realwinner
- global correctcount
- global gamesinweek
- global percentcorrect
- #print('Total Scores: ', totalscores)
- #print('Total Yards per attempt: ', (totalstats['totalpassyards'] / totalstats['totalpassplays']) / 100)
- #print('Total Average yards per completion', (totalstats['totalpassyards'] / totalstats['totalcompletions']) / 100)
- #print('Total per Carry: ', (totalstats['totalrushyards'] / totalstats['totalrunplays']) / 100)
- #print('Total yards per punt: ', (totalstats['totalpuntyards'] / totalstats['totalpuntplays']) / 100)
- htstats['comp percent'] = 100 * (htstats['totalcompletions'] / htstats['totalpassplays'])
- htstats['YP COMP'] = (htstats['totalpassyards'] / htstats['totalcompletions']) / 100
- htstats['YP Carry'] = (htstats['totalrushyards'] / htstats['totalrunplays']) / 100
- atstats['comp percent'] = 100 * (atstats['totalcompletions'] / atstats['totalpassplays'])
- atstats['YP COMP'] = (atstats['totalpassyards'] / atstats['totalcompletions']) / 100
- atstats['YP Carry'] = (atstats['totalrushyards'] / atstats['totalrunplays']) / 100
- #print(hometeam, htstats)
- #print(awayteam, atstats)
- ###print(hometeam,'completion %: ', htstats['comp percent'],' Yards Per completion: ', htstats['YP COMP'],'Yards Per Carry: ', htstats['YP Carry'] )
- ###print(awayteam,'completion %: ', atstats['comp percent'],' Yards Per completion: ', atstats['YP COMP'],'Yards Per Carry: ', atstats['YP Carry'] )
- print('Average scores :', hometeam, (totalscores[hometeam] / gamesplayed), awayteam, (totalscores[awayteam] / gamesplayed))
- end = timer()
- #print('time: ', (end - start) )
- #print('')
- finalscores.append(hometeam + ' : ' + str((totalscores[hometeam] / gamesplayed)) + ' | ' + awayteam + ' : ' + str((totalscores[awayteam] / gamesplayed)))
- print()
- winner = max(totalscores.keys(), key=(lambda k: totalscores[k]))
- if winner == hometeam:
- winpercent = (gamestats['htwincount'] / gamesplayed) * 100
- winpercent = str(round(winpercent, 2)) + '%'
- if winner == awayteam:
- winpercent = (gamestats['atwincount'] / gamesplayed) * 100
- winpercent = str(round(winpercent, 2)) + '%'
- if str(winner) == realwinner:
- prediction = 'Yes'
- correctcount += 1
- if str(winner) != realwinner:
- prediction = 'No'
- percentcorrect = (correctcount / gamesinweek) * 100
- percentcorrect = str(round(percentcorrect, 2)) + '%'
- with open('outcomes.csv', 'a', newline='') as csvFile:
- writer = csv.writer(csvFile)
- writer.writerow([winner, winpercent, prediction, hometeam, awayteam, str((totalscores[hometeam] / gamesplayed)), str((totalscores[awayteam] / gamesplayed)), gamestats['htwincount'], gamestats['atwincount']])
- def pickteams():
- global matchcount
- global hometeam
- global awayteam
- import csv
- global week
- global season
- global realwinner
- with open('schedule.csv', newline='') as csvfile:
- schedule = csv.DictReader(csvfile)
- for row in schedule:
- if row['Season'] == season:
- if row['Week'] == str(weekstart):
- if row['Match Number'] == str(matchcount):
- hometeam = str(row['hometeam'])
- awayteam = str(row['awayteam'])
- realwinner = row['Winner']
- def match():
- global gamestats
- global offset
- global gamesplayed
- global matchcount
- global totalpenaltyyards
- global gamesinweek
- global percentcorrect
- global week
- pickteams()
- teamstats()
- statsreset()
- for i in range(gamesplayed):
- game()
- gamestats['games'] += 1
- if gamestats['games'] >= offset:
- print('Percent complete: ', int(( 100 * (offset / gamesplayed))), ' | Match Number: ', matchcount, ' | Week Number: ', weekstart)
- offset += (gamesplayed / 100)
- matchcount += 1
- printstats()
- def weekgames():
- global season
- global weekstart
- global numberofgames
- global gamesplayed
- global end
- global gamesinweek
- global percentcorrect
- global matchcount
- header()
- with open('schedule.csv', newline='') as csvfile:
- schedule = csv.DictReader(csvfile)
- for row in schedule:
- if row['Season'] == season:
- if row['Week'] == str(weekstart):
- gamesinweek += 1
- for i in range(gamesinweek):
- match()
- print(finalscores)
- print('time: ', (end - start) )
- print('')
- print('')
- print('')
- with open('outcomes.csv', 'a', newline='') as csvFile:
- writer = csv.writer(csvFile)
- writer.writerow('')
- writer.writerow(['Correct prediction', 'Correct %', 'Season', 'Week', 'Number of Games in Week', 'Count of Matchups Played', 'Run Time', 'Run Minutes', 'Run Hours'])
- writer.writerow([correctcount, percentcorrect, season, weekstart, gamesinweek, gamesplayed, (end - start), round((end - start) / 60, 2), round((end - start) / 60 / 60, 2)])
- writer.writerow('')
- writer.writerow('')
- def mainloop():
- global weekstart
- global weekend
- global totalcorrectcount
- global correctcount
- global matchcount
- global totalgamesinweek
- global gamesinweek
- global totalpercentcorrect
- while weekstart <= weekend:
- weekgames()
- weekstart += 1
- totalcorrectcount += correctcount
- matchcount = 1
- totalgamesinweek += gamesinweek
- gamesinweek = 0
- correctcount = 0
- totalpercentcorrect = (totalcorrectcount / totalgamesinweek) * 100
- totalpercentcorrect = str(round(totalpercentcorrect, 2)) + '%'
- def totalstatsprint():
- global totalcorrectcount
- global totalpercentcorrect
- global totalgamesinweek
- global end
- global totalstart
- with open('outcomes.csv', 'a', newline='') as csvFile:
- writer = csv.writer(csvFile)
- writer.writerow('')
- writer.writerow(['Total Correct prediction', 'Total Correct %', ' Total Count of Games Played', 'Total Run Time', 'Total Run Minutes', 'Total Run Hours'])
- writer.writerow([totalcorrectcount, totalpercentcorrect, totalgamesinweek, (end - totalstart), round((end - totalstart) / 60, 2), round((end - totalstart) / 60 / 60, 2)])
- writer.writerow('')
- writer.writerow('')
- mainloop()
- totalstatsprint()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement