dcayton commited on
Commit
c01c6e9
1 Parent(s): 0f62d2c

py7zr fix?

Browse files
Files changed (1) hide show
  1. nba_tracking_data_15_16.py +36 -35
nba_tracking_data_15_16.py CHANGED
@@ -175,44 +175,45 @@ class NbaTracking(datasets.GeneratorBasedBuilder):
175
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
176
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
177
  for link in filepath:
178
- with open(link, encoding="utf-8") as fp:
179
- game_id = json.load(fp)["gameid"]
180
- game_date = json.load(fp)["gamedate"]
181
- for event in json.load(fp)["events"]:
182
- event_id = event["eventId"]
183
- for moment in event["moments"]:
184
- for element in moment:
185
- quarter = element[0]
186
- game_clock = element[2]
187
- shot_clock = element[3]
188
- ball_coords = element[5][0][2:]
189
- for position in element[5][1:]:
190
- team_id = position[0]
191
- player_id = position[1]
192
- x = position[2]
193
- y = position[3]
194
- z = position[4]
195
-
196
- yield game_id, {
197
- "gameid": game_id,
198
- "gamedate": game_date,
199
- "events": {
200
- "eventid": event_id,
201
- "moments": {
202
- "quarter": quarter,
203
- "game_clock": game_clock,
204
- "shot_clock": shot_clock,
205
- "ball_coordinates": ball_coords,
206
- "player_coordinates": {
207
- "teamid": team_id,
208
- "playerid": player_id,
209
- "x": x,
210
- "y": y,
211
- "z": z
 
 
212
  }
213
  }
214
  }
215
- }
216
 
217
 
218
  # for key, row in enumerate(fp):
 
175
  # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
176
  # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
177
  for link in filepath:
178
+ with open(link, encoding="utf-8") as f:
179
+ with py7zr.SevenZipFile(f, "r") as fp:
180
+ game_id = json.load(fp)["gameid"]
181
+ game_date = json.load(fp)["gamedate"]
182
+ for event in json.load(fp)["events"]:
183
+ event_id = event["eventId"]
184
+ for moment in event["moments"]:
185
+ for element in moment:
186
+ quarter = element[0]
187
+ game_clock = element[2]
188
+ shot_clock = element[3]
189
+ ball_coords = element[5][0][2:]
190
+ for position in element[5][1:]:
191
+ team_id = position[0]
192
+ player_id = position[1]
193
+ x = position[2]
194
+ y = position[3]
195
+ z = position[4]
196
+
197
+ yield game_id, {
198
+ "gameid": game_id,
199
+ "gamedate": game_date,
200
+ "events": {
201
+ "eventid": event_id,
202
+ "moments": {
203
+ "quarter": quarter,
204
+ "game_clock": game_clock,
205
+ "shot_clock": shot_clock,
206
+ "ball_coordinates": ball_coords,
207
+ "player_coordinates": {
208
+ "teamid": team_id,
209
+ "playerid": player_id,
210
+ "x": x,
211
+ "y": y,
212
+ "z": z
213
+ }
214
  }
215
  }
216
  }
 
217
 
218
 
219
  # for key, row in enumerate(fp):