Skip to content

Commit

Permalink
Merge pull request #472 from cwendt94/fix-new-team-data-format
Browse files Browse the repository at this point in the history
Fix Team Data Change
  • Loading branch information
cwendt94 authored Oct 2, 2023
2 parents 8186275 + adc35f2 commit 59ea511
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.233.0/containers/python-3/.devcontainer/base.Dockerfile

# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
ARG VARIANT="3.6-bullseye"
ARG VARIANT="3.8-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3.6-bullseye",
"VARIANT": "3.8-bullseye",
// Options
"NODE_VERSION": "none"
}
Expand Down
10 changes: 1 addition & 9 deletions espn_api/base_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def _fetch_teams(self, data, TeamClass, pro_schedule = None):
'''Fetch teams in league'''
self.teams = []
teams = data['teams']
members = data['members']
schedule = data['schedule']
seasonId = data['seasonId']

Expand All @@ -53,15 +52,8 @@ def _fetch_teams(self, data, TeamClass, pro_schedule = None):
team_roster[team['id']] = team.get('roster', {})

for team in teams:
for member in members:
# For league that is not full the team will not have a owner field
if 'owners' not in team or not team['owners']:
member = None
break
elif member['id'] == team['owners'][0]:
break
roster = team_roster[team['id']]
self.teams.append(TeamClass(team, roster=roster, member=member, schedule=schedule, year=seasonId, pro_schedule=pro_schedule))
self.teams.append(TeamClass(team, roster=roster, schedule=schedule, year=seasonId, pro_schedule=pro_schedule))

# sort by team ID
self.teams = sorted(self.teams, key=lambda x: x.team_id, reverse=False)
Expand Down
12 changes: 5 additions & 7 deletions espn_api/baseball/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,23 @@

