OneBusAway / onebusaway-alexa

An Java-based app to communicate with Amazon Alexa for devices such as the Amazon Echo
Other
52 stars 18 forks source link

Add agency name when disambiguating stops #85

Open barbeau opened 8 years ago

barbeau commented 8 years ago

Summary:

In https://github.com/OneBusAway/onebusaway-alexa/pull/83 we added the ability to disambiguate stop numbers within the same region. For example, in Tampa, stop 3105 maps to two stops. The OBA skill will now iterate through the stops by name and ask you if it's the right one.

I'd like to add the agency name(s) serving that stop when iterating through them. Reasoning is that most duplicate stop codes arise from one stop code per agency, and the user will likely know which agency they want, but may not recognize the stop names.

My comments from https://github.com/OneBusAway/onebusaway-alexa/issues/53#issuecomment-220627720:

I believe you'll need to refactor ObaUserClient.getStopFromCode() to return the ObaStopsForLocationResponse instead of just the array of stops. You can then get the route IDs for each stop, and for each route ID get the agency ID for that route and then the agency name for each agency ID. A stop in OBA can serve more than one agency, which is why this is a little convoluted.

Code should look something like this:

ObaStop stop = getObaStop();  // Get a reference to a ObaStop - this will be a loop for you, likely getting all stops from response.getStops();
String[] routeIds = stop.getRouteIds();
Set<String> agencyIds = new HashSet<>();
for (int i = 0; i < routeIds.length; i++) {
    agencyIds.add(agencyIds[i]);
}
Set<String> agencyNames = new HashSet<>();
for (String agencyId : agencyIds) {
    agencyNames.add(response.getAgency(agencyId).getName());
}
// agencyNames should now contain all the agency names (one or more) that have routes that visit this stop

I'd probably put the above in a utility method.

Steps to reproduce:

  1. "Alexa, set my city to Tampa"
  2. "3105" // Stop number

Expected behavior:

Tell me the agency names that serve each stop, when asking me if its the right stop

Observed behavior:

Only the stop names are read

Device:

Amazon Echo

cc @vikram31291

vikram31291 commented 7 years ago

Tampa and 3105 just results in a "OneBusAway could not locate your stop number. Tell me again, what is your stop number?"

Do we have other stop codes that map to multiple stops?

barbeau commented 7 years ago

See https://github.com/OneBusAway/onebusaway-alexa/issues/87#issuecomment-254896678, there are a few others listed there.