39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from app.db import init_db, session_scope # noqa: E402
|
|
from app.pipeline.routing_layer import finalize_routing_layer # noqa: E402
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description="Finalize an already imported routing graph.")
|
|
parser.add_argument("--dataset-id", type=int, default=None, help="Raw OSM PBF dataset id. Defaults to the active routing dataset.")
|
|
args = parser.parse_args()
|
|
|
|
init_db()
|
|
with session_scope() as session:
|
|
result = finalize_routing_layer(session, dataset_id=args.dataset_id, progress_callback=_progress)
|
|
print(result)
|
|
|
|
|
|
def _progress(event_type: str, message: str, current: int | None, total: int | None, metadata: dict[str, object] | None) -> None:
|
|
if current is None and total is None:
|
|
progress = ""
|
|
elif total:
|
|
progress = f" [{current}/{total}]"
|
|
else:
|
|
progress = f" [{current}]"
|
|
print(f"{event_type}{progress}: {message} {metadata or {}}", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|