-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcatch2.py
More file actions
89 lines (65 loc) · 2.56 KB
/
catch2.py
File metadata and controls
89 lines (65 loc) · 2.56 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
# This script updates the expected GPX data used in C++ tests.
import json
from pathlib import Path
import fastgpx
def get_gpx_files(dir_path: Path):
return sorted(dir_path.glob("*.gpx"))
GPX_ROOTS = [
Path("gpx/2024 Great Roadtrip"),
Path("gpx/2024 Sommertur"),
Path("gpx/2024 TopCamp"),
]
def main():
files = []
for root in GPX_ROOTS:
files.extend(get_gpx_files(root))
data = []
for gpx_path in files:
print(gpx_path.as_posix())
assert gpx_path.exists()
gpx = fastgpx.parse(str(gpx_path.resolve()))
gpx_data = {
"path": gpx_path.as_posix(),
"length2d": round(gpx.length_2d(), 4),
"length3d": round(gpx.length_3d(), 4),
"tracks": [],
}
gpx_time = gpx.time_bounds()
if gpx_time.start_time and gpx_time.end_time:
gpx_data["time_bounds"] = {
"start_time": int(gpx_time.start_time.timestamp()),
"end_time": int(gpx_time.end_time.timestamp()),
}
for track in gpx.tracks:
track_data = {
"length2d": round(track.length_2d(), 4),
"length3d": round(track.length_3d(), 4),
"segments": [],
}
track_time = track.time_bounds()
if track_time.start_time and track_time.end_time:
track_data["time_bounds"] = {
"start_time": int(track_time.start_time.timestamp()),
"end_time": int(track_time.end_time.timestamp()),
}
for segment in track.segments:
segment_data = {
"length2d": round(segment.length_2d(), 4),
"length3d": round(segment.length_3d(), 4),
}
segment_time = segment.time_bounds()
if segment_time.start_time and segment_time.end_time:
segment_data["time_bounds"] = { # type: ignore
"start_time": int(segment_time.start_time.timestamp()),
"end_time": int(segment_time.end_time.timestamp()),
}
track_data["segments"].append(segment_data)
gpx_data["tracks"].append(track_data)
data.append(gpx_data)
output_path = Path("cpp/expected_gpx_data.json")
output_path.parent.mkdir(parents=True, exist_ok=True)
with output_path.open("w", encoding="utf-8") as json_file:
json.dump(data, json_file, indent=2)
json_file.write("\n")
if __name__ == "__main__":
main()