{"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 pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-02-10T20:02:48.512745Z","iopub.execute_input":"2023-02-10T20:02:48.513372Z","iopub.status.idle":"2023-02-10T20:02:48.526226Z","shell.execute_reply.started":"2023-02-10T20:02:48.513278Z","shell.execute_reply":"2023-02-10T20:02:48.525291Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/predict-student-performance-from-game-play/train.csv\", usecols=[\"session_id\"])","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:02:53.505816Z","iopub.execute_input":"2023-02-10T20:02:53.506243Z","iopub.status.idle":"2023-02-10T20:03:06.794858Z","shell.execute_reply.started":"2023-02-10T20:02:53.506202Z","shell.execute_reply":"2023-02-10T20:03:06.793719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# TL;DR\n\n`session_id` likely contains date and time information. The last 2 digits still need to be understood.","metadata":{}},{"cell_type":"code","source":"train[\"year\"] = train[\"session_id\"].apply(lambda x: int(str(x)[:2])).astype(np.uint8)\ntrain[\"month\"] = train[\"session_id\"].apply(lambda x: int(str(x)[2:4]) + 1).astype(np.uint8)\ntrain[\"weekday\"] = train[\"session_id\"].apply(lambda x: int(str(x)[4:6])).astype(np.uint8)\ntrain[\"hour\"] = train[\"session_id\"].apply(lambda x: int(str(x)[6:8])).astype(np.uint8)\ntrain[\"minute\"] = train[\"session_id\"].apply(lambda x: int(str(x)[8:10])).astype(np.uint8)\ntrain[\"second\"] = train[\"session_id\"].apply(lambda x: int(str(x)[10:12])).astype(np.uint8)\ntrain[\"ms\"] = train[\"session_id\"].apply(lambda x: int(str(x)[12:15])).astype(np.uint16)\ntrain[\"?\"] = train[\"session_id\"].apply(lambda x: int(str(x)[15:17])).astype(np.uint8)","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:03:06.796595Z","iopub.execute_input":"2023-02-10T20:03:06.797008Z","iopub.status.idle":"2023-02-10T20:04:34.976484Z","shell.execute_reply.started":"2023-02-10T20:03:06.796977Z","shell.execute_reply":"2023-02-10T20:04:34.975403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:34.977685Z","iopub.execute_input":"2023-02-10T20:04:34.978173Z","iopub.status.idle":"2023-02-10T20:04:34.996836Z","shell.execute_reply.started":"2023-02-10T20:04:34.978142Z","shell.execute_reply":"2023-02-10T20:04:34.995895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Reverse engineering","metadata":{}},{"cell_type":"code","source":"sessions = train[\"session_id\"].drop_duplicates().reset_index(drop=True)\nsessions","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:34.998923Z","iopub.execute_input":"2023-02-10T20:04:34.999323Z","iopub.status.idle":"2023-02-10T20:04:35.161526Z","shell.execute_reply.started":"2023-02-10T20:04:34.999293Z","shell.execute_reply":"2023-02-10T20:04:35.160707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The size of the `session_id` is hugh given the number of sessions.\n\nThe first 2 digits could represent a year. Let's check it.","metadata":{"execution":{"iopub.status.busy":"2023-02-08T22:04:36.085888Z","iopub.execute_input":"2023-02-08T22:04:36.088510Z","iopub.status.idle":"2023-02-08T22:04:36.099185Z","shell.execute_reply.started":"2023-02-08T22:04:36.088465Z","shell.execute_reply":"2023-02-08T22:04:36.096720Z"}}},{"cell_type":"markdown","source":"## Date","metadata":{}},{"cell_type":"code","source":"sessions.apply(lambda x: str(x)[:2]).value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.162944Z","iopub.execute_input":"2023-02-10T20:04:35.164222Z","iopub.status.idle":"2023-02-10T20:04:35.184162Z","shell.execute_reply.started":"2023-02-10T20:04:35.164164Z","shell.execute_reply":"2023-02-10T20:04:35.183326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The data may be from 2020 to 2022.\n\nLet's check if the 2 next digits represent months.","metadata":{}},{"cell_type":"code","source":"sessions.apply(lambda x: str(x)[2:4]).value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.185655Z","iopub.execute_input":"2023-02-10T20:04:35.186341Z","iopub.status.idle":"2023-02-10T20:04:35.208464Z","shell.execute_reply.started":"2023-02-10T20:04:35.186304Z","shell.execute_reply":"2023-02-10T20:04:35.207494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sessions.apply(lambda x: str(x)[:2] + \"-\" + str(x)[2:4]).value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.210096Z","iopub.execute_input":"2023-02-10T20:04:35.210910Z","iopub.status.idle":"2023-02-10T20:04:35.232095Z","shell.execute_reply.started":"2023-02-10T20:04:35.210871Z","shell.execute_reply":"2023-02-10T20:04:35.231115Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"From october 2020 to november 2022...\n\nWhat about the next digits?","metadata":{}},{"cell_type":"code","source":"sessions.apply(lambda x: str(x)[4:6]).value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.233270Z","iopub.execute_input":"2023-02-10T20:04:35.233980Z","iopub.status.idle":"2023-02-10T20:04:35.251845Z","shell.execute_reply.started":"2023-02-10T20:04:35.233947Z","shell.execute_reply":"2023-02-10T20:04:35.251021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Day of week? 1 being monday?","metadata":{}},{"cell_type":"markdown","source":"## Hour","metadata":{}},{"cell_type":"code","source":"hour = sessions.apply(lambda x: str(x)[6:8]).value_counts().sort_index()\n\nplt.figure(figsize=(10, 4))\nplt.bar(hour.index, hour.values)\nplt.show()\n\nprint(hour)","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.253313Z","iopub.execute_input":"2023-02-10T20:04:35.253874Z","iopub.status.idle":"2023-02-10T20:04:35.497934Z","shell.execute_reply.started":"2023-02-10T20:04:35.253843Z","shell.execute_reply":"2023-02-10T20:04:35.497170Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sorted(list(set(sessions.apply(lambda x: str(x)[8:10])))))","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.500666Z","iopub.execute_input":"2023-02-10T20:04:35.501279Z","iopub.status.idle":"2023-02-10T20:04:35.514686Z","shell.execute_reply.started":"2023-02-10T20:04:35.501246Z","shell.execute_reply":"2023-02-10T20:04:35.513909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sorted(list(set(sessions.apply(lambda x: str(x)[10:12])))))","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.515979Z","iopub.execute_input":"2023-02-10T20:04:35.516523Z","iopub.status.idle":"2023-02-10T20:04:35.533967Z","shell.execute_reply.started":"2023-02-10T20:04:35.516491Z","shell.execute_reply":"2023-02-10T20:04:35.532952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(12, 15):\n    print(sessions.apply(lambda x: str(x)[i : i + 1]).value_counts())","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.535442Z","iopub.execute_input":"2023-02-10T20:04:35.535755Z","iopub.status.idle":"2023-02-10T20:04:35.570561Z","shell.execute_reply.started":"2023-02-10T20:04:35.535726Z","shell.execute_reply":"2023-02-10T20:04:35.569537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## The last 2 digits","metadata":{}},{"cell_type":"code","source":"for i in range(15, 17):\n    print(sessions.apply(lambda x: str(x)[i : i + 1]).value_counts())","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.571916Z","iopub.execute_input":"2023-02-10T20:04:35.572252Z","iopub.status.idle":"2023-02-10T20:04:35.593283Z","shell.execute_reply.started":"2023-02-10T20:04:35.572220Z","shell.execute_reply":"2023-02-10T20:04:35.592009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The last digit is not just noise as the 4 previous ones.\n\nIt turns out that the previous digit seems linked.","metadata":{}},{"cell_type":"code","source":"sessions.apply(lambda x: str(x)[15:17]).value_counts().sort_index()","metadata":{"execution":{"iopub.status.busy":"2023-02-10T20:04:35.594683Z","iopub.execute_input":"2023-02-10T20:04:35.594999Z","iopub.status.idle":"2023-02-10T20:04:35.612213Z","shell.execute_reply.started":"2023-02-10T20:04:35.594969Z","shell.execute_reply":"2023-02-10T20:04:35.611274Z"},"trusted":true},"execution_count":null,"outputs":[]}]}