-
Notifications
You must be signed in to change notification settings - Fork 4
/
dataset_construction.py
62 lines (53 loc) · 1.79 KB
/
dataset_construction.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import pandas as pd
import numpy as np
import argparse
from utils import io
parser = argparse.ArgumentParser()
parser.add_argument(
"--trajectory",
type=str,
help="trajectory file path",
)
parser.add_argument(
"--wifi",
type=str,
help="wifi file path",
)
parser.add_argument(
"--output",
type=str,
default="signal.csv",
help="output file path",
)
args = parser.parse_args()
if __name__ == "__main__":
positions, timestamps = io.load_coordinates_and_timestamps(args.trajectory)
wifi = pd.read_csv(args.wifi)
# filter only AirPennNet
wifi = wifi[wifi["SSID"] == "AirPennNet"]
wifi = wifi[["BSSID", "level", "write_time"]]
# level to float
wifi["level"] = wifi["level"].astype(float)
# average
wifi = wifi.groupby(["BSSID", "write_time"]).mean().reset_index()
# create table
wifi = wifi.pivot(index="write_time", columns="BSSID", values="level").reset_index()
# process trajectory
timestamps = np.rint(np.asarray(timestamps) / 1e9)
positions = np.asarray(positions)
# concate timestamps and positions
pos_data = np.concatenate((timestamps.reshape(-1, 1), positions), axis=1)
# group by first column (timestamp)
# then average the rest of the columns
pos_data = pd.DataFrame(pos_data).groupby(0).mean()
pos_data.reset_index(inplace=True)
# convert column 0 from timestamp to form such as 2023-12-07 19:43:23
# timezone is current timezone
pos_data[0] = pd.to_datetime(pos_data[0], unit="s", utc=True).dt.tz_convert(
"US/Eastern"
)
pos_data[0] = pos_data[0].dt.strftime("%Y-%m-%d %H:%M:%S")
# merge
merged_df = pd.merge(pos_data, wifi, left_on=0, right_on="write_time", how="left")
merged_df.drop(columns=[0], inplace=True)
merged_df.to_csv(args.output, index=False)