Skip to content

Instantly share code, notes, and snippets.

@rubysoho07
Last active August 3, 2018 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubysoho07/810d7b0e4c2b94fb1a8fb1af625a6c6c to your computer and use it in GitHub Desktop.
Save rubysoho07/810d7b0e4c2b94fb1a8fb1af625a6c6c to your computer and use it in GitHub Desktop.
Caliper Example 2. Describing Event
import datetime
from caliper import entities, events
from caliper.constants import CALIPER_ACTIONS
event = events.SessionEvent(
actor=entities.Person(id='http://example.org/person/123', name='Test'),
action=CALIPER_ACTIONS['LOGGED_IN']
object=entities.SoftwareApplication(id='http://example.org/app/testservice', name='Learning Analytics Example'),
eventTime=datetime.datetime.utcnow().isoformat(timespec='milliseconds') + 'Z'
)
print(event.as_json(thin_context=True, thin_props=True))
# Result
"""
{
"@context":"http://purl.imsglobal.org/ctx/caliper/v1p1",
"action":"LoggedIn",
"actor":{
"id":"http://example.org/person/123",
"name":"Test",
"type":"Person"
},
"eventTime":"2018-07-09T10:22:47.856Z",
"id":"urn:uuid:ac188287-ea71-4fe4-a283-8919190891ad",
"object":{
"id":"http://example.org/app/testservice",
"name":"Learning Analytics Example",
"type":"SoftwareApplication"
},
"type":"SessionEvent"
}
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment