Skip to content

Commit

Permalink
Merge pull request #552 from cwendt94/wbasketball_fix_positions
Browse files Browse the repository at this point in the history
WNBA Fix Player Positions
  • Loading branch information
cwendt94 authored Aug 15, 2024
2 parents 80bcefc + 2bb4975 commit 98d6338
Showing 3 changed files with 21 additions and 35 deletions.
48 changes: 17 additions & 31 deletions espn_api/wbasketball/constant.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
POSITION_MAP = {
0: 'PG',
1: 'SG',
2: 'SF',
3: 'PF',
4: 'C',
5: 'G',
6: 'F',
7: 'SG/SF',
8: 'G/F',
9: 'PF/C',
10: 'F/C',
11: 'UT',
12: 'BE',
13: 'IR',
14: '',
15: 'Rookie',
0: '',
1: 'G',
2: 'F',
3: 'C',
4: 'F/C',
5: 'UTIL',
6: 'BE',
7: 'IR',
8: 'Unknown',
9: 'Unknown',
# reverse
'PG': 0,
'SG': 1,
'SF': 2,
'PF': 3,
'C': 4,
'G': 5,
'F': 6,
'SG/SF': 7,
'G/F': 8,
'PF/C': 9,
'F/C': 10,
'UT': 11,
'BE': 12,
'IR': 13,
'Rookie': 15
'G': 1,
'F': 2,
'C': 3,
'F/C': 4,
'UTIL': 5,
'BE': 6,
'IR': 7
}

PRO_TEAM_MAP = {
2 changes: 1 addition & 1 deletion espn_api/wbasketball/league.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ def __init__(self, league_id: int, year: int, espn_s2=None, swid=None, fetch_lea
super().__init__(league_id=league_id, year=year, sport='wnba', espn_s2=espn_s2, swid=swid, debug=debug)

if fetch_league:
self._fetch_league()
self.fetch_league()

def fetch_league(self):
data = self._fetch_league()
6 changes: 3 additions & 3 deletions espn_api/wbasketball/player.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ class Player(object):
def __init__(self, data, year):
self.name = json_parsing(data, 'fullName')
self.playerId = json_parsing(data, 'id')
self.position = POSITION_MAP[json_parsing(data, 'defaultPositionId') - 1]
self.position = POSITION_MAP[json_parsing(data, 'defaultPositionId')]
self.lineupSlot = POSITION_MAP.get(data.get('lineupSlotId'), '')
self.eligibleSlots = [POSITION_MAP[pos] for pos in json_parsing(data, 'eligibleSlots')]
self.acquisitionType = json_parsing(data, 'acquisitionType')
@@ -20,12 +20,12 @@ def __init__(self, data, year):
self.injuryStatus = player.get('injuryStatus', self.injuryStatus)
self.injured = player.get('injured', False)

for split in player.get('stats', []):
for split in player.get('stats', []):
id = self._stat_id_pretty(split['id'])
applied_total = split.get('appliedTotal', 0)
applied_avg = round(split.get('appliedAverage', 0), 2)
self.stats[id] = dict(applied_total=applied_total, applied_avg=applied_avg)
if split['stats']:
if 'stats' in split:
if 'averageStats' in split.keys():
self.stats[id]['avg'] = {STATS_MAP[i]: split['averageStats'][i] for i in split['averageStats'].keys() if STATS_MAP[i] != ''}
self.stats[id]['total'] = {STATS_MAP[i]: split['stats'][i] for i in split['stats'].keys() if STATS_MAP[i] != ''}

0 comments on commit 98d6338

Please sign in to comment.