Skip to content

Commit

Permalink
feat: add xapi transformer for completion events
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Aug 22, 2023
1 parent 143e821 commit e32174e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
4 changes: 3 additions & 1 deletion event_routing_backends/processors/xapi/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
XAPI_VERB_VOTED = 'https://w3id.org/xapi/openedx/verb/voted'
XAPI_VERB_REPORTED = 'https://w3id.org/xapi/acrossx/verbs/reported'
XAPI_VERB_UNREPORTED = 'https://w3id.org/xapi/openedx/verb/unreported'

XAPI_VERB_PROGRESSED = 'http://adlnet.gov/expapi/verbs/progressed'
XAPI_VERB_TERMINATED = 'http://adlnet.gov/expapi/verbs/terminated'
XAPI_VERB_ASKED = 'http://adlnet.gov/expapi/verbs/asked'

Expand All @@ -47,6 +47,7 @@
XAPI_ACTIVITY_TOTAL_COUNT = 'https://w3id.org/xapi/acrossx/extensions/total-items'
XAPI_ACTIVITY_MODE = 'https://w3id.org/xapi/acrossx/extensions/type'
XAPI_ACTIVITY_ATTEMPT = 'http://id.tincanapi.com/extension/attempt-id'
XAPI_ACTIVITY_PROGRESS = 'https://w3id.org/xapi/cmi5/result/extensions/progress'

# xAPI context
XAPI_CONTEXT_VIDEO_LENGTH = 'https://w3id.org/xapi/video/extensions/length'
Expand Down Expand Up @@ -97,6 +98,7 @@
VOTED = 'voted'
REPORTED = 'reported'
UNREPORTED = 'unreported'
PROGRESSED = 'progressed'

TERMINATED = 'terminated'
NAVIGATED = 'navigated'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
All xAPI transformers.
"""

from event_routing_backends.processors.xapi.event_transformers.completion_events import CompletionCreatedTransformer
from event_routing_backends.processors.xapi.event_transformers.enrollment_events import (
EnrollmentActivatedTransformer,
EnrollmentDeactivatedTransformer,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Transformers for forum related events.
"""
import json

from tincan import Activity, ActivityDefinition, Extensions, LanguageMap, Verb

from event_routing_backends.processors.xapi import constants
from event_routing_backends.processors.xapi.registry import XApiTransformersRegistry
from event_routing_backends.processors.xapi.transformer import XApiTransformer


@XApiTransformersRegistry.register('edx.completion.block_completion.changed')
class CompletionCreatedTransformer(XApiTransformer):
"""
Transformers for event generated when an student completion is created or updated.
"""
verb = Verb(
id=constants.XAPI_VERB_PROGRESSED,
display=LanguageMap({constants.EN: constants.PROGRESSED}),
)

def get_object(self):
"""
Get object for xAPI transformed event related to a thread.
Returns:
`Activity`
"""
print(json.dumps(self.event))
print(self.get_context_activities())
return Activity(

Check warning on line 32 in event_routing_backends/processors/xapi/event_transformers/completion_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/completion_events.py#L30-L32

Added lines #L30 - L32 were not covered by tests
id=self.get_object_iri('xblock', self.get_data('data.block_key')),
definition=ActivityDefinition(
type=constants.XAPI_ACTIVITY_RESOURCE,
extensions=Extensions({
constants.XAPI_ACTIVITY_PROGRESS: self.get_data('data.completion')*100
})
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "edx.completion.block_completion.changed",
"timestamp": "2023-08-22T20:16:25.500832Z",
"data": {
"user_id": 4,
"course_id": "course-v1:asdasd+asdasd+asdas",
"context_key": "course-v1:asdasd+asdasd+asdas",
"block_key": "block-v1:asdasd+asdasd+asdas+type@problem+block@7c54b16c8ed34f9f8772015178c7a175",
"block_type": "problem",
"completion": 1.0,
"is_new": false
},
"context": {
"course_id": "course-v1:asdasd+asdasd+asdas",
"course_user_tags": {},
"session": "056aca2a1c6b76742b283e73d3424453",
"user_id": 4,
"username": "yourusername",
"ip": "172.19.0.1",
"host": "local.overhang.io:8000",
"agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
"path": "/courses/course-v1:asdasd+asdasd+asdas/xblock/block-v1:asdasd+asdasd+asdas+type@problem+block@7c54b16c8ed34f9f8772015178c7a175/handler/xmodule_handler/problem_check",
"referer": "http://local.overhang.io:8000/xblock/block-v1:asdasd+asdasd+asdas+type@vertical+block@dd8110c941b94d929b56841195213797?show_title=0&show_bookmark_button=0&recheck_access=1&view=student_view",
"accept_language": "en-US,en;q=0.9,es;q=0.8",
"client_id": null,
"org_id": "asdasd",
"enterprise_uuid": "",
"module": {
"display_name": "Checkboxes",
"usage_key": "block-v1:asdasd+asdasd+asdas+type@problem+block@7c54b16c8ed34f9f8772015178c7a175"
}
}
}
1 change: 1 addition & 0 deletions event_routing_backends/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def plugin_settings(settings):
'edx.course.enrollment.activated',
'edx.course.enrollment.deactivated',
'edx.course.enrollment.mode_changed',
'edx.completion.block_completion.changed',
'edx.forum.thread.created',
'edx.forum.thread.deleted',
'edx.forum.thread.edited',
Expand Down

0 comments on commit e32174e

Please sign in to comment.