This commit is contained in:
@@ -98,14 +98,12 @@ def normalize_station_elements(
|
||||
if not name:
|
||||
continue
|
||||
|
||||
raw_code = tags.get("ref") or tags.get(
|
||||
"railway:ref") or tags.get("local_ref")
|
||||
raw_code = tags.get("ref") or tags.get("railway:ref") or tags.get("local_ref")
|
||||
code = str(raw_code) if raw_code is not None else None
|
||||
|
||||
elevation_tag = tags.get("ele") or tags.get("elevation")
|
||||
try:
|
||||
elevation = float(
|
||||
elevation_tag) if elevation_tag is not None else None
|
||||
elevation = float(elevation_tag) if elevation_tag is not None else None
|
||||
except (TypeError, ValueError):
|
||||
elevation = None
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ def build_overpass_query(region_name: str) -> str:
|
||||
regions = DEFAULT_REGIONS
|
||||
else:
|
||||
regions = tuple(
|
||||
region for region in DEFAULT_REGIONS if region.name == region_name)
|
||||
region for region in DEFAULT_REGIONS if region.name == region_name
|
||||
)
|
||||
if not regions:
|
||||
available = ", ".join(region.name for region in DEFAULT_REGIONS)
|
||||
msg = f"Unknown region {region_name}. Available regions: [{available}]"
|
||||
@@ -86,7 +87,9 @@ def perform_request(query: str) -> dict[str, Any]:
|
||||
return json.loads(payload)
|
||||
|
||||
|
||||
def normalize_track_elements(elements: Iterable[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
def normalize_track_elements(
|
||||
elements: Iterable[dict[str, Any]]
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Convert Overpass way elements into TrackCreate-compatible payloads."""
|
||||
|
||||
tracks: list[dict[str, Any]] = []
|
||||
|
||||
@@ -91,13 +91,13 @@ def _parse_track_entries(entries: Iterable[Mapping[str, Any]]) -> list[ParsedTra
|
||||
coordinates = entry.get("coordinates")
|
||||
if not isinstance(coordinates, Sequence) or len(coordinates) < 2:
|
||||
raise ValueError(
|
||||
"Invalid track entry: 'coordinates' must contain at least two points")
|
||||
"Invalid track entry: 'coordinates' must contain at least two points"
|
||||
)
|
||||
|
||||
processed_coordinates: list[tuple[float, float]] = []
|
||||
for pair in coordinates:
|
||||
if not isinstance(pair, Sequence) or len(pair) != 2:
|
||||
raise ValueError(
|
||||
f"Invalid coordinate pair {pair!r} in track entry")
|
||||
raise ValueError(f"Invalid coordinate pair {pair!r} in track entry")
|
||||
lat, lon = pair
|
||||
processed_coordinates.append((float(lat), float(lon)))
|
||||
|
||||
@@ -155,7 +155,8 @@ def load_tracks(tracks: Iterable[ParsedTrack], commit: bool = True) -> int:
|
||||
continue
|
||||
|
||||
length = track_data.length_meters or _polyline_length(
|
||||
track_data.coordinates)
|
||||
track_data.coordinates
|
||||
)
|
||||
max_speed = (
|
||||
int(round(track_data.max_speed_kph))
|
||||
if track_data.max_speed_kph is not None
|
||||
@@ -192,8 +193,7 @@ def _nearest_station(
|
||||
best_station: StationRef | None = None
|
||||
best_distance = math.inf
|
||||
for station in stations:
|
||||
distance = _haversine(
|
||||
coordinate, (station.latitude, station.longitude))
|
||||
distance = _haversine(coordinate, (station.latitude, station.longitude))
|
||||
if distance < best_distance:
|
||||
best_station = station
|
||||
best_distance = distance
|
||||
@@ -229,7 +229,9 @@ def _to_point(geometry: WKBElement | WKTElement | Any):
|
||||
try:
|
||||
point = to_shape(geometry)
|
||||
return point if getattr(point, "geom_type", None) == "Point" else None
|
||||
except Exception: # pragma: no cover - defensive, should not happen with valid geometry
|
||||
except (
|
||||
Exception
|
||||
): # pragma: no cover - defensive, should not happen with valid geometry
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user