class Team(object):
'''Teams are part of the league'''
def __init__(self, data, member, roster, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
if year < 2023:
self.team_name = "%s %s" % (data.get('location', 'Unknown'), data.get('nickname', 'Unknown'))
else:
self.team_name = data.get('name', 'Unknown')
self.division_id = data['divisionId']
self.division_name = '' # set by caller
self.wins = data['record']['overall']['wins']
self.losses = data['record']['overall']['losses']
self.ties = data['record']['overall']['ties']
self.owner = 'None'
self.logo_url = ''
self.standing = data['playoffSeed']
self.final_standing = data['rankCalculatedFinal']
self.roster = []
self.schedule = []

if member:
self.owner = "%s %s" % (member['firstName'],
member['lastName'])
if 'logo' in data:
self.logo_url = data['logo']

Expand Down
11 changes: 5 additions & 6 deletions espn_api/basketball/team.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import pdb
from .player import Player
from .matchup import Matchup
from .constant import STATS_MAP

class Team(object):
'''Teams are part of the league'''
def __init__(self, data, member, roster, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
if year < 2023:
self.team_name = "%s %s" % (data.get('location', 'Unknown'), data.get('nickname', 'Unknown'))
else:
self.team_name = data.get('name', 'Unknown')
self.division_id = data['divisionId']
self.division_name = '' # set by caller
self.wins = data['record']['overall']['wins']
self.losses = data['record']['overall']['losses']
self.ties = data['record']['overall']['ties']
self.owner = 'None'
self.logo_url = ''
self.stats = None
self.standing = data['playoffSeed']
Expand All @@ -24,8 +25,6 @@ def __init__(self, data, member, roster, schedule, year, **kwargs):

if 'valuesByStat' in data:
self.stats = {STATS_MAP.get(i, i): j for i, j in data['valuesByStat'].items()}
if member:
self.owner = f"{member['firstName']} {member['lastName']}"
if 'logo' in data:
self.logo_url = data['logo']

Expand Down
2 changes: 1 addition & 1 deletion espn_api/football/pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def __repr__(self):
return 'Pick(%s, %s)' % (self.playerName, self.team)

def auction_repr(self):
return ', '.join(map(str, [self.team.owner, self.playerId, self.playerName, self.bid_amount, self.keeper_status]))
return ', '.join(map(str, [self.team, self.playerId, self.playerName, self.bid_amount, self.keeper_status]))
10 changes: 3 additions & 7 deletions espn_api/football/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

class Team(object):
'''Teams are part of the league'''
def __init__(self, data, roster, member, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
if year < 2023:
self.team_name = "%s %s" % (data['location'], data['nickname'])
self.team_name = "%s %s" % (data.get('location', 'Unknown'), data.get('nickname', 'Unknown'))
else:
self.team_name = data['name']
self.team_name = data.get('name', 'Unknown')
self.division_id = data['divisionId']
self.division_name = '' # set by caller
self.wins = data['record']['overall']['wins']
Expand All @@ -22,10 +22,6 @@ def __init__(self, data, roster, member, schedule, year, **kwargs):
self.trades = data.get('transactionCounter', {}).get('trades', 0)
self.playoff_pct = data.get('currentSimulationResults', {}).get('playoffPct', 0) * 100
self.draft_projected_rank = data.get('draftDayProjectedRank', 0)
self.owner = 'None'
if member:
self.owner = "%s %s" % (member['firstName'],
member['lastName'])
self.streak_length = data['record']['overall']['streakLength']
self.streak_type = data['record']['overall']['streakType']
self.standing = data['playoffSeed']
Expand Down
1 change: 0 additions & 1 deletion espn_api/hockey/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
]

from .league import League
from .member import Member
from .player import Player
from .record import Record
from .team import Team
Expand Down
9 changes: 0 additions & 9 deletions espn_api/hockey/member.py

This file was deleted.

10 changes: 5 additions & 5 deletions espn_api/hockey/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
class Team(object):
'''Teams are part of the league'''

def __init__(self, data, member, roster, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
if year < 2023:
self.team_name = "%s %s" % (data.get('location', 'Unknown'), data.get('nickname', 'Unknown'))
else:
self.team_name = data.get('name', 'Unknown')
self.division_id = data['divisionId']
self.division_name = '' # set by caller
self.wins = data['record']['overall']['wins']
Expand All @@ -26,9 +29,6 @@ def __init__(self, data, member, roster, schedule, year, **kwargs):

if 'valuesByStat' in data:
self.stats = {STATS_MAP[i]: j for i, j in data['valuesByStat'].items()}
if member:
self.owner = "%s %s" % (member['firstName'],
member['lastName'])
if 'logo' in data:
self.logo_url = data['logo']

Expand Down
9 changes: 5 additions & 4 deletions espn_api/wbasketball/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

class Team(object):
'''Teams are part of the league'''
def __init__(self, data, member, roster, schedule, year, **kwargs):
def __init__(self, data, roster, schedule, year, **kwargs):
self.team_id = data['id']
self.team_abbrev = data['abbrev']
self.team_name = "%s %s" % (data['location'], data['nickname'])
if year < 2023:
self.team_name = "%s %s" % (data.get('location', 'Unknown'), data.get('nickname', 'Unknown'))
else:
self.team_name = data.get('name', 'Unknown')
self.division_id = data['divisionId']
self.division_name = '' # set by caller
self.wins = data['record']['overall']['wins']
Expand All @@ -23,8 +26,6 @@ def __init__(self, data, member, roster, schedule, year, **kwargs):

if 'valuesByStat' in data:
self.stats = {STATS_MAP[i]: j for i, j in data['valuesByStat'].items()}
if member:
self.owner = f"{member['firstName']} {member['lastName']}"
if 'logo' in data:
self.logo_url = data['logo']

Expand Down
2 changes: 1 addition & 1 deletion tests/football/unit/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_draft(self, m):
self.assertEqual(repr(first_pick), 'Pick(Le\'Veon Bell, Team(Rollin\' With Mahomies))')
self.assertEqual(third_pick.round_num, 1)
self.assertEqual(third_pick.round_pick, 3)
self.assertEqual(third_pick.auction_repr(), 'T M, 13934, Antonio Brown, 0, False')
self.assertEqual(third_pick.auction_repr(), 'Team(Goin\' HAM Newton), 13934, Antonio Brown, 0, False')

# TODO need to get data for most recent season
# @requests_mock.Mocker()
Expand Down
6 changes: 3 additions & 3 deletions tests/hockey/unit/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ def setUp(self) -> None:
self.teams = self.data['teams']
self.schedule = self.data['schedule']
self.seasonId = self.data['seasonId']
self.year = '2020'
self.year = 2020

self.team = self.data['teams'][3]
self.team_roster = self.team['roster']

def test_team(self):
team = Team(self.team, roster= self.team_roster, member= None, schedule= self.schedule, year= self.year)
team = Team(self.team, roster= self.team_roster, schedule= self.schedule, year= self.year)
self.assertEqual(team.team_abbrev, 'ESPC')

def test_team_roster_df(self):
team = Team(self.team, roster= self.team_roster, member= None, schedule= self.schedule, year= self.year)
team = Team(self.team, roster= self.team_roster, schedule= self.schedule, year= self.year)

self.assertEqual(len(team.roster), 25)
self.assertEqual(team.roster[0].name, 'Thomas Chabot')
Expand Down

0 comments on commit 59ea511

Please sign in to comment.