dcayton commited on
Commit
c700dd0
1 Parent(s): 22ff455

updated loading structure

Browse files
Files changed (1) hide show
  1. nba_tracking_data_15_16.py +42 -6
nba_tracking_data_15_16.py CHANGED
@@ -53,6 +53,14 @@ for game in items[0:2]:
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:
@@ -76,7 +84,20 @@ class NbaTracking(datasets.GeneratorBasedBuilder):
76
  {
77
  "gameid": datasets.Value("string"),
78
  "gamedate": datasets.Value("string"),
79
- "eventid": datasets.Value("string"),
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  "visitor": {
81
  "name": datasets.Value("string"),
82
  "teamid": datasets.Value("int64"),
@@ -172,8 +193,7 @@ class NbaTracking(datasets.GeneratorBasedBuilder):
172
  def _generate_examples(self, filepaths, split):
173
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
174
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
175
- dl_manager = DownloadManager()
176
- pbp_out = dl_manager.download_and_extract(_PBP_URL)
177
  pbp = pd.read_csv(pbp_out)
178
 
179
  moment_id = 0
@@ -196,11 +216,11 @@ class NbaTracking(datasets.GeneratorBasedBuilder):
196
 
197
  event_away_desc = event_row["AWAYDESCRIPTION"]
198
 
199
- primary_home_away = event_row["PERSON1TYPE"]
200
  primary_player_id = event_row["PLAYER1_ID"]
201
  primary_team_id = event_row["PLAYER1_TEAM_ID"]
202
 
203
- secondary_home_away = event_row["PERSON2TYPE"]
204
  secondary_player_id = event_row["PLAYER2_ID"]
205
  secondary_team_id = event_row["PLAYER2_TEAM_ID"]
206
 
@@ -241,7 +261,23 @@ class NbaTracking(datasets.GeneratorBasedBuilder):
241
  yield moment_id, {
242
  "gameid": game_id,
243
  "gamedate": game_date,
244
- "eventid": event_id,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  "visitor": {
246
  "name": visitor_name,
247
  "teamid": visitor_team_id,
 
53
  name = game['name'][:-3]
54
  _URLS[name] = _URL + "/" + name + ".7z"
55
 
56
+ def home_away_event_conversion(number):
57
+ if number == 4:
58
+ return "home"
59
+ elif number == 5:
60
+ return "away"
61
+ else:
62
+ return None
63
+
64
  def identify_offense(row):
65
  identified_offense_events = [1, 2, 3, 4, 5]
66
  if row['EVENTMSGTYPE'] in identified_offense_events:
 
84
  {
85
  "gameid": datasets.Value("string"),
86
  "gamedate": datasets.Value("string"),
87
+ "event_info": {"id": datasets.Value("string"),
88
+ "type": datasets.Value("int64"),
89
+ "possession_team_id": datasets.Value("int64"),
90
+ "desc_home": datasets.Value("string"),
91
+ "desc_away": datasets.Value("string")
92
+ },
93
+ "primary_info": {"team": datasets.Value("string"),
94
+ "player_id": datasets.Value("int64"),
95
+ "team_id": datasets.Value("int64")
96
+ },
97
+ "secondary_info": {"team": datasets.Value("string"),
98
+ "player_id": datasets.Value("int64"),
99
+ "team_id": datasets.Value("int64")
100
+ },
101
  "visitor": {
102
  "name": datasets.Value("string"),
103
  "teamid": datasets.Value("int64"),
 
193
  def _generate_examples(self, filepaths, split):
194
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
195
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
196
+ pbp_out = datasets.DownloadManager().download_and_extract(_PBP_URL)
 
197
  pbp = pd.read_csv(pbp_out)
198
 
199
  moment_id = 0
 
216
 
217
  event_away_desc = event_row["AWAYDESCRIPTION"]
218
 
219
+ primary_home_away = home_away_event_conversion(event_row["PERSON1TYPE"])
220
  primary_player_id = event_row["PLAYER1_ID"]
221
  primary_team_id = event_row["PLAYER1_TEAM_ID"]
222
 
223
+ secondary_home_away = home_away_event_conversion(event_row["PERSON2TYPE"])
224
  secondary_player_id = event_row["PLAYER2_ID"]
225
  secondary_team_id = event_row["PLAYER2_TEAM_ID"]
226
 
 
261
  yield moment_id, {
262
  "gameid": game_id,
263
  "gamedate": game_date,
264
+ "event_info": {
265
+ "id": event_id,
266
+ "type": event_type,
267
+ "possession_team_id": poss_team_id,
268
+ "desc_home": event_home_desc,
269
+ "desc_away": event_away_desc
270
+ },
271
+ "primary_info": {
272
+ "team": primary_home_away,
273
+ "player_id": primary_player_id,
274
+ "team_id": primary_team_id
275
+ },
276
+ "secondary_info": {
277
+ "team": secondary_home_away,
278
+ "player_id": secondary_player_id,
279
+ "team_id": secondary_team_id
280
+ },
281
  "visitor": {
282
  "name": visitor_name,
283
  "teamid": visitor_team_id,