{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-11-03T02:59:22.957920Z","iopub.execute_input":"2021-11-03T02:59:22.958315Z","iopub.status.idle":"2021-11-03T02:59:22.988754Z","shell.execute_reply.started":"2021-11-03T02:59:22.958219Z","shell.execute_reply":"2021-11-03T02:59:22.987582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Notebook tasks\n\n- create grid for field\n- add any field markings that my be relevant\n- plot every player at a given time\n- plot representations of player speed, angle, etc if necessary","metadata":{}},{"cell_type":"code","source":"track_test = pd.read_csv(\"/kaggle/input/nfl-big-data-bowl-2022/tracking2018.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-11-03T02:59:22.990515Z","iopub.execute_input":"2021-11-03T02:59:22.990943Z","iopub.status.idle":"2021-11-03T02:59:58.941758Z","shell.execute_reply.started":"2021-11-03T02:59:22.990915Z","shell.execute_reply":"2021-11-03T02:59:58.940977Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"track_test.head()","metadata":{"execution":{"iopub.status.busy":"2021-11-03T02:59:58.943003Z","iopub.execute_input":"2021-11-03T02:59:58.944025Z","iopub.status.idle":"2021-11-03T02:59:58.976418Z","shell.execute_reply.started":"2021-11-03T02:59:58.943975Z","shell.execute_reply":"2021-11-03T02:59:58.975569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_test = track_test.loc[(track_test['gameId'] == 2018123000) & (track_test['playId'] == 36)]","metadata":{"execution":{"iopub.status.busy":"2021-11-03T02:59:58.977979Z","iopub.execute_input":"2021-11-03T02:59:58.978153Z","iopub.status.idle":"2021-11-03T02:59:59.020658Z","shell.execute_reply.started":"2021-11-03T02:59:58.978132Z","shell.execute_reply":"2021-11-03T02:59:59.019645Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_test.shape","metadata":{"execution":{"iopub.status.busy":"2021-11-03T02:59:59.021948Z","iopub.execute_input":"2021-11-03T02:59:59.022124Z","iopub.status.idle":"2021-11-03T02:59:59.027737Z","shell.execute_reply.started":"2021-11-03T02:59:59.022101Z","shell.execute_reply":"2021-11-03T02:59:59.026950Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib as mlp\nimport matplotlib.pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2021-11-03T02:59:59.167834Z","iopub.execute_input":"2021-11-03T02:59:59.168851Z","iopub.status.idle":"2021-11-03T02:59:59.181084Z","shell.execute_reply.started":"2021-11-03T02:59:59.168782Z","shell.execute_reply":"2021-11-03T02:59:59.180235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_frame2 = play_test.loc[(play_test['time'] == '2018-12-30T21:25:38.900')]\nplay_frame2['team'] = (play_frame2['team'] != 'home').astype(int)\nx = play_frame2['x']\ny = play_frame2['y']\ncolor = play_frame2['team']","metadata":{"execution":{"iopub.status.busy":"2021-11-03T02:59:59.182117Z","iopub.execute_input":"2021-11-03T02:59:59.182887Z","iopub.status.idle":"2021-11-03T02:59:59.199943Z","shell.execute_reply.started":"2021-11-03T02:59:59.182847Z","shell.execute_reply":"2021-11-03T02:59:59.198910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# general plot of field\n\nfig, ax = plt.subplots(figsize=(12, 6))\n\nplt.xlim([0, 120])\nplt.ylim([0, 53.3])\n\nplt.axvline(x=10, c='r')\nplt.axvline(x=20, c='k')\nplt.axvline(x=30, c='k')\nplt.axvline(x=40, c='k')\nplt.axvline(x=50, c='k')\nplt.axvline(x=60, c='g')\nplt.axvline(x=70, c='k')\nplt.axvline(x=80, c='k')\nplt.axvline(x=90, c='k')\nplt.axvline(x=100, c='k')\nplt.axvline(x=110, c='r')\n\nplt.scatter(x,y, c=color)","metadata":{"execution":{"iopub.status.busy":"2021-11-03T02:59:59.201471Z","iopub.execute_input":"2021-11-03T02:59:59.201744Z","iopub.status.idle":"2021-11-03T02:59:59.400846Z","shell.execute_reply.started":"2021-11-03T02:59:59.201707Z","shell.execute_reply":"2021-11-03T02:59:59.399892Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\n\npx.scatter(play_test, x='x', y='y', animation_frame='time', color='team', range_x=[0, 120], range_y=[0, 53.3])","metadata":{"execution":{"iopub.status.busy":"2021-11-03T03:24:54.209045Z","iopub.execute_input":"2021-11-03T03:24:54.209282Z","iopub.status.idle":"2021-11-03T03:24:55.278335Z","shell.execute_reply.started":"2021-11-03T03:24:54.209256Z","shell.execute_reply":"2021-11-03T03:24:55.277701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def play_plotter(season_df, gameID, playID):\n    \n    play = season_df.loc[(season_df['gameId'] == gameID) & (track_test['playId'] == playID)]\n    \n    return px.scatter(play, x='x', y='y', animation_frame='time', color='team', range_x=[0, 120], range_y=[0, 53.3])","metadata":{"execution":{"iopub.status.busy":"2021-11-03T03:38:11.508731Z","iopub.execute_input":"2021-11-03T03:38:11.509024Z","iopub.status.idle":"2021-11-03T03:38:11.515434Z","shell.execute_reply.started":"2021-11-03T03:38:11.508993Z","shell.execute_reply":"2021-11-03T03:38:11.514575Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"play_plotter(track_test, 2018123000, 36)","metadata":{"execution":{"iopub.status.busy":"2021-11-03T03:38:14.430352Z","iopub.execute_input":"2021-11-03T03:38:14.430864Z","iopub.status.idle":"2021-11-03T03:38:15.359116Z","shell.execute_reply.started":"2021-11-03T03:38:14.430837Z","shell.execute_reply":"2021-11-03T03:38:15.358174Z"},"trusted":true},"execution_count":null,"outputs":[]}]}