Skip to content

Commit

Permalink
Merge pull request #251 from cwendt94/HockeyPlayerPosition
Browse files Browse the repository at this point in the history
Fix Hockey Player Position
  • Loading branch information
cwendt94 authored Oct 4, 2021
2 parents c787aa6 + 0212fff commit 80c4383
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 56 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/espn-api-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ jobs:
- name: Test integration
run: |
python3 setup.py nosetests --tests tests/football/integration/
python3 setup.py nosetests --tests tests/basketball/integration/
python3 setup.py nosetests --tests tests/basketball/integration/
python3 setup.py nosetests --tests tests/hockey/integration/
python3 setup.py nosetests --tests tests/baseball/integration/
5 changes: 5 additions & 0 deletions espn_api/hockey/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
, 6 : '6' # Forward ?
, 7 : '7' # Goalie, F (Goalie Bench?)
, 8 : '8' # Goalie, F
, 'Center': 1
, 'Left Wing' : 2
, 'Right Wing' : 3
, 'Defense' : 4
, 'Goalie' : 5
}

STATS_IDENTIFIER = {
Expand Down
2 changes: 1 addition & 1 deletion espn_api/hockey/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Player(object):
def __init__(self, data):
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')
Expand Down
Empty file added tests/hockey/__init__.py
Empty file.
16 changes: 8 additions & 8 deletions tests/hockey/unit/test_league.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setUp(self) -> None:
self.season = 2020
self.league = BaseLeague(self.league_id, self.season, sport= 'nhl')

with open('data/league_data.json') as data:
with open('tests/hockey/unit/data/league_data.json') as data:
self.league_data = json.loads(data.read())


Expand All @@ -34,7 +34,7 @@ def test_base_league_fetch_league(self, mock_get_league_request):

@mock.patch.object(EspnFantasyRequests, 'get_pro_players')
def test_base_league_fetch_players(self, mock_get_players):
with open('data/player_data.json') as data:
with open('tests/hockey/unit/data/player_data.json') as data:
player_data = json.loads(data.read())
mock_get_players.return_value = player_data

Expand All @@ -46,7 +46,7 @@ def test_base_league_fetch_players(self, mock_get_players):

@mock.patch.object(EspnFantasyRequests, 'get_pro_schedule')
def test_base_league_fetch_schedule(self, mock_get_pro_schedule):
with open('data/pro_schedule.json') as data:
with open('tests/hockey/unit/data/pro_schedule.json') as data:
schedule_data = json.loads(data.read())
mock_get_pro_schedule.return_value = schedule_data

Expand Down Expand Up @@ -85,7 +85,7 @@ def test_league(self, mock_league_request):

league = HockeyLeague(self.league_id, self.season)
self.assertEqual(league.scoringPeriodId, 265)
self.assertEqual(league.currentMatchupPeriod, 24)
self.assertEqual(league.currentMatchupPeriod, 13)
self.assertEqual(league.current_week, 264)
self.assertEqual(league.year, self.season)
mock_league_request.assert_called_once()
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_league_teams(self, mock_league_request):
@mock.patch.object(EspnFantasyRequests, 'league_get')
@mock.patch.object(EspnFantasyRequests, 'get_league')
def test_league_scoreboard(self, mock_get_league_request, mock_league_get_request):
with open('data/matchup_data.json') as file:
with open('tests/hockey/unit/data/matchup_data.json') as file:
matchup_data = json.loads(file.read())
mock_get_league_request.return_value = self.league_data
mock_league_get_request.return_value = matchup_data
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_league_get_team_data(self, mock_get_league_request):
@mock.patch.object(EspnFantasyRequests, 'league_get')
@mock.patch.object(EspnFantasyRequests, 'get_league')
def test_league_free_agency(self, mock_get_league_request, mock_league_get_request):
with open('data/free_agent_data.json') as file:
with open('tests/hockey/unit/data/free_agent_data.json') as file:
free_agents_data = json.loads(file.read())
mock_get_league_request.return_value = self.league_data
mock_league_get_request.return_value = free_agents_data
Expand All @@ -162,7 +162,7 @@ def test_league_free_agency(self, mock_get_league_request, mock_league_get_reque
@mock.patch.object(EspnFantasyRequests, 'league_get')
@mock.patch.object(EspnFantasyRequests, 'get_league')
def test_league_recent_activity(self, mock_get_league_request, mock_league_get_request):
with open('data/recent_activity_data.json') as file:
with open('tests/hockey/unit/data/recent_activity_data.json') as file:
activity_data = json.loads(file.read())
mock_get_league_request.return_value = self.league_data
mock_league_get_request.return_value = activity_data
Expand All @@ -180,7 +180,7 @@ def test_league_recent_activity(self, mock_get_league_request, mock_league_get_r
@mock.patch.object(EspnFantasyRequests, 'league_get')
@mock.patch.object(EspnFantasyRequests, 'get_league')
def test_league_box_scores(self, mock_get_league_request, mock_league_get_request):
with open('data/box_score_data.json') as file:
with open('tests/hockey/unit/data/box_score_data.json') as file:
box_score_data = json.loads(file.read())
mock_get_league_request.return_value = self.league_data
mock_league_get_request.return_value = box_score_data
Expand Down
18 changes: 2 additions & 16 deletions tests/hockey/unit/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,15 @@
class TestPlayer(TestCase):

def setUp(self) -> None:
with open('./data/league_data.json') as data:
with open('tests/hockey/unit/data/league_data.json') as data:
self.roster_data = json.loads(data.read())['teams'][0]['roster']['entries']

def test_player(self):
player_input = self.roster_data[0]
actual_player = Player(player_input)

self.assertEqual('Player(Taylor Hall)', repr(actual_player))


def test_player_stats_to_df(self):
player_input = self.roster_data[0]
actual_player = Player(player_input)

actual_df = actual_player.to_df("Total 2020")
# test dict
second_df = actual_player.to_df("Total 2020")
self.assertEqual(actual_df['G'].iloc[0], 16)
self.assertEqual(actual_df['A'].iloc[0], 36)
self.assertEqual(actual_df['+/-'].iloc[0], -13)
self.assertEqual(actual_df['PIM'].iloc[0], 32)

self.assertEqual(actual_player, second_df)
self.assertEqual(actual_player.position, 'Left Wing')



Expand Down
34 changes: 4 additions & 30 deletions tests/hockey/unit/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class TestHockeyTeam(TestCase):
def setUp(self) -> None:
with open('./data/league_data.json') as file:
with open('tests/hockey/unit/data/league_data.json') as file:
self.data = json.loads(file.read())
self.teams = self.data['teams']
self.schedule = self.data['schedule']
Expand All @@ -22,33 +22,7 @@ def test_team(self):

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

expected_players = ['Thomas Chabot',
'Brayden Point',
'Patrik Laine',
'Mikko Rantanen',
'Sidney Crosby',
'Dougie Hamilton',
'Artemi Panarin',
'Frederik Andersen',
'Teuvo Teravainen',
'Matt Dumba',
'William Nylander',
'Nico Hischier',
'Brock Boeser',
'Shea Theodore',
'Sam Reinhart',
'Jacob Markstrom',
'Evgenii Dadonov',
'Adam Fox',
'Phillip Danault',
'Bryan Rust',
'Ryan Suter',
'Elvis Merzlikins',
'Anthony Cirelli',
'Alexandar Georgiev',
'Nikita Gusev']

self.assertListEqual(list(df.index), expected_players)

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

0 comments on commit 80c4383

Please sign in to comment.