Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft Evaluation Metric #619

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added espn_api/.DS_Store
Binary file not shown.
61 changes: 61 additions & 0 deletions espn_api/football/league.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
import json
import random
from typing import Callable, Dict, List, Tuple, Union
Expand Down Expand Up @@ -398,3 +399,63 @@ def message_board(self, msg_types: List[str] = None):
for msg in msgs:
messages.append(msg)
return messages



def draft_evaluation(self):
#Calculating draft quality score based on projected score vs actual score for each pick
draftData = self.draft
#Process of removing any duplicates from draft data for accuracy
duplicates = set()
duplicates_removed = []
for pick in draftData:
pick_id = (pick.round_num, pick.round_pick)
if pick_id not in duplicates:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would there ever be duplicates in this data?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I printed out league.draft, the draft picks would repeat so that the set was double the actual size, sometimes even triple. I couldn't find why, so I decided to just filter it out with this method.

duplicates_removed.append(pick)
duplicates.add(pick_id)

#Adding drafted players to each team
hashmap = defaultdict(list)
for pick in duplicates_removed:
team = pick.team
hashmap[team.team_name].append(pick.playerName)

realScores = []

#Calculating scores
for team_name, players in hashmap.items():
print(f"Processing Team: {team_name}")
projectedsum = 0
actualsum = 0
avg_projectedsum = 0
avg_actualsum = 0
for player in players:
playerData = self.player_info(name=player)
if not playerData:
print(f"Warning: No data found for player '{player}' in team '{team_name}'. Skipping.")
continue

print(f"Player Data: {playerData}")
projectedsum += playerData.projected_total_points
actualsum += playerData.total_points
avg_projectedsum += playerData.projected_avg_points
avg_actualsum += playerData.avg_points

draftscore = actualsum - projectedsum
avgdraftscore = avg_actualsum - avg_projectedsum

#Weighting average points vs total points
real_score = 0.2 * draftscore + 0.8 * avgdraftscore
Comment on lines +444 to +448
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like a draft score should incorporate the pick number in some way. Screwing up your 1st round pick should hurt you much more than screwing up your 10th round pick, for example. Simply using points wouldn't necessarily pick up on this, as a QB will have the largest raw points but probably isn't drafted until a few rounds later. Perhaps using pick value to weight each pick (or something similar to this).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great point, I'll incorporate this.


realScores.append({
"Name": team_name,
"Score": real_score
})

#Scaling scores for more intuitive results
for item in realScores:
item["Score"] = (item["Score"] / 100) + 10

realScores.sort(key=lambda x: x["Score"], reverse=True)

return realScores
19 changes: 19 additions & 0 deletions tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pandas as pd
from espn_api.football import League


'''
Algorithm: Draft Score (Scaled) -> Value Added From Acquisitions (Straight Addition) -> Lineup Setting -> (Bench Output)
'''
league_id = 44356805
year = 2024
swid = '{F8014DC0-556B-4952-AC13-98FA88F24081}'
espn_s2 = 'AEB%2BnXVSBDwR0k6uRFDJz%2Ft73KjhXlHta8mtA05%2BlW0fVF7boPlz6%2FJK4J71B57S%2FvAYDQMA%2B1FoZU%2Bhf7oU2ybOi7%2BWtzHPiS7wQwEhh9WqKfUt6wKKklb9KzHvkuhxlro%2FSLUsZkaWpaW51ckTjN9v9sVFVzSQt3%2FN6deYEs4AbwJJxEq%2Bx6sd4bWpLxgRkMSyX5%2FXyp5xb1P6sv%2FWdxL2uVuH4gdyZ%2FHxxrnqTQuaYMZCFQyBa%2Fc5uU56GclYq3AEeJEth01IljeokzoQe1D%2FFHrT3ajd0hAZvZu3m1iLOudkf49cIa16gaRVxo1x710%3D'




league = League(league_id=league_id, year=year,swid=swid,espn_s2=espn_s2)
league.fetch_league()
league.refresh_draft()
print(league.draftEvaluation())