From 32d038529c5529c27fdd6c8955d7c5a486cb39e0 Mon Sep 17 00:00:00 2001 From: Rishab Jayaraman Date: Thu, 19 Dec 2024 21:48:32 +0000 Subject: [PATCH] Draft Evaluation Metric --- .DS_Store | Bin 0 -> 6148 bytes espn_api/.DS_Store | Bin 0 -> 6148 bytes espn_api/football/league.py | 61 ++++++++++++++++++++++++++++++++++++ tester.py | 19 +++++++++++ 4 files changed, 80 insertions(+) create mode 100644 .DS_Store create mode 100644 espn_api/.DS_Store create mode 100644 tester.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..df36ca965bc681e0625caeb00e3c751de198167b GIT binary patch literal 6148 zcmeHKJ8r`;3?*9+2D*66s4Mgag5jQ^2T0PSLjj{MV08DCbLD7#{0t4;Z0Qm_0@RZz zJ_&k*X^M#U-^XW>PDEO`p`2`3o9&yg>>(oxgyW2@?Bz>7j`Lw$W&a&8ZY%FHgZKHH z|29pdZPKU!6`%rCfC^B7n<|jywSBtjsXUAdP=R|;z`hR!ZdenSK>u`L@D>2rAnb;@ z_Y%Nj0bosB0ug~}P=P_!Y%w(Gh?mT(iA!M6MYH+PyjinDQNJDM7f%S-4S0Nmge*B3%ja}qs1Dp_`nX&IPkg5oO=_TBi=FN?~gBs-8jZN z1Ku$5IW0b)ylfv;NdYM!1*Cu!kOHXyd$!wfo2V!Sq<|DSDd6WrqdWG(DKU-?hPVO{ zS4@ZTJ?;|3<_TgioD!L#SyG8fwYp+h(wT2n*9)h_q{Cuou2VZ(-B2ucXTC)_tS2f; z0V!~6cqnsgHF)>;( g2i}VBW_8WqIo}JX#Go@DbfSI)To;)X_zMNT0rFNGV*mgE literal 0 HcmV?d00001 diff --git a/espn_api/football/league.py b/espn_api/football/league.py index 17fa12b2..906ac09e 100644 --- a/espn_api/football/league.py +++ b/espn_api/football/league.py @@ -1,3 +1,4 @@ +from collections import defaultdict import json import random from typing import Callable, Dict, List, Tuple, Union @@ -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 \ No newline at end of file diff --git a/tester.py b/tester.py new file mode 100644 index 00000000..306670b6 --- /dev/null +++ b/tester.py @@ -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())