-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathget_data.py
38 lines (34 loc) · 1.14 KB
/
get_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import os
from access_points import get_scanner
from utils import ensure_model_path
def aps_to_dict(aps):
return {ap['ssid'] + " " + ap['bssid']: ap['quality'] for ap in aps}
def sample(device=""):
wifi_scanner = get_scanner(device)
if not os.environ.get("PYTHON_ENV", False):
aps = wifi_scanner.get_access_points()
else:
aps = [{"quality": 100, "bssid": "XX:XX:XX:XX:XX:84",
"ssid": "X", "security": "XX"}]
return aps_to_dict(aps)
def get_external_sample(path):
data = []
with open(os.path.join(path, "current.loc.txt")) as f:
for line in f:
data.append(json.loads(line))
return data
def get_train_data(folder=None):
if folder is None:
folder = ensure_model_path()
X = []
y = []
for fname in os.listdir(folder):
if fname.endswith(".txt"):
data = []
with open(os.path.join(folder, fname)) as f:
for line in f:
data.append(json.loads(line))
X.extend(data)
y.extend([fname.rstrip(".txt")] * len(data))
return X, y