Skip to content

Commit

Permalink
Update events to inherit object class
Browse files Browse the repository at this point in the history
  • Loading branch information
panzarino committed Aug 24, 2017
1 parent 6acc826 commit 68ec906
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions mlbgame/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import mlbgame.data
import mlbgame.object

import lxml.etree as etree

Expand Down Expand Up @@ -74,7 +75,7 @@ def __init__(self, data, inning):
`data` should be a dictionary of values.
"""
self.num = inning
self.num = int(inning)
self.top = [AtBat(x) for x in data['top']]
self.bottom = [AtBat(x) for x in data['bottom']]

Expand All @@ -97,7 +98,9 @@ class AtBat(object):
b3
batter
des
des_es
event
event_es
event_num
home_team_runs
num
Expand Down Expand Up @@ -142,7 +145,7 @@ def __str__(self):
return self.nice_output()


class Pitch(object):
class Pitch(mlbgame.object.Object):
"""Class that holds information about individual pitches.
Properties:
Expand All @@ -153,26 +156,6 @@ class Pitch(object):
type
"""

def __init__(self, data):
"""Creates a pitch object that matches the corresponding info in `data`.
`data` should be a dictionary of values.
"""
# loop through data
for x in data:
# remove spanish info (causes text encoding errors)
if '_es' in x:
continue
# set information as correct data type
try:
setattr(self, x, int(data[x]))
except ValueError:
try:
setattr(self, x, float(data[x]))
except ValueError:
# string if not number
setattr(self, x, str(data[x]))

def nice_output(self):
"""Prints basic event info in a nice way."""
return 'Pitch: {0} at {1}: {2}'.format(
Expand Down

0 comments on commit 68ec906

Please sign in to comment.