Alpha stage commit
This commit is contained in:
48
scripts/import_routing_layer.py
Normal file
48
scripts/import_routing_layer.py
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/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 rebuild_routing_layer # noqa: E402
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Import a routable OSM graph for walking/driving first/last-mile routing.")
|
||||
parser.add_argument("--dataset-id", type=int, default=None, help="Raw OSM PBF dataset id. Defaults to the raw dataset behind the active OSM import.")
|
||||
parser.add_argument("--input-path", type=Path, default=None, help="Override the PBF path.")
|
||||
parser.add_argument("--batch-size", type=int, default=5000, help="Insert batch size.")
|
||||
parser.add_argument("--append", action="store_true", help="Append instead of clearing existing graph rows for the dataset.")
|
||||
args = parser.parse_args()
|
||||
|
||||
init_db()
|
||||
with session_scope() as session:
|
||||
result = rebuild_routing_layer(
|
||||
session,
|
||||
dataset_id=args.dataset_id,
|
||||
input_path=args.input_path,
|
||||
reset=not args.append,
|
||||
batch_size=args.batch_size,
|
||||
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()
|
||||
Reference in New Issue
Block a user