-
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 exam attempts events
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
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
69 changes: 69 additions & 0 deletions
69
event_routing_backends/processors/xapi/event_transformers/exam_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,69 @@ | ||
""" | ||
Transformers for enrollment related events. | ||
""" | ||
|
||
from tincan import Activity, ActivityDefinition, Extensions, LanguageMap, Verb | ||
|
||
from event_routing_backends.helpers import get_course_from_id | ||
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 | ||
|
||
|
||
class BaseExamAttemptTransformer(XApiTransformer): | ||
""" | ||
Base transformer for exam attempt events. | ||
""" | ||
|
||
def get_context_activities(self): | ||
""" | ||
Get context activities for xAPI transformed event. | ||
Returns: | ||
`ContextActivities` | ||
""" | ||
|
||
return None | ||
|
||
def get_object(self): | ||
""" | ||
Get object for xAPI transformed event. | ||
Returns: | ||
`Activity` | ||
""" | ||
object_id = 'dummy' ## TODO Load the object id from the event | ||
|
||
return Activity( | ||
id=object_id, | ||
definition=ActivityDefinition( | ||
type=constants.XAPI_ACTIVITY_ATTEMPT, | ||
extensions=Extensions({ | ||
constants.XAPI_ACTIVITY_ID: self.get_data('data.attempt_id'), | ||
constants.XAPI_ACTIVITY_ATTEMPT_STATUS: self.get_data('data.attempt_status'), | ||
constants.XAPI_ACTIVITY_ATTEMPT_TIME: self.get_data('data.attempt_event_elapsed_time_secs'), | ||
}) | ||
), | ||
) | ||
|
||
|
||
@XApiTransformersRegistry.register('edx.special_exam.practice.attempt.started') | ||
class EnrollmentActivatedTransformer(BaseExamAttemptTransformer): | ||
""" | ||
Transformers for event generated when learner start an exam attempt. | ||
""" | ||
verb = Verb( | ||
id=constants.XAPI_VERB_STARTED, | ||
display=LanguageMap({constants.EN: constants.STARTED}), | ||
) | ||
|
||
|
||
@XApiTransformersRegistry.register('edx.special_exam.practice.attempt.submitted') | ||
class EnrollmentDeactivatedTransformer(BaseExamAttemptTransformer): | ||
""" | ||
Transformers for event generated when learner submit an exam attempt. | ||
""" | ||
verb = Verb( | ||
id=constants.XAPI_VERB_SUBMITTED, | ||
display=LanguageMap({constants.EN: constants.SUBMITTED}), | ||
) |