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

feat: optionally use OpenTripPlanner for nearby transit #41

Merged
merged 6 commits into from
Jan 25, 2024

Conversation

boringcactus
Copy link
Member

Asana task: [Backend] Endpoint for stops + routes near given location

I think having the source of stop info as a parameter might make some sense while we're still figuring out how we want to approach nearby stop sorting and filtering.

As mentioned in the Asana comments, the OpenTripPlanner route pattern info is somewhat mangled compared to the GTFS values, so I'm not using it here, but I split that decision into its own commit so it's easier to roll back if we decide we want to.

Running this in production will require configuring the OTP_URL environment variable.

This OpenTripPlanner client is derived approximately from #34, and so also from dotcom.

@boringcactus boringcactus requested a review from a team as a code owner January 24, 2024 17:37
@boringcactus boringcactus requested review from KaylaBrady and removed request for a team January 24, 2024 17:37

This comment was marked as outdated.

This comment was marked as outdated.

Copy link
Collaborator

@KaylaBrady KaylaBrady left a comment

Choose a reason for hiding this comment

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

This looks good! Added a few small suggestions

Comment on lines 21 to 23
|> case do
{:ok, stops} -> {:ok, Enum.reverse(stops)}
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: I find this function a bit hard to read with the nesting, but it may also be because I am less familiar with the for comprehension than reducing via enum.

Could this perhaps be broken into smaller steps, or use more piped steps? The single pipe on line 21 into a case with only one condition is a bit confusing as well - could pattern matching be used here if there is only one case?

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea here was to implement a skeleton on top of which we can build error handling without having to rearchitect all this code, but with no actual error handling it's just harder to read for no reason. Conveniently, in my visualization work I encountered the problem of Massport shuttle stops being neither errors nor success, so it's worth fleshing this out somewhat to ensure those stops are correctly filtered out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know much about the massport shuttle and the expectations for whether or not it would show up in nearby transit - filtering seems reasonable for now, but can you ask product/design if you haven't done so already about how to handle them?

Copy link
Member Author

Choose a reason for hiding this comment

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

mix.exs Show resolved Hide resolved
@@ -0,0 +1 @@
{"data":{"nearest":{"edges":[{"node":{"distance":354,"place":{"gtfsId":"mbta-ma-us:67120","lat":42.28101,"lon":-71.177035,"name":"Millennium Park","parentStation":null}}},{"node":{"distance":618,"place":{"gtfsId":"mbta-ma-us:129","lat":42.278959,"lon":-71.175667,"name":"Rivermoor St @ Charles Park Rd","parentStation":null}}},{"node":{"distance":627,"place":{"gtfsId":"mbta-ma-us:137","lat":42.278907,"lon":-71.175492,"name":"Charles Park Rd @ Rivermoor St","parentStation":null}}}]}}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: could you please add a case where there is a stop that has a parentStation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

Comment on lines 11 to 13
case Map.fetch!(params, "source") do
"v3" -> :v3
"otp" -> :otp
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 this is a nice approach while we're in the testing phase! Can you please add a ticket to the backlog so we can revisit what to do here once we've learned more? Do we want to remove one entirely? Do we want to keep both options and have configuration on the backend so that we can make a switch between the two with a deploy if needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

This comment was marked as outdated.

This comment was marked as outdated.

Copy link

Coverage of commit 3ba001e

Summary coverage rate:
  lines......: 59.0% (350 of 593 lines)
  functions..: 59.9% (170 of 284 functions)
  branches...: no data found

Files changed coverage rate:
                                                             |Lines       |Functions  |Branches    
  Filename                                                   |Rate     Num|Rate    Num|Rate     Num
  =================================================================================================
  lib/mobile_app_backend_web/controllers/nearby_controller.ex| 100%     20|88.9%     9|    -      0
  lib/open_trip_planner_client.ex                            |68.8%     16|80.0%     5|    -      0
  lib/open_trip_planner_client/nearby.ex                     |81.8%     22| 100%     7|    -      0
  test/support/data.ex                                       |38.0%    100|68.4%    19|    -      0

Download coverage report

@boringcactus
Copy link
Member Author

The [Nearby Transit] Update radius & sort order ticket can include flipping the default source back to V3.

@boringcactus boringcactus merged commit 73aff82 into main Jan 25, 2024
4 checks passed
@boringcactus boringcactus deleted the mth-otp-near-me branch January 25, 2024 22:09
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.

2 participants