Skip to content

Commit

Permalink
Draft Evaluation Metric
Browse files Browse the repository at this point in the history
  • Loading branch information
rishab827 committed Dec 19, 2024
1 parent 47a31fd commit 32d0385
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
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:
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

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())

0 comments on commit 32d0385

Please sign in to comment.