Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The roster for team #142

Open
WillMusing opened this issue Jun 23, 2024 · 6 comments
Open

The roster for team #142

WillMusing opened this issue Jun 23, 2024 · 6 comments
Assignees
Labels
question Question about usage/support

Comments

@WillMusing
Copy link

I am looking for the team roster information and found the statsapi.roster() is very helpful. However, it returns a string which I have to parse and might have some level of errors i.e. if one has middle name, etc. Would it be better to return a list - it seems having the list format in the string.

In addition, it would be really great to also return the player Id as well.

Thank you for creating this statsapi!

@toddrob99
Copy link
Owner

You can fetch the unformatted data the same way statsapi.roster() does, using statsapi.get("team_roster", <params>). Here is the function in the source code.

@toddrob99 toddrob99 self-assigned this Jun 23, 2024
@toddrob99 toddrob99 added the question Question about usage/support label Jun 23, 2024
@WillMusing
Copy link
Author

Thank you so much @toddrob99. I much appreciated your response!

So the exercise I am working on is to find the team Id / team name based on the pitcher Id (from every pitch) to analyze the pitcher performance. Since I can't find any function to get team Id from pitcher Id, the path I am going is to use the pitcher Id from a specific game -> pitcher first name, last name -> look up the name from team roster of all time (lots of data to aggregate) -> find the team(s) has this pitch name or pitcher Id. Is there any better way to do this?

@toddrob99
Copy link
Owner

Where are you getting the pitch data from? If it's from the game endpoint, the team information is in there too.

If you truly have pitch data with a pitcher id but no team info, you can look up the player from the pitcher id using the person endpoint and statsapi.get().

If I were analyzing all pitches from all games in a given season, I would start with the schedule endpoint to get a list of gamePks, then loop through the game endpoint for each gamePk and collect the team, pitcher, and pitch data from there.

@WillMusing
Copy link
Author

Thanks again @toddrob99. I tried the team_roster but couldn't get the right data yet. Still working on it. For example,

roster_list = statsapi.get("team_roster", params= { "teamId": 4104, "rosterType": "fullRoster", "season" : 2018})
It returns without the actual roster. I am not sure if I am using it the correct way:

{'copyright': 'Copyright 2024 MLB Advanced Media, L.P.  Use of any content on this page acknowledges agreement to the terms posted here http://gdx.mlb.com/components/copyright.txt',
 'link': '/api/v1/teams/4104/roster',
 'teamId': 4104,
 'rosterType': 'fullSeason'}

@WillMusing
Copy link
Author

WillMusing commented Jun 28, 2024

By the way, for your question about pitch data, I got it from https://github.com/jldbc/pybaseball. It contains detail pitching data around every pitch since 2018. I thought analyzing the pitching style/speed by team over time could be valuable information.

This pybaseball data does have gamePk.

@toddrob99
Copy link
Owner

It seems like the API doesn't have roster data for minor league teams, because if I change the teamId to 143 (Philadelphia Phillies) it does return the roster data.

https://statsapi.mlb.com/api/v1/teams/4104/roster?rosterType=fullRoster&season=2018
https://statsapi.mlb.com/api/v1/teams/143/roster?rosterType=fullRoster&season=2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about usage/support
Projects
None yet
Development

No branches or pull requests

2 participants