-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add xapi transformer for completion events
- Loading branch information
Showing
5 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
40 changes: 40 additions & 0 deletions
40
event_routing_backends/processors/xapi/event_transformers/completion_events.py
This file contains 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
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( | ||
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 | ||
}) | ||
), | ||
) |
33 changes: 33 additions & 0 deletions
33
event_routing_backends/processors/xapi/event_transformers/event.json
This file contains 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
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" | ||
} | ||
} | ||
} |
This file contains 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