What if the fantasy schedule were different?
Anyone who plays fantasy football knows that it feels your team would have a higher rank, if only your schedule had been different. While with actual sports, it is non-sensical to consider every team playing every other team each week, the benefit of fantasy football is our imaginations are less constrained by the realities of life.
The goal in each week of fantasy is the same: get as many points as possible. Therefore, the strategy: who you start who you sit each week, doesn’t really depend on your opponent that week. This means that, in my mind, there is a more reasonable way to say that in some sense, the hypothetical where every team plays every other teams each week is reasonable. If this were the case, then the new true ranking would be the total sum of all possible wins over all the weeks.
So, how do you remove the effect of schedule? Fortunatley, it’s quite easy! While there is 12 choose 2 = 2 66 possible pairings each week, it is easy to visualize how many wins a team would have in a given week. If a team comes in 5th place in a given week, then we know there are 7 pairings they would have won, and 4 they would have lost. This can be done for each player, and since the number of pairings are the same for each person each week, to get a total ranking, all we have to do is count up the total number of possible wins (that is, green rectangles) over the regular season!
To get the true score, you would have to calculate the total number of wins through all the weeks of fantasy
Curious if this would be easy, I decided to do it for our fantasy league! Fortunately, if a team uses the sleeper app, this is very easy to calculate using their public api. All you need to calclate the true rankings is the league id
number. The code to calculate it is shown here!
First, we need to get points for each team through all the weeks
Then we can convert these point values to number of wins for that week and add up the total number of wins.
Finally, we have the true rankings.
Note, this code does not have pretty formatting.
import pandas as pd
import requests as rq
from tqdm import tqdm
league_id = '978044540609208320' # 3rd Shitshow
bn = 'https://api.sleeper.app/v1' # Base name
# Get usernames
r = rq.get(f'{bn}/league/{league_id}/rosters')
t = r.json()
ownerIDs = [k['owner_id'] for k in t]
users = []
for k in tqdm(ownerIDs):
r = rq.get(f'{bn}/user/{k}')
users.append(r.json()['username'])
# Get team names
r = rq.get(f'{bn}/league/{league_id}/users')
t = r.json()
teamNames = 12*['No Name!']
for k in t:
idx = ownerIDs.index(k['user_id'])
if 'team_name' in k['metadata']:
teamNames[idx] = k['metadata']['team_name']
# Grab points from each week
df = {'Users':users, 'Team Names':teamNames}
for week in tqdm(range(1,11)):
r = rq.get(f'{bn}/league/{league_id}/matchups/{week}')
if r.status_code == 200:
data = r.json()
points = [k['points'] for k in data]
df[f'Week {week}'] = points
df = pd.DataFrame(df)
df_ranked = df.rank(numeric_only=True) - 1
# Convert scores to ranks!
df_ranked['Total Wins'] = df_ranked.sum(numeric_only=True,axis=1)
df_ranked.insert(loc=0,column='User',value=users)
df_ranked = df_ranked.sort_values(by='Total Wins',ascending=False)
print('Point Totals'); print(df)
print('Total Wins'); print(df_ranked)
Thank you for reading!