Last active
December 23, 2015 23:08
-
-
Save predictioniogists/6707523 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.prediction.Client; | |
import io.prediction.UserActionItemRequestBuilder; | |
import io.prediction.CreateItemRequestBuilder; | |
// In the beginning of your application, you need to instantiate the PredictionIO client object. | |
// You need this client object to import data into PredictionIO and retrieve prediction results. | |
// Add this line to the place where you do initialization: | |
Client client = new Client("your app key"); | |
// Then add the following lines to your codes which handle the corresponding application logic: | |
// When a new user registers: | |
try { | |
client.createUser("new user id"); | |
} catch (Exception e) { | |
handleException(e); | |
} | |
// When a new driver registers or an existing driver changes location: | |
try { | |
String[] itypes = {"drivers"}; // NOTE: the item itype is "drivers" | |
CreateItemRequestBuilder builder = client.getCreateItemRequestBuilder("new or existing driver id", itypes) | |
.latitude(latitude) // current latitude of the driver. eg latitude = 37.7881 | |
.longitude(longitude); // current longitude of the driver. eg longitude = 122.4075 | |
client.createItem(builder); | |
} catch (Exception e) { | |
handleException(e); | |
} | |
// When a user logs in: | |
client.identify("the logged-in user ID"); | |
// When the logged-in user views a driver: | |
try { | |
client.userActionItem("view", "the viewed driver id"); | |
} catch (Exception e) { | |
handleException(e); | |
} | |
// When the logged-in user rates the driver after the ride: | |
// the variable rating stores the rating value (from 1 to 5) | |
try { | |
UserActionItemRequestBuilder builder = client.getUserActionItemRequestBuilder("rate", "the rated driver id") | |
.rate(rating); | |
client.userActionItem(builder); | |
} catch (Exception e) { | |
handleException(e); | |
} | |
// When the logged-in user pays the driver after the ride: | |
// Use built-in action "conversion" to represent the "pay" action | |
try { | |
client.userActionItem("conversion", "the driver id"); | |
} catch (Exception e) { | |
handleException(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment