{"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)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\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":"2022-08-30T03:46:03.562827Z","iopub.execute_input":"2022-08-30T03:46:03.563338Z","iopub.status.idle":"2022-08-30T03:46:04.295592Z","shell.execute_reply.started":"2022-08-30T03:46:03.563235Z","shell.execute_reply":"2022-08-30T03:46:04.294131Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"../input/big-data-derby-2022/nyra_start_table.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:04.298078Z","iopub.execute_input":"2022-08-30T03:46:04.299463Z","iopub.status.idle":"2022-08-30T03:46:04.343784Z","shell.execute_reply.started":"2022-08-30T03:46:04.299405Z","shell.execute_reply":"2022-08-30T03:46:04.342722Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.isna().sum(axis=0)/len(df)","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:04.345611Z","iopub.execute_input":"2022-08-30T03:46:04.346682Z","iopub.status.idle":"2022-08-30T03:46:04.367808Z","shell.execute_reply.started":"2022-08-30T03:46:04.346630Z","shell.execute_reply":"2022-08-30T03:46:04.366786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:04.370242Z","iopub.execute_input":"2022-08-30T03:46:04.370914Z","iopub.status.idle":"2022-08-30T03:46:04.402652Z","shell.execute_reply.started":"2022-08-30T03:46:04.370875Z","shell.execute_reply":"2022-08-30T03:46:04.401440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(df.isna(),cbar=False,cmap=\"binary\")","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:04.404036Z","iopub.execute_input":"2022-08-30T03:46:04.404937Z","iopub.status.idle":"2022-08-30T03:46:04.932598Z","shell.execute_reply.started":"2022-08-30T03:46:04.404900Z","shell.execute_reply":"2022-08-30T03:46:04.931324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.histplot(data = df,x=\"weight_carried\")","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:04.934535Z","iopub.execute_input":"2022-08-30T03:46:04.935299Z","iopub.status.idle":"2022-08-30T03:46:05.465499Z","shell.execute_reply.started":"2022-08-30T03:46:04.935249Z","shell.execute_reply":"2022-08-30T03:46:05.464273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.boxplot(data=df,x=\"weight_carried\")","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.467239Z","iopub.execute_input":"2022-08-30T03:46:05.467935Z","iopub.status.idle":"2022-08-30T03:46:05.665408Z","shell.execute_reply.started":"2022-08-30T03:46:05.467897Z","shell.execute_reply":"2022-08-30T03:46:05.664018Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## AQU stands for aqueduct stadium ","metadata":{}},{"cell_type":"code","source":"sns.boxplot(data=df[df['track_id']=='AQU'],x=\"weight_carried\")","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.667174Z","iopub.execute_input":"2022-08-30T03:46:05.667630Z","iopub.status.idle":"2022-08-30T03:46:05.863026Z","shell.execute_reply.started":"2022-08-30T03:46:05.667589Z","shell.execute_reply":"2022-08-30T03:46:05.861764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data=df[df['track_id']=='AQU']['weight_carried']","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.866869Z","iopub.execute_input":"2022-08-30T03:46:05.867372Z","iopub.status.idle":"2022-08-30T03:46:05.876647Z","shell.execute_reply.started":"2022-08-30T03:46:05.867336Z","shell.execute_reply":"2022-08-30T03:46:05.875454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.881950Z","iopub.execute_input":"2022-08-30T03:46:05.882765Z","iopub.status.idle":"2022-08-30T03:46:05.897846Z","shell.execute_reply.started":"2022-08-30T03:46:05.882712Z","shell.execute_reply":"2022-08-30T03:46:05.896644Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.nunique()","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.900175Z","iopub.execute_input":"2022-08-30T03:46:05.901458Z","iopub.status.idle":"2022-08-30T03:46:05.926806Z","shell.execute_reply.started":"2022-08-30T03:46:05.901408Z","shell.execute_reply":"2022-08-30T03:46:05.925855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(df['track_id'].values)","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.928306Z","iopub.execute_input":"2022-08-30T03:46:05.928906Z","iopub.status.idle":"2022-08-30T03:46:05.942980Z","shell.execute_reply.started":"2022-08-30T03:46:05.928874Z","shell.execute_reply":"2022-08-30T03:46:05.941874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AQU_perc = len(df[df['track_id']==\"AQU\"])/len(df)\nAQU_perc","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.945261Z","iopub.execute_input":"2022-08-30T03:46:05.945927Z","iopub.status.idle":"2022-08-30T03:46:05.956116Z","shell.execute_reply.started":"2022-08-30T03:46:05.945889Z","shell.execute_reply":"2022-08-30T03:46:05.955039Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BEL_perc = len(df[df['track_id']==\"BEL\"])/len(df)\nBEL_perc","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.957772Z","iopub.execute_input":"2022-08-30T03:46:05.958628Z","iopub.status.idle":"2022-08-30T03:46:05.971745Z","shell.execute_reply.started":"2022-08-30T03:46:05.958583Z","shell.execute_reply":"2022-08-30T03:46:05.970260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAR_perc = len(df[df['track_id']==\"SAR\"])/len(df)\nSAR_perc","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.973724Z","iopub.execute_input":"2022-08-30T03:46:05.974607Z","iopub.status.idle":"2022-08-30T03:46:05.987478Z","shell.execute_reply.started":"2022-08-30T03:46:05.974561Z","shell.execute_reply":"2022-08-30T03:46:05.986252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_race = pd.read_csv(\"../input/big-data-derby-2022/nyra_race_table.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:05.989106Z","iopub.execute_input":"2022-08-30T03:46:05.990584Z","iopub.status.idle":"2022-08-30T03:46:06.011825Z","shell.execute_reply.started":"2022-08-30T03:46:05.990537Z","shell.execute_reply":"2022-08-30T03:46:06.010547Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"raw","source":"df_race","metadata":{}},{"cell_type":"code","source":"df_race","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:06.013491Z","iopub.execute_input":"2022-08-30T03:46:06.014685Z","iopub.status.idle":"2022-08-30T03:46:06.044944Z","shell.execute_reply.started":"2022-08-30T03:46:06.014638Z","shell.execute_reply":"2022-08-30T03:46:06.043780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race_types = np.unique(df_race['race_type'].values)","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:06.047980Z","iopub.execute_input":"2022-08-30T03:46:06.048912Z","iopub.status.idle":"2022-08-30T03:46:06.055734Z","shell.execute_reply.started":"2022-08-30T03:46:06.048874Z","shell.execute_reply":"2022-08-30T03:46:06.054379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in race_types:\n    print(i)","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:06.057559Z","iopub.execute_input":"2022-08-30T03:46:06.058352Z","iopub.status.idle":"2022-08-30T03:46:06.070953Z","shell.execute_reply.started":"2022-08-30T03:46:06.058306Z","shell.execute_reply":"2022-08-30T03:46:06.069378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race_type_perc = {}\nfor i in race_types:\n     race_type_perc[i] = len(df_race[df_race['race_type']==i])/len(df_race)\n","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:06.072962Z","iopub.execute_input":"2022-08-30T03:46:06.073463Z","iopub.status.idle":"2022-08-30T03:46:06.096585Z","shell.execute_reply.started":"2022-08-30T03:46:06.073417Z","shell.execute_reply":"2022-08-30T03:46:06.095265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"race_type_perc","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:06.098800Z","iopub.execute_input":"2022-08-30T03:46:06.099573Z","iopub.status.idle":"2022-08-30T03:46:06.108204Z","shell.execute_reply.started":"2022-08-30T03:46:06.099526Z","shell.execute_reply":"2022-08-30T03:46:06.106705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.bar(race_type_perc.keys(),race_type_perc.values())","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:06.110126Z","iopub.execute_input":"2022-08-30T03:46:06.110852Z","iopub.status.idle":"2022-08-30T03:46:06.356863Z","shell.execute_reply.started":"2022-08-30T03:46:06.110805Z","shell.execute_reply":"2022-08-30T03:46:06.355685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_track = pd.read_csv(\"../input/big-data-derby-2022/nyra_tracking_table.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:06.358711Z","iopub.execute_input":"2022-08-30T03:46:06.359441Z","iopub.status.idle":"2022-08-30T03:46:13.671446Z","shell.execute_reply.started":"2022-08-30T03:46:06.359395Z","shell.execute_reply":"2022-08-30T03:46:13.670022Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_track['race_date'] = pd.to_datetime(df_track['race_date'])\n","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:13.672942Z","iopub.execute_input":"2022-08-30T03:46:13.673348Z","iopub.status.idle":"2022-08-30T03:46:14.651859Z","shell.execute_reply.started":"2022-08-30T03:46:13.673312Z","shell.execute_reply":"2022-08-30T03:46:14.650702Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_track.info()","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:14.653413Z","iopub.execute_input":"2022-08-30T03:46:14.653854Z","iopub.status.idle":"2022-08-30T03:46:14.665776Z","shell.execute_reply.started":"2022-08-30T03:46:14.653821Z","shell.execute_reply":"2022-08-30T03:46:14.664565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_track_1 = df_track.query(\"race_number == 9\")\ndf_track_1 = df_track_1[df_track_1['race_date']==\"2019-01-01\"]\n# plt.style.use(\"dark_background\")\n# plt.figure(figsize = (16, 8))\n# sns.scatterplot(data = nyra_tracking1, x = \"longitude\", y = \"latitude\", hue = \"program_number\", palette = \"Paired\")\n\n# plt.title(\"track_id = AQU, Longitude and Latitude by Race Number\")\n# plt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:14.667432Z","iopub.execute_input":"2022-08-30T03:46:14.668123Z","iopub.status.idle":"2022-08-30T03:46:14.802278Z","shell.execute_reply.started":"2022-08-30T03:46:14.668079Z","shell.execute_reply":"2022-08-30T03:46:14.800695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_track_1","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:14.804207Z","iopub.execute_input":"2022-08-30T03:46:14.805328Z","iopub.status.idle":"2022-08-30T03:46:14.835838Z","shell.execute_reply.started":"2022-08-30T03:46:14.805262Z","shell.execute_reply":"2022-08-30T03:46:14.834216Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(df_track_1.program_number.values)","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:14.840946Z","iopub.execute_input":"2022-08-30T03:46:14.841467Z","iopub.status.idle":"2022-08-30T03:46:14.851338Z","shell.execute_reply.started":"2022-08-30T03:46:14.841430Z","shell.execute_reply":"2022-08-30T03:46:14.850062Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20, 10))\n\nsns.scatterplot(data = df_track_1, x = \"longitude\", y = \"latitude\", hue = \"program_number\", palette = \"Paired\")\nplt.title(\"track_id = AQU, Longitude and Latitude by Race Number\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:14.853383Z","iopub.execute_input":"2022-08-30T03:46:14.853780Z","iopub.status.idle":"2022-08-30T03:46:15.585056Z","shell.execute_reply.started":"2022-08-30T03:46:14.853729Z","shell.execute_reply":"2022-08-30T03:46:15.584122Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"scrolled":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (20, 10))\n\nsns.scatterplot(data = df_track_1, x = \"longitude\", y = \"latitude\", hue = \"program_number\", palette = \"Paired\")\nplt.title(\"track_id = AQU, Longitude and Latitude by Race Number\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:46:15.586460Z","iopub.execute_input":"2022-08-30T03:46:15.587388Z","iopub.status.idle":"2022-08-30T03:46:16.302580Z","shell.execute_reply.started":"2022-08-30T03:46:15.587350Z","shell.execute_reply":"2022-08-30T03:46:16.301359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(df_track_1.trakus_index.values)","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:47:08.108318Z","iopub.execute_input":"2022-08-30T03:47:08.108727Z","iopub.status.idle":"2022-08-30T03:47:08.118319Z","shell.execute_reply.started":"2022-08-30T03:47:08.108695Z","shell.execute_reply":"2022-08-30T03:47:08.116889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_track_1[df_track_1.trakus_index == 1]","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:47:56.411281Z","iopub.execute_input":"2022-08-30T03:47:56.412388Z","iopub.status.idle":"2022-08-30T03:47:56.429961Z","shell.execute_reply.started":"2022-08-30T03:47:56.412338Z","shell.execute_reply":"2022-08-30T03:47:56.428771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Finding timing using trakus_index (index is every 0.25 second)","metadata":{}},{"cell_type":"code","source":"df_track_index = df_track_1[[\"program_number\",\"trakus_index\"]].groupby(['program_number']).max()","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:50:57.405758Z","iopub.execute_input":"2022-08-30T03:50:57.406171Z","iopub.status.idle":"2022-08-30T03:50:57.420364Z","shell.execute_reply.started":"2022-08-30T03:50:57.406123Z","shell.execute_reply":"2022-08-30T03:50:57.419368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_track_index","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:51:10.331981Z","iopub.execute_input":"2022-08-30T03:51:10.332415Z","iopub.status.idle":"2022-08-30T03:51:10.342049Z","shell.execute_reply.started":"2022-08-30T03:51:10.332379Z","shell.execute_reply":"2022-08-30T03:51:10.341002Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nplt.figure(figsize = (20, 10))\n\nsns.scatter3D(data = df_track_1, x = \"longitude\", y = \"latitude\",z = \"trakus_index\", hue = \"program_number\", palette = \"Paired\")\nplt.title(\"track_id = AQU, Longitude and Latitude by Race Number\")\nplt.legend()","metadata":{"execution":{"iopub.status.busy":"2022-08-30T03:58:05.961866Z","iopub.execute_input":"2022-08-30T03:58:05.962307Z","iopub.status.idle":"2022-08-30T03:58:05.986994Z","shell.execute_reply.started":"2022-08-30T03:58:05.962268Z","shell.execute_reply":"2022-08-30T03:58:05.985784Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(6,5))\naxes = plt.axes(projection='3d')\nprint(type(axes))\naxes.scatter3D(df_track_1['longitude'],df_track_1['latitude'],df_track_1['trakus_index'])\n\naxes.set_xlabel('x')\naxes.set_ylabel('y')\naxes.set_zlabel('z')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-08-30T04:00:47.815445Z","iopub.execute_input":"2022-08-30T04:00:47.815858Z","iopub.status.idle":"2022-08-30T04:00:48.114586Z","shell.execute_reply.started":"2022-08-30T04:00:47.815824Z","shell.execute_reply":"2022-08-30T04:00:48.113251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\n","metadata":{"execution":{"iopub.status.busy":"2022-08-30T04:09:15.167968Z","iopub.execute_input":"2022-08-30T04:09:15.168352Z","iopub.status.idle":"2022-08-30T04:09:16.248907Z","shell.execute_reply.started":"2022-08-30T04:09:15.168321Z","shell.execute_reply":"2022-08-30T04:09:16.247704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter_3d(df_track_1, x='latitude', y='longitude', z='trakus_index',\n              color='program_number')\nfig.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-08-30T04:09:22.785047Z","iopub.execute_input":"2022-08-30T04:09:22.785497Z","iopub.status.idle":"2022-08-30T04:09:23.051180Z","shell.execute_reply.started":"2022-08-30T04:09:22.785459Z","shell.execute_reply":"2022-08-30T04:09:23.049945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Trakus index observation: \n1. Every horse has 297 index no. at the end the one closest to it latitude maybe the once closest to the end line\n2. The horse doesn't speed up at the start( trakus index was increading lat/lon value were not changing","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}