53 lines
2 KiB
Python
53 lines
2 KiB
Python
|
|
"""Routing engine configuration with environment variable loading."""
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import os
|
||
|
|
from dataclasses import dataclass
|
||
|
|
from typing import Self
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass(frozen=True)
|
||
|
|
class RoutingConfig:
|
||
|
|
"""Configuration for self-hosted routing engines (OSRM + OTP).
|
||
|
|
|
||
|
|
Attributes:
|
||
|
|
osrm_foot_url: URL for OSRM walking profile instance.
|
||
|
|
osrm_bicycle_url: URL for OSRM cycling profile instance.
|
||
|
|
otp_url: URL for OpenTripPlanner instance.
|
||
|
|
osrm_batch_size: Number of origins per OSRM /table request.
|
||
|
|
otp_max_concurrent: Max concurrent OTP requests.
|
||
|
|
"""
|
||
|
|
|
||
|
|
osrm_foot_url: str = "http://osrm-foot:5000"
|
||
|
|
osrm_bicycle_url: str = "http://osrm-bicycle:5000"
|
||
|
|
otp_url: str = "http://otp:8080"
|
||
|
|
osrm_batch_size: int = 50
|
||
|
|
otp_max_concurrent: int = 10
|
||
|
|
|
||
|
|
@classmethod
|
||
|
|
def from_env(cls) -> Self:
|
||
|
|
"""Load configuration from environment variables.
|
||
|
|
|
||
|
|
Environment variables:
|
||
|
|
OSRM_FOOT_URL: OSRM walking instance URL (default: http://osrm-foot:5000)
|
||
|
|
OSRM_BICYCLE_URL: OSRM cycling instance URL (default: http://osrm-bicycle:5000)
|
||
|
|
OTP_URL: OpenTripPlanner URL (default: http://otp:8080)
|
||
|
|
OSRM_BATCH_SIZE: Origins per /table request (default: 50)
|
||
|
|
OTP_MAX_CONCURRENT: Max concurrent OTP requests (default: 10)
|
||
|
|
"""
|
||
|
|
return cls(
|
||
|
|
osrm_foot_url=os.environ.get("OSRM_FOOT_URL", "http://osrm-foot:5000"),
|
||
|
|
osrm_bicycle_url=os.environ.get("OSRM_BICYCLE_URL", "http://osrm-bicycle:5000"),
|
||
|
|
otp_url=os.environ.get("OTP_URL", "http://otp:8080"),
|
||
|
|
osrm_batch_size=int(os.environ.get("OSRM_BATCH_SIZE", "50")),
|
||
|
|
otp_max_concurrent=int(os.environ.get("OTP_MAX_CONCURRENT", "10")),
|
||
|
|
)
|
||
|
|
|
||
|
|
def get_osrm_url(self, profile: str) -> str:
|
||
|
|
"""Get the OSRM URL for a given profile."""
|
||
|
|
if profile == "foot":
|
||
|
|
return self.osrm_foot_url
|
||
|
|
elif profile == "bicycle":
|
||
|
|
return self.osrm_bicycle_url
|
||
|
|
raise ValueError(f"Unknown OSRM profile: {profile}")
|