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 a setting to say times in clock times (vs. ETA) #97

Closed barbeau closed 7 years ago

barbeau commented 7 years ago

Summary:

A user requested that we allow the skill to say times in clock times (10:32) instead of ETA (9 minutes):

“ It also does not give the times but says leaves in 5 minutes, 12minutes etc. I want actual times such as 10:32 am etc.”

Steps to reproduce:

  1. Ask for an arrival time at any region/stop

Expected behavior:

Add an option so the skill can announce "Route 5 to Downtown will arrive at 10:32 am".

Observed behavior:

Always announces "Route 5 to Downtown will arrive in 9 minutes".

Device:

N/A

Audio or video:

N/A

barbeau commented 7 years ago

This will need to be enabled via feature in https://github.com/OneBusAway/onebusaway-client-library/issues/16.

barbeau commented 7 years ago

This feature is now supported in the library (via https://github.com/OneBusAway/onebusaway-client-library/commit/723ac7400ef9dbeb084f4782c0fbe28197857683, fixed in https://github.com/OneBusAway/onebusaway-client-library/issues/16), so this issue is unblocked.

Here's an example code of how to request ETAs vs. clock times:

// Make HTTP request and get the response from the OBA server
ObaArrivalInfoResponse response =
                new ObaArrivalInfoRequest.Builder("Hillsborough%20Area%20Regional%20Transit_10001").build().call();
ObaArrivalInfo[] arrivals = response.getArrivalInfo();
boolean includeArriveDepartLabels = true;
final String SEPARATOR = "\n";

boolean clocktime = true;  // true for clock times like "arriving at 10:05 PM", false for ETAs like "arriving in 9 minutes"
List<ArrivalInfo> arrivalInfo = ArrivalInfo.convertObaArrivalInfo(arrivals, null,
    response.getCurrentTime(), includeArriveDepartLabels, clocktime);
String summary = UIUtils.getArrivalInfoSummary(arrivalInfo, SEPARATOR, clocktime);
barbeau commented 7 years ago

Spoke too soon - there is a timezone issue that still needs to be resolved in the library - see https://github.com/OneBusAway/onebusaway-client-library/issues/19#issuecomment-279198900 for details.

barbeau commented 7 years ago

In case anyone following this issue already knows the answer to this - is there a built-in way to get the timezone of a device for an incoming Alexa request?

barbeau commented 7 years ago

This issue is unblocked again - there is now a timeZone parameter for the related methods which allows the application to specify which timezone should be used when calculating the clock time. For example:

// Make HTTP request and get the response from the OBA server
ObaArrivalInfoResponse response =
                new ObaArrivalInfoRequest.Builder("Hillsborough%20Area%20Regional%20Transit_10001").build().call();
ObaArrivalInfo[] arrivals = response.getArrivalInfo();
boolean includeArriveDepartLabels = true;
final String SEPARATOR = "\n";

boolean clocktime = true;  // true for clock times like "arriving at 10:05 PM", false for ETAs like "arriving in 9 minutes"
String timeZoneText = "America/New_York";
TimeZone timeZone = TimeZone.getTimeZone(timeZoneText);
List<ArrivalInfo> arrivalInfo = ArrivalInfo.convertObaArrivalInfo(arrivals, null,
    response.getCurrentTime(), includeArriveDepartLabels, clocktime, timeZone);
String summary = UIUtils.getArrivalInfoSummary(arrivalInfo, SEPARATOR, clocktime, timeZone);
barbeau commented 7 years ago

Also, if we can't get the time zone from the device for an incoming Alexa request, we can make a call to the regional OneBusAway server to retrieve this info via the agencies-with-coverage method: http://api.tampa.onebusaway.org/api/api/where/agencies-with-coverage.json?key=TEST

A timezone is returned for each agency in the references block:

"disclaimer": "",
"email": "gohart.service@gmail.com",
"fareUrl": "",
"id": "Hillsborough Area Regional Transit",
"lang": "en",
"name": "Hillsborough Area Regional Transit",
"phone": "813-254-4278",
"privateService": false,
"timezone": "America/New_York",
"url": "http://www.gohart.org"
barbeau commented 7 years ago

I'm working on this.