From b84f82cceefcfa05e110ea5b817a7bf018282ec6 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 8 Sep 2023 10:11:12 -0500 Subject: [PATCH] feat: add xapi transformer for exam attempts events --- docs/event-mapping/Supported_events.rst | 6 ++ .../xapi/event_transformers/exam_events.py | 69 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 event_routing_backends/processors/xapi/event_transformers/exam_events.py diff --git a/docs/event-mapping/Supported_events.rst b/docs/event-mapping/Supported_events.rst index 92b980c6..71ba7254 100644 --- a/docs/event-mapping/Supported_events.rst +++ b/docs/event-mapping/Supported_events.rst @@ -72,6 +72,12 @@ Forum events * `edx.forum.comment.reported`_ | edX `sample <../../event_routing_backends/processors/tests/fixtures/current/edx.forum.comment.reported.json>`__ | xAPI `map <./xAPI_mapping.rst#edx.forum.comment.reported>`__ , `sample <../../event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.comment.reported.json>`__ * `edx.forum.comment.unreported`_ | edX `sample <../../event_routing_backends/processors/tests/fixtures/current/edx.forum.comment.unreported.json>`__ | xAPI `map <./xAPI_mapping.rst#edx.forum.comment.unreported>`__ , `sample <../../event_routing_backends/processors/xapi/tests/fixtures/expected/edx.forum.comment.unreported.json>`__ +Exam events +------------------ + +* `edx.special_exam.practice.attempt.started`_ | edX `sample <../../event_routing_backends/processors/tests/fixtures/current/edx.special_exam.practice.attempt.started.json>` | xAPI `map <./xAPI_mapping.rst#edx-special-exam-practire-attempt-started>` , `sample <../../event_routing_backends/processors/xapi/tests/fixtures/expected/edx.special_exam.practice.attempt.started.json>`__ +* `edx.special_exam.practice.attempt.submitted`_ | edX `sample <../../event_routing_backends/processors/tests/fixtures/current/edx.special_exam.practice.attempt.submitted.json>` | xAPI `map <./xAPI_mapping.rst#edx-special-exam-practire-attempt-submitted>` , `sample <../../event_routing_backends/processors/xapi/tests/fixtures/expected/edx.special_exam.practice.attempt.submitted.json>`__ + .. _edx.course.enrollment.activated: http://edx.readthedocs.io/projects/devdata/en/latest/internal_data_formats/tracking_logs/student_event_types.html#edx-course-enrollment-activated-and-edx-course-enrollment-deactivated .. _edx.course.enrollment.deactivated: http://edx.readthedocs.io/projects/devdata/en/latest/internal_data_formats/tracking_logs/student_event_types.html#edx-course-enrollment-activated-and-edx-course-enrollment-deactivated diff --git a/event_routing_backends/processors/xapi/event_transformers/exam_events.py b/event_routing_backends/processors/xapi/event_transformers/exam_events.py new file mode 100644 index 00000000..051868bb --- /dev/null +++ b/event_routing_backends/processors/xapi/event_transformers/exam_events.py @@ -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}), + )