load in data from csv now operational
Browse files- nba_tracking_data_15_16.py +11 -0
nba_tracking_data_15_16.py
CHANGED
@@ -22,6 +22,8 @@ import py7zr
|
|
22 |
import datasets
|
23 |
import requests
|
24 |
|
|
|
|
|
25 |
|
26 |
_CITATION = """\
|
27 |
@misc{Linou2016,
|
@@ -39,6 +41,7 @@ By merging all .7z files into one large .json file, access is easier to retrieve
|
|
39 |
|
40 |
_HOMEPAGE = "https://github.com/linouk23/NBA-Player-Movements/tree/master/"
|
41 |
_URL = "https://github.com/linouk23/NBA-Player-Movements/raw/master/data/2016.NBA.Raw.SportVU.Game.Logs"
|
|
|
42 |
|
43 |
res = requests.get(_URL)
|
44 |
|
@@ -54,6 +57,7 @@ class NbaTracking(datasets.GeneratorBasedBuilder):
|
|
54 |
"""Tracking data for all games of 2015-2016 season in forms of coordinates for players and ball at each moment."""
|
55 |
|
56 |
_URLS = _URLS
|
|
|
57 |
|
58 |
def _info(self):
|
59 |
features = datasets.Features(
|
@@ -156,14 +160,21 @@ class NbaTracking(datasets.GeneratorBasedBuilder):
|
|
156 |
def _generate_examples(self, filepaths, split):
|
157 |
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
158 |
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
|
|
|
|
|
|
159 |
moment_id = 0
|
|
|
160 |
for game_title, link in filepaths.items():
|
161 |
with open(link, encoding="utf-8") as fp:
|
162 |
game = json.load(fp)
|
163 |
game_id = game["gameid"]
|
164 |
game_date = game["gamedate"]
|
|
|
165 |
for event in game["events"]:
|
166 |
event_id = event["eventId"]
|
|
|
|
|
167 |
|
168 |
visitor_name = event['visitor']['name']
|
169 |
visitor_team_id = event['visitor']['teamid']
|
|
|
22 |
import datasets
|
23 |
import requests
|
24 |
|
25 |
+
import pandas as pd
|
26 |
+
|
27 |
|
28 |
_CITATION = """\
|
29 |
@misc{Linou2016,
|
|
|
41 |
|
42 |
_HOMEPAGE = "https://github.com/linouk23/NBA-Player-Movements/tree/master/"
|
43 |
_URL = "https://github.com/linouk23/NBA-Player-Movements/raw/master/data/2016.NBA.Raw.SportVU.Game.Logs"
|
44 |
+
_PBP_URL = "https://github.com/sumitrodatta/nba-alt-awards/raw/main/Historical/PBP%20Data/2015-16_pbp.csv"
|
45 |
|
46 |
res = requests.get(_URL)
|
47 |
|
|
|
57 |
"""Tracking data for all games of 2015-2016 season in forms of coordinates for players and ball at each moment."""
|
58 |
|
59 |
_URLS = _URLS
|
60 |
+
_PBP_URL = _PBP_URL
|
61 |
|
62 |
def _info(self):
|
63 |
features = datasets.Features(
|
|
|
160 |
def _generate_examples(self, filepaths, split):
|
161 |
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
162 |
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
163 |
+
pbp_out = dl_manager.download_and_extract(_PBP_URL)
|
164 |
+
pbp = pd.read_csv(pbp_out)
|
165 |
+
|
166 |
moment_id = 0
|
167 |
+
|
168 |
for game_title, link in filepaths.items():
|
169 |
with open(link, encoding="utf-8") as fp:
|
170 |
game = json.load(fp)
|
171 |
game_id = game["gameid"]
|
172 |
game_date = game["gamedate"]
|
173 |
+
|
174 |
for event in game["events"]:
|
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']
|