-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNFLSimulator
48 lines (38 loc) · 2.36 KB
/
NFLSimulator
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## Main arguments used for predicting scores are Standard Relative Strength, Points Per Game, Points Allowed Per Game, DVOA (From Football Outsiders), and Variance (From Football Outsiders)
# Method below is for putting all the team information in a single dictionary
def teambuilder(team, srs, pf, pa, dvoa, var):
return {'Team': team, 'Standard Relative Strength': srs, 'Points For': pf, 'Points Against': pa, 'DVOA': dvoa, 'Variance': var}
# Extracts the values from the dictionary and turns it into a team based listed
def extract(team):
return list(team.values())
# Takes in the standard relative strength of both teams and calculates who has a better chance of winning
def win_probability(a, b):
if a > b:
a *= 100
print('Win Probability: ' + format(a,'.1f') + '%')
elif b > a:
b *= 100
print('Win Probability: ' + format(b, '.1f') + '%')
else:
print('Win Probability: 50%')
# Method that determines the scores based upon the teams playing
def matchup(teama, teamb):
lista = extract(teama)
listb = extract(teamb)
totalstrength = int(lista[1]) + int(listb[1]) # Adding the total strength of both teams
srsa = int(lista[1])/totalstrength # Percent strength of team A based on Standard Relative Strength
srsb = int(listb[1])/totalstrength # Percent strength of team B based on Standard Relative Strength
a = (float(lista[2]) + float(lista[3]) + float(listb[2]) + float(listb[3]))/2 # Adding the points for and points against for an O/U number
x = srsa * a # Team A percent strength times O/U number
y = srsb * a # Team B percent strength times O/U number
x1 = (100 + float(lista[4]) + float(listb[5]) - float(lista[5]))/100 # Team A's DVOA plus Team B's performance variance minus Team A's performance variance
y1 = (100 + float(listb[4]) + float(lista[5]) - float(listb[5]))/100 # Team B's DVOA plus Team A's performance variance minus Team B's performance variance
score1 = x * x1 # Score prediction for team A based on the previous calculations
score2 = (y * y1) + 3 # Score prediction for team B based on the previous calculations plus 3 for home field advantage
# Formatting the output and then printing
away = lista[0] + ': ' + str(round(score1))
home = listb[0] + ': ' + str(round(score2))
print(away)
print(home)
win_probability(srsa, srsb)
print()