Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds fallback for OSRM "NoRoute" errors #14

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

merschformann
Copy link
Member

Description

This PR introduces a fallback mechanism for when OSRM fails to find a route, alongside improved error handling.

Changes

  • Implemented a fallback to as-the-crow-flies calculation if OSRM returns "NoRoute". Print warning if this happens.
  • Enhanced error logging to include OSRM response text upon request failure.
  • Introduced counting and warning for routes not found by OSRM.

Copy link

@nilsbeck nilsbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT, just smaller remarks. Not sure if they are blocking, you decide

nextplot/osrm.py Outdated
)
distances.append(common.haversine(f, t))
durations.append(common.haversine(f, t) / TRAVEL_SPEED)
return OsrRouteResponse(paths=paths, distances=distances, durations=durations, no_route=True)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a "m" missing? 🧐

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. 😊

@@ -40,9 +41,26 @@ def query_route(
# Query OSRM
try:
response = requests.get(url)
# If no route was found, use as-the-crow-flies fallback
if response.status_code == 400 and response.json()["code"] == "NoRoute":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it was a "bad request" why not always fall back?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. 🤔
I think the reason here is that it will likely fall back for all routes, which might be worse. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will leave it like it for now. Let's see whether we want to change this in future. ☺️

@merschformann merschformann merged commit 21dde0c into develop Oct 24, 2024
3 checks passed
@merschformann merschformann deleted the merschformann/fix-osrm-no-route branch October 24, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants