{"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 # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport glob\nfrom main_io_comp_vis_all import calibrate_magnetic_wifi_ibeacon_to_position, read_data_file\nimport warnings\nwarnings.filterwarnings('ignore')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('../input/indoor-location-navigation/sample_submission.csv')\ntest_df[[\"site\",\"path\",\"time\"]]=test_df[\"site_path_timestamp\"].str.split('_', expand=True)\nsite_list = list(set(list(test_df[\"site\"])))\npath_list = list(set(list(test_df[\"path\"])))\nlen(path_list)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1) Format Test data","metadata":{}},{"cell_type":"markdown","source":"## 1.1) Initialize","metadata":{}},{"cell_type":"code","source":"floor_txt_num = {'F1':1,'1F':1,'L1':1,'1L':1,'F2':3,'2F':3,'L2':3,'2L':3,'F3':4,'3F':4,'L3':4,'3L':4,'F4':5,'4F':5,'L4':5,'4L':5,\n                'F5':6,'5F':6,'L5':6,'5L':6,'F6':7,'6F':7,'L6':7,'6L':7,'F7':8,'7F':8,'L7':8,'7L':8,'F8':9,'8F':9,'L8':9,'8L':9,\n                'F9':10,'9F':10,'L9':10,'9L':10,'F10':11,'10F':11,'L10':11,'10L':11,'F11':12,'11F':12,'L11':12,'11L':12,\n                'B1':1,'1B':1,\"B\":1,'B2':2,'2B':2,'B3':3,'3B':3,'B4':4,'4B':4}","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NUM_FEATS=10\nBSSID_FEATS = [f'BSSID_{i}' for i in range(NUM_FEATS)]\nRSSI_FEATS = [f'RSSI_{i}' for i in range(NUM_FEATS)]\nBEACON_FEATS = [f'BEACONID_{i}' for i in range(NUM_FEATS)]\nBEACONRSSI_FEATS = [f'BEACONRSSI_{i}' for i in range(NUM_FEATS)]\ntest_df[BSSID_FEATS] = \"XXX\"\ntest_df[BEACON_FEATS] = \"XXX\"\ntest_df[RSSI_FEATS] = -100\ntest_df[BEACONRSSI_FEATS] = -100","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## 1.2) Generate Test data","metadata":{}},{"cell_type":"code","source":"for idxp, path in enumerate(path_list):\n    data = read_data_file('../input/indoor-location-navigation/test/'+path+'.txt')\n    if (data.wifi != []):\n        wifi_df = pd.DataFrame(data=data.wifi, columns= [\"Time\",\"SSID\",\"BSSID\",\"RSSI\",\"LTime\"])\n        wifi_df = wifi_df.drop(columns=[\"SSID\",\"LTime\"])\n        wifi_df[[\"Time\", \"RSSI\"]] = wifi_df[[\"Time\", \"RSSI\"]].astype('int')\n    else:\n        wifi_df = pd.DataFrame(data={\"Time\":[],\"SSID\":[],\"BSSID\":[],\"RSSI\":[],\"LTime\":[]})\n    if (data.ibeacon != []):\n        beacon_df = pd.DataFrame(data=data.ibeacon, columns= [\"Time\",\"BEACONID\",\"RSSI\"])\n        beacon_df[[\"Time\",\"RSSI\"]] = beacon_df[[\"Time\",\"RSSI\"]].astype('int')\n    else:\n        beacon_df = pd.DataFrame(data={\"Time\":[],\"BEACONID\":[],\"RSSI\":[]})\n    \n    test_df_time = list(test_df.loc[test_df[\"path\"]==path,[\"time\"]].values)\n    test_df_time = [int(i) for i in test_df_time]\n    \n    for time in test_df_time:\n        wifi_df_temp = wifi_df.loc[(wifi_df[\"Time\"]<(time+2000)) & (wifi_df[\"Time\"]>(time-2000)),:]\n        wifi_df_temp = wifi_df_temp.groupby(by=[\"BSSID\"]).mean()\n        wifi_df_temp = wifi_df_temp.sort_values(by=[\"RSSI\"],ascending=False)\n        wifi_df_temp = wifi_df_temp[:10]\n        wifi_df_temp_bssid = list(wifi_df_temp.index)\n        wifi_df_temp_rssi = list(wifi_df_temp[\"RSSI\"])\n        for i in range(10-len(wifi_df_temp)):\n            wifi_df_temp_bssid.append('XXX')\n            wifi_df_temp_rssi.append(-100)\n        test_df.loc[(test_df[\"path\"]==path) & (test_df[\"time\"].astype('int')==time),BSSID_FEATS] = wifi_df_temp_bssid\n        test_df.loc[(test_df[\"path\"]==path) & (test_df[\"time\"].astype('int')==time),RSSI_FEATS] = wifi_df_temp_rssi\n        # print(wifi_df_temp_bssid)\n        # print(test_df.loc[(test_df[\"path\"]==path) & (test_df[\"time\"].astype('int')==time),BSSID_FEATS])\n        \n        \n        beacon_df_temp = beacon_df.loc[(beacon_df[\"Time\"]<(time+2000)) & (beacon_df[\"Time\"]>(time-2000)),:]\n        beacon_df_temp = beacon_df_temp.groupby(by=[\"BEACONID\"]).mean()\n        beacon_df_temp = beacon_df_temp.sort_values(by=[\"RSSI\"],ascending=False)\n        beacon_df_temp = beacon_df_temp[:10]\n        beacon_df_temp_beaconid = list(beacon_df_temp.index)\n        beacon_df_temp_rssi = list(beacon_df_temp[\"RSSI\"])\n        for i in range(10-len(beacon_df_temp)):\n            beacon_df_temp_beaconid.append('XXX')\n            beacon_df_temp_rssi.append(-100)\n        test_df.loc[(test_df[\"path\"]==path) & (test_df[\"time\"].astype('int')==time),BEACON_FEATS] = beacon_df_temp_beaconid\n        test_df.loc[(test_df[\"path\"]==path) & (test_df[\"time\"].astype('int')==time),BEACONRSSI_FEATS] = beacon_df_temp_rssi\n    print(\"FILE : \", idxp, \" of 626\")\n        \ntest_df.to_csv('sub_file.csv')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}