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 5994c6a
Showing 1 changed file with 69 additions and 0 deletions.
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 5994c6a

Please sign in to comment.