Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save predictioniogists/6517307 to your computer and use it in GitHub Desktop.
Save predictioniogists/6517307 to your computer and use it in GitHub Desktop.
import predictionio
# 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:
cient = predictionio.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.create_user("the new user ID")
except Exception as e:
log_error(e) # log the error for debugging or retry importing later
# When a new course is added:
try:
client.create_item("the new course ID", ("course category 1",))
except Exception as e:
log_error(e) # log the error for debugging or retry importing later
# When your user logs in:
try:
client.identify("the logged-in user ID")
except Exception as e:
log_error(e) # log the error for debugging or retry importing later
# When the logged-in user clicks or views a course:
try:
client.record_action_on_item("view", "the viewed course ID")
except Exception as e:
log_error(e) # log the error for debugging or retry importing later
# When the logged-in user enrolls a course:
# use built-in action "conversion" to represent the "enroll" action
try:
client.record_action_on_item("conversion", "the enrolled course ID")
except Exception as e:
log_error(e) # log the error for debugging or retry importing later
# When the logged-in user rates a course:
# the variable rating stores the rating value (from 1 to 5 )
try:
client.record_action_on_item("rate", "rated course ID", { "pio_rate": rating })
except Exception as e:
log_error(e) # log the error for debugging or retry importing later
@thomasrorystone
Copy link

in Line 6:

cient = predictionio.Client("your App Key")

should be:

client = predictionio.Client("your App Key")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment