{"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":"import numpy as np\nimport pandas as pd\nimport plotly.graph_objects as go","metadata":{"execution":{"iopub.status.busy":"2022-10-07T15:32:31.316251Z","iopub.execute_input":"2022-10-07T15:32:31.316724Z","iopub.status.idle":"2022-10-07T15:32:31.359446Z","shell.execute_reply.started":"2022-10-07T15:32:31.316629Z","shell.execute_reply":"2022-10-07T15:32:31.358170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(\"../input/tabular-playground-series-oct-2022/train_0.csv\")\ndf = df[0:100]","metadata":{"execution":{"iopub.status.busy":"2022-10-07T15:32:31.361583Z","iopub.execute_input":"2022-10-07T15:32:31.361975Z","iopub.status.idle":"2022-10-07T15:33:08.576678Z","shell.execute_reply.started":"2022-10-07T15:32:31.361939Z","shell.execute_reply":"2022-10-07T15:33:08.575668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.columns","metadata":{"execution":{"iopub.status.busy":"2022-10-07T15:33:08.577898Z","iopub.execute_input":"2022-10-07T15:33:08.578214Z","iopub.status.idle":"2022-10-07T15:33:08.588626Z","shell.execute_reply.started":"2022-10-07T15:33:08.578185Z","shell.execute_reply":"2022-10-07T15:33:08.587457Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"event_df = df[['game_num', 'event_id', 'event_time']]\n\nball_df = df[['ball_pos_x', 'ball_pos_y', 'ball_pos_z', 'ball_vel_x', 'ball_vel_y', 'ball_vel_z']]\n\nboost_df = df[['boost0_timer', 'boost1_timer', 'boost2_timer', 'boost3_timer', 'boost4_timer', 'boost5_timer']]\n\nscore_df = df[['player_scoring_next', 'team_scoring_next', 'team_A_scoring_within_10sec', 'team_B_scoring_within_10sec']]\n\np0_df = df[['p0_pos_x', 'p0_pos_y', 'p0_pos_z', 'p0_vel_x', 'p0_vel_y', 'p0_vel_z', 'p0_boost']]\np1_df = df[['p1_pos_x', 'p1_pos_y', 'p1_pos_z', 'p1_vel_x', 'p1_vel_y', 'p1_vel_z', 'p1_boost']]\np2_df = df[['p2_pos_x', 'p2_pos_y', 'p2_pos_z', 'p2_vel_x', 'p2_vel_y', 'p2_vel_z', 'p2_boost']]\np3_df = df[['p3_pos_x', 'p3_pos_y', 'p3_pos_z', 'p3_vel_x', 'p3_vel_y', 'p3_vel_z', 'p3_boost']]\np4_df = df[['p4_pos_x', 'p4_pos_y', 'p4_pos_z', 'p4_vel_x', 'p4_vel_y', 'p4_vel_z', 'p4_boost']]\np5_df = df[['p5_pos_x', 'p5_pos_y', 'p5_pos_z', 'p5_vel_x', 'p5_vel_y', 'p5_vel_z', 'p5_boost']]\n\nplayers_DF = df[['p0_pos_x', 'p0_pos_y', 'p0_pos_z',  \n                 'p1_pos_x', 'p1_pos_y', 'p1_pos_z',  \n                 'p2_pos_x', 'p2_pos_y', 'p2_pos_z',  \n                 'p3_pos_x', 'p3_pos_y', 'p3_pos_z',  \n                 'p4_pos_x', 'p4_pos_y', 'p4_pos_z',  \n                 'p5_pos_x', 'p5_pos_y', 'p5_pos_z']]\n","metadata":{"execution":{"iopub.status.busy":"2022-10-07T15:33:08.591234Z","iopub.execute_input":"2022-10-07T15:33:08.592399Z","iopub.status.idle":"2022-10-07T15:33:08.616440Z","shell.execute_reply.started":"2022-10-07T15:33:08.592350Z","shell.execute_reply":"2022-10-07T15:33:08.615411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"p0_x, p0_y, p0_z = p0_df.p0_pos_x, p0_df.p0_pos_y, p0_df.p0_pos_z\np1_x, p1_y, p1_z = p1_df.p1_pos_x, p1_df.p1_pos_y, p1_df.p1_pos_z\np2_x, p2_y, p2_z = p2_df.p2_pos_x, p2_df.p2_pos_y, p2_df.p2_pos_z\np3_x, p3_y, p3_z = p3_df.p3_pos_x, p3_df.p3_pos_y, p3_df.p3_pos_z\np4_x, p4_y, p4_z = p4_df.p4_pos_x, p4_df.p4_pos_y, p4_df.p4_pos_z\np5_x, p5_y, p5_z = p5_df.p5_pos_x, p5_df.p5_pos_y, p5_df.p5_pos_z\n\nfig = go.Figure(\n    data=[go.Scatter3d(x=[], y=[], z=[])],\n    \n    \n    frames=[go.Frame(data=[go.Scatter3d(x=[p0_x[idx], p1_x[idx], p2_x[idx], p3_x[idx], p4_x[idx], p5_x[idx]], \n                                        y=[p0_y[idx], p1_y[idx], p2_y[idx], p3_y[idx], p4_y[idx], p5_y[idx]],\n                                        z=[p0_z[idx], p1_z[idx], p2_z[idx], p3_z[idx], p4_z[idx], p5_z[idx]])],\n                           name=f'frame{idx}') \n                           for idx in range(len(p0_x))]) \n\nfig.update(frames=fig.frames)\n\ndef frame_args(duration):\n    return {\n            \"frame\": {\"duration\": duration},\n            \"mode\": \"immediate\",\n            \"fromcurrent\": True,\n            \"transition\": {\"duration\": duration, \"easing\": \"linear\"},\n            }\n\n\nsliders = [\n    {\"pad\": {\"b\": 10, \"t\": 60},\n     \"len\": 0.9,\n     \"x\": 0.1,\n     \"y\": 0,\n     \n     \"steps\": [\n                 {\"args\": [[f.name], frame_args(0)],\n                  \"label\": str(k),\n                  \"method\": \"animate\",\n                  } for k, f in enumerate(fig.frames)\n              ]\n     }\n        ]\n\nfig.update_layout(\n\n    updatemenus = [{\"buttons\":[\n                    {\n                        \"args\": [None, frame_args(200)],\n                        \"label\": \"Play\", \n                        \"method\": \"animate\",\n                    },\n                    {\n                        \"args\": [[None], frame_args(0)],\n                        \"label\": \"Pause\", \n                        \"method\": \"animate\",\n                  }],\n                    \n                \"direction\": \"left\",\n                \"pad\": {\"r\": 10, \"t\": 70},\n                \"type\": \"buttons\",\n                \"x\": 0.1,\n                \"y\": 0,\n            }\n         ],\n         sliders=sliders\n    )\n\nfig.update_layout(scene = dict(xaxis=dict(range=[-100, 100], autorange=False),\n                               yaxis=dict(range=[-100, 100], autorange=False),\n                               zaxis=dict(range=[0, 40], autorange=False)\n                               )\n                  )\n\nfig.update_layout(\n    template=\"plotly_dark\",\n    height=700,\n    width=1400,\n    title=\"Protein representation by elements\",\n    font = dict(family = \"Sans seriff\", size = 14, color = \"#E0FFFF\"))\n\n\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-07T15:33:08.618204Z","iopub.execute_input":"2022-10-07T15:33:08.618688Z","iopub.status.idle":"2022-10-07T15:33:09.963193Z","shell.execute_reply.started":"2022-10-07T15:33:08.618641Z","shell.execute_reply":"2022-10-07T15:33:09.962308Z"},"trusted":true},"execution_count":null,"outputs":[]}]}