Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save predictioniogists/6707826 to your computer and use it in GitHub Desktop.
Save predictioniogists/6707826 to your computer and use it in GitHub Desktop.
import io.prediction.ItemRecGetTopNRequestBuilder;
// You need to specify the name of the engine from which you want to retrieve the prediction results.
// Add the following code to display recommended drivers to the logged-in user:
String[] driverIds;
try {
// Retrieve top 5 recommended drivers from the item recommendation engine.
// Assuming client.identify("user id") is already called when the user logged in.
ItemRecGetTopNRequestBuilder builder = client.getItemRecGetTopNRequestBuilder("the engine name", 5)
.latitude(latitude) // current latitude of the user. eg. latitude = 37.7881
.longitude(longitude); // current longitude of the user. eg. longitude = 122.4075
driverIds = client.getItemRecTopN(builder);
} catch (Exception e) { // exception is raised when there is no prediction result.
driverIds = getDefaultDrivers(5); // default behavior when there is no recommendation. eg. get nearest 5 drivers
handleException(e);
}
displayDrivers(driverIds); // display drivers to the user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment