Skip to content

Commit

Permalink
feat: add xapi transformer for exam attempts events
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Sep 8, 2023
1 parent bbe9f25 commit b84f82c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/event-mapping/Supported_events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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}),
)

0 comments on commit b84f82c

Please sign in to comment.