{"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":"markdown","source":"This notebook creates the dictionary of wifi bssid and the ibeacon MAC address in the test data.\n  \nTraining on data with IDs that are not included here will not be useful for prediction, so it is better not to include them in the training data.","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import sys\nimport pickle, gc, glob\nfrom tqdm import tqdm","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_path = '../input/indoor-location-navigation'\ntest_files = glob.glob(f'{input_path}/test/*.txt')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"''' Retrieve the Site ID from txt file '''\ndef SiteID(txt):\n    p1 = txt[1].find('SiteID:')+7\n    p2 = txt[1].find('\\tSiteName:')\n    assert p1!=-1+7 and p2!=-1, 'SiteID not found'\n    return txt[1][p1:p2]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"site_dict = {}\nfor file in tqdm(test_files):\n    with open(file, 'r', encoding=\"utf-8\") as f:\n        txt = f.readlines()\n    site = SiteID(txt)\n    wifi,beac = [],[]\n    for line in txt:\n        tmp = line.strip().split()\n        if tmp[1] == \"TYPE_WIFI\":\n            wifi.append(tmp[3]) #bssid\n        elif tmp[1] == \"TYPE_BEACON\":\n            beac.append(tmp[8]) #MAC Address\n    if not site in site_dict:\n        site_dict[site] = {'path':[file.split('/')[-1]\n                                   .replace('.txt','')],\n                           'wifi':list(set(wifi)),\n                           'beac':list(set(beac))}\n    else:\n        site_dict[site]['path'].append(file.split('/')[-1]\n                                       .replace('.txt',''))\n        site_dict[site]['wifi'] = list(set(site_dict[site]['wifi']\n                                           +wifi))\n        site_dict[site]['beac'] = list(set(site_dict[site]['beac']\n                                           +beac))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f'num of buildings in test set: {len(site_dict)}')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with open(\"test_site_dict.pkl\", \"wb\") as f:\n    pickle.dump(site_dict, f)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}