Forked from predictioniogists/ UseCase_OnlineCourse_PythonSDK_import_data.py
Last active
August 29, 2015 13:57
-
-
Save thomasrorystone/9921753 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 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: | |
client = 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment