panzarino / mlbgame

A Python API to retrieve and read MLB GameDay data
http://panz.io/mlbgame/
MIT License
526 stars 112 forks source link

What is an Injury object? How can it be accessed? #47

Closed robotallie closed 6 years ago

robotallie commented 6 years ago

I am trying to create a pandas dataframe of injuries from 2000-2017, with corresponding player profiles. I have a list of injury objects for each game, for each year, but I hit a snag when I was looking for 2005 game data. There was an error for one of the URLs that raised an exception error and crashed the entire 2005 grab.

The challenge I'm having is trying to understand the injury() object. Are there any examples out there or is there documentation that shows some injury data? For all the games in a year, I appended injury() to an injured_list. I can access the injury information by subsetting the injured list, but I can't seem to iterate that list. Any advice or examples would be really helpful.

panzarino commented 6 years ago

Do you have the exact date for the URL error? If you can provide me with that data, I should be able to look into it and see that the error is.

Documentation for the injury object can be located here: http://panz.io/mlbgame/info.m.html#mlbgame.info.Injury This documentation contains all of the object properties for injuries.

Here is a small example of getting injury data:

import mlbgame

for injury in mlbgame.injury().injuries:
    print(injury.name_first + " " +
    injury.name_last + " (" +
    injury.position + ") (" +
    injury.team_name + ") " +
    injury.injury_desc)

And the output:

Alex Meyer (P) (Angels) Recovering from Sept. 2017 right shoulder surgery
Brady Rodgers (P) (Astros) Recovering from May 2017 Tommy John surgery
Jandel Gustave (P) (Astros) Recovering from June 2017 Tommy John surgery
Jimmy Nelson (P) (Brewers) Recovering from Sept. 2017 right shoulder surgery
Alex Reyes (P) (Cardinals) Recovering from February 2017 Tommy John surgery
Ildemaro Vargas (2B) (D-backs) Recovering from Oct. 2017 right hand surgery
Chris Owings (SS) (D-backs) Fractured right middle finger
Shelby Miller (P) (D-backs) Recovering from May 2017 Tommy John surgery
Grant Dayton (P) (Dodgers) Recovering from August 2017 Tommy John surgery
Will Smith (P) (Giants) Recovering from March 2017 Tommy John surgery
Brandon Guyer (RF) (Indians) Left wrist soreness
Michael Brantley (LF) (Indians) Recovering from October 2017 right ankle surgery
Cody Anderson (P) (Indians) Recovering from March 2017 Tommy John surgery
Drew Smyly (P) (Mariners) Recovery from July 2017 Tommy John surgery
Edinson Volquez (P) (Marlins) Recovering from August 2017 Tommy John surgery
David Wright (3B) (Mets) Recovering from September 2017 shoulder surgery
T.J. Rivera (3B) (Mets) Recovering from September 2017 Tommy John surgery
Michael Conforto (LF) (Mets) Recovering from September 2017 shoulder surgery
Joe Ross (P) (Nationals) Recovering from July 2017 Tommy John surgery
Daniel Murphy (2B) (Nationals) Recovering from October 2017 right knee surgery
Carter Capps (P) (Padres) Recovering from Sept. 2017 surgery
Chi Chi Gonzalez (P) (Rangers) Recovering from July 2017 Tommy John surgery
Eduardo Rodriguez (P) (Red Sox) Recovering from October 2017 right knee surgery
Dustin Pedroia (2B) (Red Sox) Recovering from October 2017 left knee surgery
Rookie Davis (P) (Reds) Recovering from October 2017 right hip surgery
Nate Karns (P) (Royals) Recovering from July 2017 rib surgery
Trevor May (P) (Twins) Recovering from March 2017 Tommy John surgery
Carlos Rodon (P) (White Sox) Recovering from Sept. 2017 left shoulder surgery
Zach Putnam (P) (White Sox) Recovering from June 2017 Tommy John surgery
Jake Petricka (P) (White Sox) Recovering from October 2017 right elbow surgery

Hopefully this helps, if you need any more information feel free to let me know.

robotallie commented 6 years ago

This really helps! The date was March 8, 2005, I believe. Thanks!

Here's the error: File "http://gd2.mlb.com/components/game/mlb/year_2005/month_03/day_08/scoreboard.xml", line 1 XMLSyntaxError: Document is empty, line 1, column 1

robotallie commented 6 years ago

I want injury data for all teams for 2000, so I requested game data this way: year_games_2000 = mlbgame.games(2000) games_2000 = mlbgame.combine_games(year_games_2000)

Then, to get corresponding injuries info, where would I insert the game specific id to request injuries for 2005 in the following code snipped:

injury_2000 = mlbgame.injuries().injuries

Thanks!

panzarino commented 6 years ago

I am not sure if that is currently an option. Currently, the injury function just gets current injury data. I will look into seeing if there is a way to get historical injury data for certain games or certain points in time.

robotallie commented 6 years ago

That would be great. There are a few people that have created Excel sheets on their own with updates from other fans for years 2000 - 2017, but I'm hoping to do a machine learning classification analysis on injuries to predict the likelihood of a player being injured in any game based on other historical stats for that player and that game.

The API is awesome, by the way!