{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":60095,"databundleVersionId":6542333,"sourceType":"competition"},{"sourceId":6590022,"sourceType":"datasetVersion","datasetId":3795964}],"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Smartphone Decimeter: Activity Locations","metadata":{"papermill":{"duration":0.023455,"end_time":"2021-10-15T07:15:30.871323","exception":false,"start_time":"2021-10-15T07:15:30.847868","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import os\nimport numpy as np\nimport pandas as pd\nimport random\nimport folium\nfrom folium import plugins\nimport seaborn as sns\nimport cv2\nimport matplotlib.pyplot as plt\nimport IPython\nimport time\nimport plotly.express as px\nfrom mpl_toolkits.mplot3d import Axes3D\nfrom branca.colormap import linear","metadata":{"papermill":{"duration":3.207351,"end_time":"2021-10-15T07:15:34.18931","exception":false,"start_time":"2021-10-15T07:15:30.981959","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-23T17:05:22.869327Z","iopub.execute_input":"2024-02-23T17:05:22.869961Z","iopub.status.idle":"2024-02-23T17:05:22.879257Z","shell.execute_reply.started":"2024-02-23T17:05:22.869881Z","shell.execute_reply":"2024-02-23T17:05:22.877697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"paths=[]\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        if filename.endswith('.csv') and filename[0:6]=='ground':\n            paths+=[(os.path.join(dirname, filename))]","metadata":{"papermill":{"duration":0.097915,"end_time":"2021-10-15T07:15:34.311617","exception":false,"start_time":"2021-10-15T07:15:34.213702","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2024-02-23T17:05:22.882177Z","iopub.execute_input":"2024-02-23T17:05:22.882690Z","iopub.status.idle":"2024-02-23T17:05:23.494893Z","shell.execute_reply.started":"2024-02-23T17:05:22.882645Z","shell.execute_reply":"2024-02-23T17:05:23.493765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df=pd.read_csv(paths[0])\nprint(df.columns.tolist())","metadata":{"execution":{"iopub.status.busy":"2024-02-23T17:05:23.497338Z","iopub.execute_input":"2024-02-23T17:05:23.497750Z","iopub.status.idle":"2024-02-23T17:05:23.519073Z","shell.execute_reply.started":"2024-02-23T17:05:23.497714Z","shell.execute_reply":"2024-02-23T17:05:23.517800Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def rgb_to_hex(rgb):\n    hex_color = \"#{:02x}{:02x}{:02x}\".format(rgb[0], rgb[1], rgb[2])\n    return hex_color\n\n#color palette\ncluster_centers=np.load('/kaggle/input/color-palette/standard_color14.npy')\n\ncolors=[]\nfor i in range(14):\n    rgb_tuple=tuple(cluster_centers[i%14])\n    colors+=[rgb_to_hex(rgb_tuple)]\n\nN=list(range(len(colors)))\n    \nnormal_mapping=dict(zip(N,colors)) \nprint(normal_mapping)","metadata":{"execution":{"iopub.status.busy":"2024-02-23T17:05:23.521358Z","iopub.execute_input":"2024-02-23T17:05:23.521968Z","iopub.status.idle":"2024-02-23T17:05:23.532218Z","shell.execute_reply.started":"2024-02-23T17:05:23.521928Z","shell.execute_reply":"2024-02-23T17:05:23.530878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfll=pd.DataFrame(columns=['LatitudeDegrees','LongitudeDegrees','color'])\nfor i,path in enumerate(paths):\n    df=pd.read_csv(path)\n    c=normal_mapping[i%14]\n    ll=df.iloc[:,[2,3]]\n    ll.loc[:,'color']=[c]*len(ll)\n    dfll=pd.concat([dfll,ll],axis=0)","metadata":{"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-02-23T17:05:23.534360Z","iopub.execute_input":"2024-02-23T17:05:23.535447Z","iopub.status.idle":"2024-02-23T17:05:25.349969Z","shell.execute_reply.started":"2024-02-23T17:05:23.535406Z","shell.execute_reply":"2024-02-23T17:05:25.348780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfll","metadata":{"execution":{"iopub.status.busy":"2024-02-23T17:05:25.351789Z","iopub.execute_input":"2024-02-23T17:05:25.352774Z","iopub.status.idle":"2024-02-23T17:05:25.366630Z","shell.execute_reply.started":"2024-02-23T17:05:25.352738Z","shell.execute_reply":"2024-02-23T17:05:25.365558Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"    latm=dfll['LatitudeDegrees'].mean()\n    lonm=dfll['LongitudeDegrees'].mean()\n\n    eq_map = folium.Map(location=[latm+0.5,lonm-0.5], tiles='OpenStreetMap', zoom_start=9.0, min_zoom=2.0)\n\n    for i in range(len(dfll)):\n        if i%50==0:\n            ll= dfll.iloc[i,0:2].tolist()\n            c=dfll.iloc[i,2][0]\n            folium.Circle(location=ll, radius=10, color=c, fill_color=None).add_to(eq_map)\n\n    eq_map","metadata":{}},{"cell_type":"code","source":"latm=dfll['LatitudeDegrees'].mean()\nlonm=dfll['LongitudeDegrees'].mean()\n\neq_map = folium.Map(location=[latm+0.5,lonm-0.5], tiles='OpenStreetMap', zoom_start=9.0, min_zoom=2.0)\n\nfor i in range(len(dfll)):\n    if i%50==0:\n        ll= dfll.iloc[i,0:2].tolist()\n        c=dfll.iloc[i,2]\n        folium.Circle(location=ll, radius=10, color=c, fill_color=None).add_to(eq_map)\n\neq_map","metadata":{"execution":{"iopub.status.busy":"2024-02-23T17:05:25.368589Z","iopub.execute_input":"2024-02-23T17:05:25.369555Z","iopub.status.idle":"2024-02-23T17:05:30.424787Z","shell.execute_reply.started":"2024-02-23T17:05:25.369515Z","shell.execute_reply":"2024-02-23T17:05:30.423051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n    eq_map = folium.Map(location=[latm-3,lonm+3], tiles='OpenStreetMap', zoom_start=9.0, min_zoom=2.0)\n\n    for i in range(len(dfll)):\n        if i%50==0:\n            ll= dfll.iloc[i,0:2].tolist()\n            c=dfll.iloc[i,2]\n            folium.Circle(location=ll, radius=10, color=c, fill_color=None).add_to(eq_map)\n\n    eq_map","metadata":{}},{"cell_type":"code","source":"\neq_map = folium.Map(location=[latm-3,lonm+3], tiles='OpenStreetMap', zoom_start=9.0, min_zoom=2.0)\n\nfor i in range(len(dfll)):\n    if i%50==0:\n        ll= dfll.iloc[i,0:2].tolist()\n        c=dfll.iloc[i,2]\n        folium.Circle(location=ll, radius=10, color=c, fill_color=None).add_to(eq_map)\n\neq_map","metadata":{"execution":{"iopub.status.busy":"2024-02-23T17:05:30.427261Z","iopub.execute_input":"2024-02-23T17:05:30.427889Z","iopub.status.idle":"2024-02-23T17:05:35.478701Z","shell.execute_reply.started":"2024-02-23T17:05:30.427830Z","shell.execute_reply":"2024-02-23T17:05:35.477461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### It can be confirmed that there are multiple activities moving on the same course.\nEven if there is no location information in the test data, it would be possible to predict the location if it is possible to identify which course the activity is on.","metadata":{}}]}