-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathguess_time.py
More file actions
95 lines (76 loc) · 2.6 KB
/
guess_time.py
File metadata and controls
95 lines (76 loc) · 2.6 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import argparse
import pandas as pd
def main():
args = init_argparse().parse_args()
cell_df = pd.read_csv(args.cell_info, parse_dates=[0], infer_datetime_format=True)
signal_df = pd.read_csv(args.signal_strengths, parse_dates=[0], infer_datetime_format=True)
loc_df = pd.read_csv(args.location_updates)
data = []
for i, r in loc_df.iterrows():
similar = cell_df.loc[
(cell_df["latitude"] == r["latitude"])
& (cell_df["longitude"] == r["longitude"])
& (cell_df["altitude"] == r["altitude"])
& (cell_df["speed"] == r["speed"])
& (cell_df["locationAccuracy"] == r["locationAccuracy"])
]
data.append([
similar.iloc[0]["time"] if len(similar) > 0 else None,
r["latitude"],
r["longitude"],
r["altitude"],
r["speed"],
r["locationAccuracy"],
])
df = pd.DataFrame(data, columns=["time", "latitude", "longitude", "altitude", "speed", "locationAccuracy"])
for i, r in df.iterrows():
if r["time"] is not pd.NaT:
continue
similar = signal_df.loc[
(signal_df["latitude"] == r["latitude"])
& (signal_df["longitude"] == r["longitude"])
& (signal_df["altitude"] == r["altitude"])
& (signal_df["speed"] == r["speed"])
& (signal_df["locationAccuracy"] == r["locationAccuracy"])
]
if len(similar) > 0:
df.at[i, "time"] = similar.iloc[0]["time"]
else:
before = df.iloc[i - 1]["time"]
after = df.iloc[i + 1]["time"]
average = before + (after - before) / 2
df.at[i, "time"] = average
print(f"WARNING: Guessed the timestamp {average}")
df.to_csv(args.out, date_format="%Y-%m-%dT%H:%M:%S.%f", index=False)
def init_argparse() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
usage="%(prog)s [OPTIONS]",
description="Generate coverage maps for measurement data."
)
parser.add_argument(
"-l",
"--location-updates",
type=argparse.FileType("r"),
required=True,
)
parser.add_argument(
"-c",
"--cell-info",
type=argparse.FileType("r"),
required=True,
)
parser.add_argument(
"-s",
"--signal-strengths",
type=argparse.FileType("r"),
required=True,
)
parser.add_argument(
"-o",
"--out",
type=argparse.FileType("w"),
required=True,
)
return parser
if __name__ == '__main__':
main()