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

Balls, Strikes, and Outs #55

Closed
ajbowler opened this issue Jan 22, 2018 · 3 comments
Closed

Balls, Strikes, and Outs #55

ajbowler opened this issue Jan 22, 2018 · 3 comments

Comments

@ajbowler
Copy link
Contributor

Splitting out from #54, it would be wonderful to get the balls/strikes/outs for an inning's current state.

@trevor-viljoen found a possible solution that we'll have to live test once spring training starts up.

<status status="Final" ind="F" reason="" inning="9" top_inning="N" b="0" s="0" o="3" inning_state="" note="" is_perfect_game="N" is_no_hitter="N"/>

@panzarino
Copy link
Owner

@ajbowler The existing events module contains information about the balls strikes and outs for each at bat, and I am fairly sure that just getting the last at bat will provide you with the current (live) ball, strikes, and outs.

@ajbowler
Copy link
Contributor Author

@panzarino yes, it does look like the existing events module will work fine for this. Thanks!

@trevor-viljoen
Copy link
Contributor

@ajbowler
mlbgame.game_events("2017_11_01_houmlb_lanmlb_1")[0].top[1] would correspond to this event:

<atbat num="2" b="0" s="0" o="0" start_tfs="002311" start_tfs_zulu="2017-11-02T00:23:11Z" end_tfs_zulu="2017-11-02T00:24:18Z" batter="608324" pitcher="506433" des="Alex Bregman reaches on a throwing error by first baseman Cody Bellinger.   George Springer scores.    Alex Bregman to 2nd.  " des_es="Alex Bregman se embasa por error en tiro de primera base Cody Bellinger.   George Springer anota  Alex Bregman a 2da.  " event_num="14" event="Field Error" event_es="Error de Fildeo" play_guid="05156dff-7cbc-456e-a480-9e64b00e89c2" score="T" home_team_runs="0" away_team_runs="1" b1="" b2="608324" b3="">

b1, b2, b3 are the bases. The number should be a player_id if you need that information. You can get it from mlbgame.players(game_id).home_players or mlbgame.players(game_id).away_players.

Something like this should work:

game_id = "2017_11_01_houmlb_lanmlb_1"

def runner(player_id, players):
    player = filter(lambda p: p.id == player_id, players)
    return player if player else None # or "", depending on how you want to implement it

away_players = mlbgame.players(game_id).away_players
home_players = mlbgame.players(game_id).home_players
events = mlbgame.game_events(game_id)[0].top
curr_ab = events[len(events)-1]
on_base = dict(b1=runner(curr_ab.b1, players), b2=runner(curr_ab.b2, players), b3=runner(curr_ab.b3, players))
count = dict(b=curr_ab.b, s=curr_ab.s, o=curr_ab.o)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants