Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save dlhaines/9ca6b5cda7b7da93654a444bcc42cf0a to your computer and use it in GitHub Desktop.

Select an option

Save dlhaines/9ca6b5cda7b7da93654a444bcc42cf0a to your computer and use it in GitHub Desktop.
"Caliper: Basic Example" uses Jupyter Notebook to demonstrate IMS Global's Caliper for Python.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# coding: utf-8
# Caliper: Basic Example
# Lance E Sloan - https://gist.github.com/lsloan
import caliper
from datetime import datetime, timezone
import getpass
sensorId = getpass.getuser() + '_caliper_python_example'
endpointUrl = 'https://lti.tools/caliper/event?key=' + sensorId
sensorConfiguration = caliper.HttpOptions(
host=endpointUrl,
auth_scheme='Bearer',
api_key='no-key-required-for-lti.tools',)
sensor = caliper.build_sensor_from_config(
sensor_id = 'urn:' + sensorId,
config_options = sensorConfiguration,)
eventTime = datetime.now(timezone.utc).isoformat()
aPerson = caliper.entities.Person(
id='urn:/user/193828',)
aCourse = caliper.entities.CourseSection(
id='urn:/course/4077',
courseNumber='SSED514',
name='Economy and Society',
category='lecture',)
aResource = caliper.entities.DigitalResource(
id='urn:/course/4077/resource/1',
name='Lecture Introduction',
description='Lecture Introduction',)
aPersonCourseMembership = caliper.entities.Membership(
id='urn:/course/4077/member/193828',
member=aPerson,
organization=aCourse,
roles=[caliper.constants.CALIPER_ROLES['LEARNER']],
status=caliper.constants.CALIPER_STATUS['ACTIVE'],)
aPersonSession = caliper.entities.Session(
id='urn:/session/379053173489041',
user=aPerson,)
navEvent = caliper.events.NavigationEvent(
actor=aPerson,
action=caliper.constants.BASIC_EVENT_ACTIONS['NAVIGATED_TO'],
object=aResource,
eventTime = eventTime,
membership=aPersonCourseMembership,
session=aPersonSession,)
sensor.send(navEvent)
actorDescribe = sensor.describe(navEvent.actor)
sensor.send(navEvent, described_objects=actorDescribe['default'])
@dlhaines
Copy link
Copy Markdown
Author

May want to mention that homebrew is also a quick way to install Jupyter Notebook on OSX. Anaconda is a fine way to get a tool rich environment though there is additional overhead learning to use it.

May also want to point out that when doing the 'source activate base' the user is entering the land of virtual environments. They don't need to know more unless they find that they need to start customizing their runtime environment. That's a good time to start learning about virtual environments.

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