Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
add POI_TYPE nearest to provide nearest result (#1986) (#2024)
Browse files Browse the repository at this point in the history
* add POI_TYPE nearest to provide nearest result (#1986)

* POI test aligns with Calendar, Email, ToDo tests

* POI: add nearest tests, multiple routes test and fix RouteToPointOfInterestBy* tests
  • Loading branch information
xieofxie authored and ryanisgrig committed Aug 5, 2019
1 parent 6d40eee commit 846b822
Show file tree
Hide file tree
Showing 35 changed files with 540 additions and 779 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ $ROUTE_TYPE:fastest=

$ROUTE_TYPE:shortest=

$POI_TYPE:nearest=
- Nächste
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ $ROUTE_TYPE:fastest=
- high-speed

$ROUTE_TYPE:shortest=

$POI_TYPE:nearest=
- nearest
- closest
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ $ROUTE_TYPE:fastest=

$ROUTE_TYPE:shortest=

$POI_TYPE:nearest=
- Más cercano
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ $ROUTE_TYPE:fastest=

$ROUTE_TYPE:shortest=

$POI_TYPE:nearest=
- le plus proche
- Plus
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ $ROUTE_TYPE:fastest=

$ROUTE_TYPE:shortest=

$POI_TYPE:nearest=
- Più vicina
- più vicino
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ $ROUTE_TYPE:fastest=

$ROUTE_TYPE:shortest=

$POI_TYPE:nearest=
- 最近
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,22 @@ protected async Task<DialogTurnResult> RouteToFindFindParkingDialog(WaterfallSte
if (pointOfInterestAddressList.Any())
{
var pointOfInterest = pointOfInterestAddressList[0];
pointOfInterestList = await mapsService.GetPointOfInterestListByParkingCategoryAsync(pointOfInterest.Geolocation.Latitude, pointOfInterest.Geolocation.Longitude);

// TODO nearest here is not for current
pointOfInterestList = await mapsService.GetPointOfInterestListByParkingCategoryAsync(pointOfInterest.Geolocation.Latitude, pointOfInterest.Geolocation.Longitude, state.PoiType);
cards = await GetPointOfInterestLocationCards(sc, pointOfInterestList, mapsService);
}
else
{
// Find parking lot near address
pointOfInterestList = await mapsService.GetPointOfInterestListByParkingCategoryAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude);
pointOfInterestList = await mapsService.GetPointOfInterestListByParkingCategoryAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.PoiType);
cards = await GetPointOfInterestLocationCards(sc, pointOfInterestList, mapsService);
}
}
else
{
// No entities identified, find nearby parking lots
pointOfInterestList = await mapsService.GetPointOfInterestListByParkingCategoryAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude);
pointOfInterestList = await mapsService.GetPointOfInterestListByParkingCategoryAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.PoiType);
cards = await GetPointOfInterestLocationCards(sc, pointOfInterestList, mapsService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ public MainDialog(
// Activity should have text to trigger next intent, update Type & Route again
if (!string.IsNullOrEmpty(dc.Context.Activity.Text))
{
// since route is on highest level, cancel all before calling it
await dc.CancelAllDialogsAsync();
dc.Context.Activity.Type = ActivityTypes.Message;
await RouteAsync(dc);
}
Expand Down Expand Up @@ -392,6 +394,11 @@ private async Task DigestLuisResult(DialogContext dc, PointOfInterestLuis luisRe
state.RouteType = entities.ROUTE_TYPE[0][0];
}

if (entities.POI_TYPE != null)
{
state.PoiType = entities.POI_TYPE[0][0];
}

if (entities.number != null)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,37 +246,39 @@ protected async Task<DialogTurnResult> ProcessCurrentLocationSelection(Waterfall
if (string.IsNullOrEmpty(state.Keyword) && string.IsNullOrEmpty(state.Address))
{
// No entities identified, find nearby locations
pointOfInterestList = await service.GetNearbyPointOfInterestListAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude);
pointOfInterestList = await service.GetNearbyPointOfInterestListAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.PoiType);
cards = await GetPointOfInterestLocationCards(sc, pointOfInterestList, service);
}
else if (!string.IsNullOrEmpty(state.Keyword) && !string.IsNullOrEmpty(state.Address))
{
// Get first POI matched with address, if there are multiple this could be expanded to confirm which address to use
var pointOfInterestAddressList = await addressMapsService.GetPointOfInterestListByAddressAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.Address);
var pointOfInterestAddressList = await addressMapsService.GetPointOfInterestListByAddressAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.Address, state.PoiType);

if (pointOfInterestAddressList.Any())
{
var pointOfInterest = pointOfInterestAddressList[0];
pointOfInterestList = await service.GetPointOfInterestListByQueryAsync(pointOfInterest.Geolocation.Latitude, pointOfInterest.Geolocation.Longitude, state.Keyword);

// TODO nearest here is not for current
pointOfInterestList = await service.GetPointOfInterestListByQueryAsync(pointOfInterest.Geolocation.Latitude, pointOfInterest.Geolocation.Longitude, state.Keyword, state.PoiType);
cards = await GetPointOfInterestLocationCards(sc, pointOfInterestList, service);
}
else
{
// No POIs found from address - search near current coordinates
pointOfInterestList = await service.GetPointOfInterestListByQueryAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.Keyword);
pointOfInterestList = await service.GetPointOfInterestListByQueryAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.Keyword, state.PoiType);
cards = await GetPointOfInterestLocationCards(sc, pointOfInterestList, service);
}
}
else if (!string.IsNullOrEmpty(state.Keyword))
{
// Fuzzy query search with keyword
pointOfInterestList = await service.GetPointOfInterestListByQueryAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.Keyword);
pointOfInterestList = await service.GetPointOfInterestListByQueryAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.Keyword, state.PoiType);
cards = await GetPointOfInterestLocationCards(sc, pointOfInterestList, service);
}
else if (!string.IsNullOrEmpty(state.Address))
{
// Fuzzy query search with address
pointOfInterestList = await addressMapsService.GetPointOfInterestListByAddressAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.Address);
pointOfInterestList = await addressMapsService.GetPointOfInterestListByAddressAsync(state.CurrentCoordinates.Latitude, state.CurrentCoordinates.Longitude, state.Address, state.PoiType);
cards = await GetPointOfInterestLocationCards(sc, pointOfInterestList, addressMapsService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ public class SearchResult

[JsonProperty(PropertyName = "viewport")]
public Viewport Viewport { get; set; }

[JsonProperty(PropertyName = "dist")]
public double Distance { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public PointOfInterestSkillState()
LastFoundPointOfInterests = null;
ActiveRoute = null;
RouteType = string.Empty;
PoiType = string.Empty;
UserSelectIndex = -1;
}

Expand All @@ -39,6 +40,8 @@ public PointOfInterestSkillState()

public string RouteType { get; set; }

public string PoiType { get; set; }

public PointOfInterestLuis LuisResult { get; set; }

public DialogState ConversationDialogState { get; set; }
Expand All @@ -61,6 +64,7 @@ public void ClearLuisResults()
Keyword = string.Empty;
Address = string.Empty;
RouteType = string.Empty;
PoiType = string.Empty;
UserSelectIndex = -1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public Task<IGeoSpatialService> InitKeyAsync(string key, int radiusConfiguration
/// <param name="latitude">The current latitude.</param>
/// <param name="longitude">The current longitude.</param>
/// <param name="query">The search query.</param>
/// <param name="poiType">The poi type.</param>
/// <returns>List of PointOfInterestModels.</returns>
public async Task<List<PointOfInterestModel>> GetPointOfInterestListByQueryAsync(double latitude, double longitude, string query)
public async Task<List<PointOfInterestModel>> GetPointOfInterestListByQueryAsync(double latitude, double longitude, string query, string poiType = null)
{
if (string.IsNullOrEmpty(query))
{
Expand All @@ -91,10 +92,10 @@ public async Task<List<PointOfInterestModel>> GetPointOfInterestListByQueryAsync
if (double.IsNaN(latitude) || double.IsNaN(longitude))
{
// If missing either coordinate, the skill needs to run a fuzzy search on the query
return await GetPointsOfInterestAsync(string.Format(CultureInfo.InvariantCulture, FindByFuzzyQueryNoCoordinatesApiUrl, query, limit));
return await GetPointsOfInterestAsync(string.Format(CultureInfo.InvariantCulture, FindByFuzzyQueryNoCoordinatesApiUrl, query, limit), poiType);
}

return await GetPointsOfInterestAsync(string.Format(CultureInfo.InvariantCulture, FindByFuzzyQueryApiUrl, latitude, longitude, query, radius, limit));
return await GetPointsOfInterestAsync(string.Format(CultureInfo.InvariantCulture, FindByFuzzyQueryApiUrl, latitude, longitude, query, radius, limit), poiType);
}

/// <summary>
Expand All @@ -103,8 +104,9 @@ public async Task<List<PointOfInterestModel>> GetPointOfInterestListByQueryAsync
/// <param name="latitude">The current latitude.</param>
/// <param name="longitude">The current longitude.</param>
/// <param name="address">The search address.</param>
/// <param name="poiType">The poi type.</param>
/// <returns>List of PointOfInterestModels.</returns>
public async Task<List<PointOfInterestModel>> GetPointOfInterestListByAddressAsync(double latitude, double longitude, string address)
public async Task<List<PointOfInterestModel>> GetPointOfInterestListByAddressAsync(double latitude, double longitude, string address, string poiType = null)
{
if (string.IsNullOrEmpty(address))
{
Expand All @@ -114,49 +116,52 @@ public async Task<List<PointOfInterestModel>> GetPointOfInterestListByAddressAsy
if (double.IsNaN(latitude) || double.IsNaN(longitude))
{
// If missing either coordinate, the skill needs to run an address search on the query
return await GetPointsOfInterestAsync(string.Format(CultureInfo.InvariantCulture, FindByAddressNoCoordinatesQueryUrl, Uri.EscapeDataString(address), limit));
return await GetPointsOfInterestAsync(string.Format(CultureInfo.InvariantCulture, FindByAddressNoCoordinatesQueryUrl, Uri.EscapeDataString(address), limit), poiType);
}

return await GetPointsOfInterestAsync(string.Format(CultureInfo.InvariantCulture, FindByAddressQueryUrl, latitude, longitude, Uri.EscapeDataString(address), radius, limit));
return await GetPointsOfInterestAsync(string.Format(CultureInfo.InvariantCulture, FindByAddressQueryUrl, latitude, longitude, Uri.EscapeDataString(address), radius, limit), poiType);
}

/// <summary>
/// Get a street address from coordinates.
/// </summary>
/// <param name="latitude">The current latitude.</param>
/// <param name="longitude">The current longitude.</param>
/// <param name="poiType">The poi type.</param>
/// <returns>List of PointOfInterestModels.</returns>
public async Task<List<PointOfInterestModel>> GetPointOfInterestByCoordinatesAsync(double latitude, double longitude)
public async Task<List<PointOfInterestModel>> GetPointOfInterestByCoordinatesAsync(double latitude, double longitude, string poiType = null)
{
return await GetPointsOfInterestAsync(
string.Format(CultureInfo.InvariantCulture, FindAddressByCoordinateUrl, latitude, longitude, radius, limit));
string.Format(CultureInfo.InvariantCulture, FindAddressByCoordinateUrl, latitude, longitude, radius, limit), poiType);
}

/// <summary>
/// Get Point of Interest results around a specific location.
/// </summary>
/// <param name="latitude">The current latitude.</param>
/// <param name="longitude">The current longitude.</param>
/// <param name="poiType">The poi type.</param>
/// <returns>List of PointOfInterestModels.</returns>
public async Task<List<PointOfInterestModel>> GetNearbyPointOfInterestListAsync(double latitude, double longitude)
public async Task<List<PointOfInterestModel>> GetNearbyPointOfInterestListAsync(double latitude, double longitude, string poiType = null)
{
return await GetPointsOfInterestAsync(
string.Format(CultureInfo.InvariantCulture, FindNearbyUrl, latitude, longitude, radius, limit));
string.Format(CultureInfo.InvariantCulture, FindNearbyUrl, latitude, longitude, radius, limit), poiType);
}

/// <summary>
/// Get Point of Interest parking results around a specific location.
/// </summary>
/// <param name="latitude">The current latitude.</param>
/// <param name="longitude">The current longitude.</param>
/// <param name="poiType">The poi type.</param>
/// <returns>List of PointOfInterestModels.</returns>
public async Task<List<PointOfInterestModel>> GetPointOfInterestListByParkingCategoryAsync(double latitude, double longitude)
public async Task<List<PointOfInterestModel>> GetPointOfInterestListByParkingCategoryAsync(double latitude, double longitude, string poiType = null)
{
// Available categories described at https://docs.microsoft.com/en-us/azure/azure-maps/supported-search-categories
var parkingCategory = "OPEN_PARKING_AREA,PARKING_GARAGE";

return await GetPointsOfInterestAsync(
string.Format(CultureInfo.InvariantCulture, FindByCategoryUrl, latitude, longitude, parkingCategory, radius, limit));
string.Format(CultureInfo.InvariantCulture, FindByCategoryUrl, latitude, longitude, parkingCategory, radius, limit), poiType);
}

/// <summary>
Expand Down Expand Up @@ -273,7 +278,8 @@ private async Task<RouteDirections> GetRouteDirectionsAsync(string url)
if (response.StatusCode != System.Net.HttpStatusCode.BadRequest)
{
response = response.EnsureSuccessStatusCode();
apiResponse = JsonConvert.DeserializeObject<RouteDirections>(await response.Content.ReadAsStringAsync());
var content = await response.Content.ReadAsStringAsync();
apiResponse = JsonConvert.DeserializeObject<RouteDirections>(content);
}

apiResponse.Provider = PointOfInterestModel.AzureMaps;
Expand All @@ -285,7 +291,7 @@ private async Task<RouteDirections> GetRouteDirectionsAsync(string url)
/// Get search reuslts response from Azure Maps and convert to point of interest list.
/// </summary>
/// <returns>List of PointOfInterestModels.</returns>
private async Task<List<PointOfInterestModel>> GetPointsOfInterestAsync(string url)
private async Task<List<PointOfInterestModel>> GetPointsOfInterestAsync(string url, string poiType = null)
{
url = string.Concat(url, $"&language={userLocale}&subscription-key={apiKey}");

Expand All @@ -297,6 +303,19 @@ private async Task<List<PointOfInterestModel>> GetPointsOfInterestAsync(string u

if (apiResponse?.Results != null)
{
if (!string.IsNullOrEmpty(poiType))
{
if (poiType == GeoSpatialServiceTypes.PoiType.Nearest)
{
var nearestResult = apiResponse.Results.Aggregate((agg, next) => agg.Distance <= next.Distance ? agg : next);

if (nearestResult != null)
{
apiResponse.Results = new List<SearchResult> { nearestResult };
}
}
}

foreach (var searchResult in apiResponse.Results)
{
var newPointOfInterest = new PointOfInterestModel(searchResult);
Expand Down
Loading

0 comments on commit 846b822

Please sign in to comment.