-
Notifications
You must be signed in to change notification settings - Fork 2
/
cleanup.py
54 lines (41 loc) · 1.84 KB
/
cleanup.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
#!/usr/bin/env python
from __future__ import annotations
import argparse
import os
from os import PathLike
from typing import Any, Dict, Tuple
from cli_utils import add_default_cli_args, use_default_cli_args
from tc_utils import TcFile
def cleanup(tc_directory: PathLike | str, force: bool = False) -> Tuple[TcFile, TcFile]:
path_json = TcFile('Path', tc_directory)
for path in path_json.data:
remove_annotations_from_path(path)
station_json = TcFile('Station', tc_directory)
for station in station_json.data:
remove_annotations_from_station(station)
return path_json, station_json
def remove_annotations_from_path(path: Dict[str, Any]):
path.pop('start_long', '')
path.pop('end_long', '')
path.pop('sinuosity', 0)
if "maxSpeed" in path and path.get("maxSpeed") == 0:
path.pop("maxSpeed")
if 'objects' in path:
for sub_path in path['objects']:
remove_annotations_from_path(sub_path)
def remove_annotations_from_station(station: Dict[str, Any], force: bool = False):
if 'group' not in station or station['group'] not in (4,):
if force or ('platforms' in station and 'platformLength' in station
and station['platforms'] and station['platformLength']):
station.pop('google_maps', '')
station.pop('osm', '')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Entferne nicht mehr benötigte Daten')
add_default_cli_args(parser, data_directory=False)
parser.add_argument("--force", action="store_true",
help="Löscht alle Annotationen, auch, wenn sie vielleicht noch hilfreich sind.")
args = parser.parse_args()
use_default_cli_args(args)
path_json, station_json = cleanup(tc_directory=args.tc_directory, force=args.force)
path_json.save()
station_json.save()