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

Check warning on line 5 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L5

Added line #L5 was not covered by tests

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

Check warning on line 10 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L7-L10

Added lines #L7 - L10 were not covered by tests


class BaseExamAttemptTransformer(XApiTransformer):

Check warning on line 13 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L13

Added line #L13 was not covered by tests
"""
Base transformer for exam attempt events.
"""

def get_context_activities(self):

Check warning on line 18 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L18

Added line #L18 was not covered by tests
"""
Get context activities for xAPI transformed event.
Returns:
`ContextActivities`
"""

return None

Check warning on line 26 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L26

Added line #L26 was not covered by tests

def get_object(self):

Check warning on line 28 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L28

Added line #L28 was not covered by tests
"""
Get object for xAPI transformed event.
Returns:
`Activity`
"""
object_id = 'dummy' ## TODO Load the object id from the event

Check warning on line 35 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L35

Added line #L35 was not covered by tests

return Activity(

Check warning on line 37 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L37

Added line #L37 was not covered by tests
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):

Check warning on line 51 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L51

Added line #L51 was not covered by tests
"""
Transformers for event generated when learner start an exam attempt.
"""
verb = Verb(

Check warning on line 55 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L55

Added line #L55 was not covered by tests
id=constants.XAPI_VERB_STARTED,
display=LanguageMap({constants.EN: constants.STARTED}),
)


@XApiTransformersRegistry.register('edx.special_exam.practice.attempt.submitted')
class EnrollmentDeactivatedTransformer(BaseExamAttemptTransformer):

Check warning on line 62 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L62

Added line #L62 was not covered by tests
"""
Transformers for event generated when learner submit an exam attempt.
"""
verb = Verb(

Check warning on line 66 in event_routing_backends/processors/xapi/event_transformers/exam_events.py

View check run for this annotation

Codecov / codecov/patch

event_routing_backends/processors/xapi/event_transformers/exam_events.py#L66

Added line #L66 was not covered by tests
id=constants.XAPI_VERB_SUBMITTED,
display=LanguageMap({constants.EN: constants.SUBMITTED}),
)

0 comments on commit b84f82c

Please sign in to comment.