dcayton commited on
Commit
07b35ae
1 Parent(s): 06015f0

update to include play-by-play

Browse files
Files changed (1) hide show
  1. nba_tracking_data_15_16.py +29 -0
nba_tracking_data_15_16.py CHANGED
@@ -53,6 +53,18 @@ for game in items[0:2]:
53
  name = game['name'][:-3]
54
  _URLS[name] = _URL + "/" + name + ".7z"
55
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  class NbaTracking(datasets.GeneratorBasedBuilder):
57
  """Tracking data for all games of 2015-2016 season in forms of coordinates for players and ball at each moment."""
58
 
@@ -175,6 +187,23 @@ class NbaTracking(datasets.GeneratorBasedBuilder):
175
  event_id = event["eventId"]
176
 
177
  event_row = pbp[(pbp.GAME_ID == int(game_id)) & (pbp.EVENTNUM == int(event_id))]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
  visitor_name = event['visitor']['name']
180
  visitor_team_id = event['visitor']['teamid']
 
53
  name = game['name'][:-3]
54
  _URLS[name] = _URL + "/" + name + ".7z"
55
 
56
+ def identify_offense(row):
57
+ identified_offense_events = [1, 2, 3, 4, 5]
58
+ if row['EVENTMSGTYPE'] in identified_offense_events:
59
+ poss_team_id = row['PLAYER1_TEAM_ID']
60
+ elif ("OFF.FOUL" in row["HOMEDESCRIPTION"]) or ("OFF.FOUL" in row["AWAYDESCRIPTION"]):
61
+ poss_team_id = row['PLAYER1_TEAM_ID']
62
+ elif row['EVENTMSGTYPE'] == 6:
63
+ poss_team_id = row['PLAYER2_TEAM_ID']
64
+ else:
65
+ poss_team_id = None
66
+ return poss_team_id
67
+
68
  class NbaTracking(datasets.GeneratorBasedBuilder):
69
  """Tracking data for all games of 2015-2016 season in forms of coordinates for players and ball at each moment."""
70
 
 
187
  event_id = event["eventId"]
188
 
189
  event_row = pbp[(pbp.GAME_ID == int(game_id)) & (pbp.EVENTNUM == int(event_id))]
190
+
191
+
192
+ event_type = event_row["EVENTMSGTYPE"]
193
+
194
+ event_home_desc = event_row["HOMEDESCRIPTION"]
195
+
196
+ event_away_desc = event_row["AWAYDESCRIPTION"]
197
+
198
+ primary_home_away = event_row["PERSON1TYPE"]
199
+ primary_player_id = event_row["PLAYER1_ID"]
200
+ primary_team_id = event_row["PLAYER1_TEAM_ID"]
201
+
202
+ secondary_home_away = event_row["PERSON2TYPE"]
203
+ secondary_player_id = event_row["PLAYER2_ID"]
204
+ secondary_team_id = event_row["PLAYER2_TEAM_ID"]
205
+
206
+ poss_team_id = identify_offense(event_row)
207
 
208
  visitor_name = event['visitor']['name']
209
  visitor_team_id = event['visitor']['teamid']