-
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
fix: add attempt type for exam attempt events fix: add context data to event attempt events test: add fixtures for special exams refactor: use exam object for event attempts fix: add missing xapi concepts for exam events fix: use scorm pattern for exam events test: add fixtures for special exams
- Loading branch information
Showing
10 changed files
with
335 additions
and
2 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
38 changes: 38 additions & 0 deletions
38
...ng_backends/processors/tests/fixtures/current/edx.special_exam.timed.attempt.created.json
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,38 @@ | ||
{ | ||
"name": "edx.special_exam.timed.attempt.created", | ||
"context": { | ||
"user_id": 3, | ||
"path": "/api/edx_proctoring/v1/proctored_exam/attempt", | ||
"course_id": "course-v1:edX+DemoX+Demo_Course", | ||
"org_id": "edX", | ||
"enterprise_uuid": "" | ||
}, | ||
"username": "student", | ||
"session": "1c7862f091c5d7232ad3d7cf558f6e80", | ||
"ip": "172.18.0.1", | ||
"agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36", | ||
"host": "localhost:18000", | ||
"referer": "http://localhost:18000", | ||
"accept_language": "en-US,en;q=0.9", | ||
"event": { | ||
"exam_id": 1, | ||
"exam_content_id": "block-v1:edX+DemoX+Demo_Course+type@sequential+block@5b4bf8d7d41c4070b299abefed74155e", | ||
"exam_name": "Subsection", | ||
"exam_default_time_limit_mins": 60, | ||
"exam_is_proctored": false, | ||
"exam_is_practice_exam": false, | ||
"exam_is_active": true, | ||
"attempt_id": 1, | ||
"attempt_user_id": 3, | ||
"attempt_started_at": null, | ||
"attempt_completed_at": null, | ||
"attempt_code": "438AD672-DE2C-4F0B-8876-35444E7DD746", | ||
"attempt_allowed_time_limit_mins": null, | ||
"attempt_status": "created", | ||
"attempt_event_elapsed_time_secs": null | ||
}, | ||
"time": "2023-09-08T15:58:04.833393+00:00", | ||
"event_type": "edx.special_exam.timed.attempt.created", | ||
"event_source": "server", | ||
"page": null | ||
} |
38 changes: 38 additions & 0 deletions
38
..._backends/processors/tests/fixtures/current/edx.special_exam.timed.attempt.submitted.json
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,38 @@ | ||
{ | ||
"name": "edx.special_exam.timed.attempt.submitted", | ||
"context": { | ||
"user_id": 3, | ||
"path": "/api/edx_proctoring/v1/proctored_exam/attempt/1", | ||
"course_id": "course-v1:edX+DemoX+Demo_Course", | ||
"org_id": "edX", | ||
"enterprise_uuid": "" | ||
}, | ||
"username": "student", | ||
"session": "1c7862f091c5d7232ad3d7cf558f6e80", | ||
"ip": "172.18.0.1", | ||
"agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36", | ||
"host": "localhost:18000", | ||
"referer": "http://localhost:18000", | ||
"accept_language": "en-US,en;q=0.9", | ||
"event": { | ||
"exam_id": 1, | ||
"exam_content_id": "block-v1:edX+DemoX+Demo_Course+type@sequential+block@5b4bf8d7d41c4070b299abefed74155e", | ||
"exam_name": "Subsection", | ||
"exam_default_time_limit_mins": 60, | ||
"exam_is_proctored": false, | ||
"exam_is_practice_exam": false, | ||
"exam_is_active": true, | ||
"attempt_id": 1, | ||
"attempt_user_id": 3, | ||
"attempt_started_at": "2023-09-08T15:58:04.838598+00:00", | ||
"attempt_completed_at": "2023-09-08T16:20:53.577698+00:00", | ||
"attempt_code": "438AD672-DE2C-4F0B-8876-35444E7DD746", | ||
"attempt_allowed_time_limit_mins": 60, | ||
"attempt_status": "submitted", | ||
"attempt_event_elapsed_time_secs": 1368.7657 | ||
}, | ||
"time": "2023-09-08T16:20:53.604375+00:00", | ||
"event_type": "edx.special_exam.timed.attempt.submitted", | ||
"event_source": "server", | ||
"page": null | ||
} |
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
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
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
116 changes: 116 additions & 0 deletions
116
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,116 @@ | ||
""" | ||
Transformers for enrollment related events. | ||
""" | ||
|
||
from tincan import Activity, ActivityDefinition, Extensions, LanguageMap, Verb | ||
|
||
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 BaseExamTransformer(XApiTransformer): | ||
""" | ||
Base transformer for exam events. | ||
""" | ||
|
||
def get_object(self): | ||
""" | ||
Get object for xAPI transformed event. | ||
Returns: | ||
`Activity` | ||
""" | ||
object_id = self.get_data("event.exam_content_id") | ||
exam_type = self.get_data("name").split(".")[2] | ||
|
||
return Activity( | ||
id=object_id, | ||
definition=ActivityDefinition( | ||
type=constants.XAPI_ACTIVITY_ASSESSMENT_FORMAT.format(exam_type), | ||
name=LanguageMap(**({constants.EN: self.get_data("event.exam_name")})), | ||
extensions=Extensions( | ||
{ | ||
constants.XAPI_ACTIVITY_PRACTICE_EXAM: self.get_data( | ||
"event.exam_is_practice_exam" | ||
), | ||
constants.XAPI_ACTIVITY_PROCTORED_EXAM: self.get_data( | ||
"event.exam_is_proctored" | ||
), | ||
constants.XAPI_ACTIVITY_COURSE: self.get_data( | ||
"event.course_id" | ||
), | ||
constants.XAPI_ACTIVITY_TIME_LIMIT: self.get_data( | ||
"event.exam_default_time_limit_mins" | ||
) | ||
} | ||
), | ||
), | ||
) | ||
|
||
def get_context_activities(self): | ||
context_activities = super().get_context_activities() | ||
|
||
context_activities.grouping = [ | ||
Activity( | ||
id=self.get_data("event.attempt_code"), | ||
definition=ActivityDefinition( | ||
type=constants.XAPI_ACTIVITY_EXAM_ATTEMPT, | ||
name=LanguageMap({constants.EN: self.get_data("event.exam_name")}), | ||
extensions=Extensions( | ||
{ | ||
constants.XAPI_CONTEXT_ATTEMPT_STARTED: self.get_data( | ||
"event.attempt_started_at" | ||
), | ||
constants.XAPI_CONTEXT_ATTEMPT_COMPLETED: self.get_data( | ||
"event.attempt_completed_at" | ||
), | ||
constants.XAPI_CONTEXT_ATTEMPT_TIME: self.get_data( | ||
"event.attempt_event_elapsed_time_secs" | ||
), | ||
constants.XAPI_CONTEXT_ID: self.get_data("event.attempt_id"), | ||
} | ||
), | ||
), | ||
), | ||
] | ||
|
||
return context_activities | ||
|
||
|
||
@XApiTransformersRegistry.register("edx.special_exam.timed.attempt.created") | ||
class PracticeExamStartedTransformer(BaseExamTransformer): | ||
""" | ||
Transformers for event generated when learner start an exam attempt. | ||
""" | ||
|
||
verb = Verb( | ||
id=constants.XAPI_VERB_INITIALIZED, | ||
display=LanguageMap({constants.EN: constants.INITIALIZED}), | ||
) | ||
|
||
def get_context_extensions(self): | ||
return ( | ||
super() | ||
.get_context_extensions() | ||
.update({constants.XAPI_CONTEXT_ATTEMPT_TYPE: "timed"}) | ||
) | ||
|
||
|
||
@XApiTransformersRegistry.register("edx.special_exam.timed.attempt.submitted") | ||
class PracticeExamSubmittedTransformer(BaseExamTransformer): | ||
""" | ||
Transformers for event generated when learner submit an exam attempt. | ||
""" | ||
|
||
verb = Verb( | ||
id=constants.XAPI_VERB_TERMINATED, | ||
display=LanguageMap({constants.EN: constants.TERMINATED}), | ||
) | ||
|
||
def get_context_extensions(self): | ||
return ( | ||
super() | ||
.get_context_extensions() | ||
.update({constants.XAPI_CONTEXT_ATTEMPT_TYPE: "timed"}) | ||
) |
50 changes: 50 additions & 0 deletions
50
...kends/processors/xapi/tests/fixtures/expected/edx.special_exam.timed.attempt.created.json
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,50 @@ | ||
{ | ||
"id": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb", | ||
"version": "1.0.3", | ||
"actor": { | ||
"objectType": "Agent", | ||
"account": { "name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb", "homePage": "http://localhost:18000" } | ||
}, | ||
"verb": { "id": "http://adlnet.gov/expapi/verbs/initialized", "display": { "en": "initialized" } }, | ||
"object": { | ||
"id": "block-v1:edX+DemoX+Demo_Course+type@sequential+block@5b4bf8d7d41c4070b299abefed74155e", | ||
"objectType": "Activity", | ||
"definition": { | ||
"name": { "en": "Subsection" }, | ||
"type": "https://w3id.org/xapi/openedx/activity/timed-assessment", | ||
"extensions": { | ||
"https://w3id.org/xapi/openedx/extension/practice-exam": false, | ||
"https://w3id.org/xapi/openedx/extension/proctored-exam": false, | ||
"https://w3id.org/xapi/acrossx/extensions/time-limit": 60 | ||
} | ||
} | ||
}, | ||
"timestamp": "2023-09-08T15:58:04.833393+00:00", | ||
"context": { | ||
"contextActivities": { | ||
"parent": [ | ||
{ | ||
"id": "http://localhost:18000/course/course-v1:edX+DemoX+Demo_Course", | ||
"objectType": "Activity", | ||
"definition": { | ||
"name": { "en-US": "Demonstration Course" }, | ||
"type": "http://adlnet.gov/expapi/activities/course" | ||
} | ||
} | ||
], | ||
"grouping": [ | ||
{ | ||
"id": "438AD672-DE2C-4F0B-8876-35444E7DD746", | ||
"objectType": "Activity", | ||
"definition": { | ||
"name": { "en": "Subsection" }, | ||
"type": "http://adlnet.gov/expapi/activities/attempt", | ||
"extensions": { | ||
"https://w3id.org/xapi/openedx/extension/id": 1 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...nds/processors/xapi/tests/fixtures/expected/edx.special_exam.timed.attempt.submitted.json
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,53 @@ | ||
{ | ||
"id": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb", | ||
"version": "1.0.3", | ||
"actor": { | ||
"objectType": "Agent", | ||
"account": { "name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb", "homePage": "http://localhost:18000" } | ||
}, | ||
"verb": { "id": "http://adlnet.gov/expapi/verbs/terminated", "display": { "en": "terminated" } }, | ||
"object": { | ||
"id": "block-v1:edX+DemoX+Demo_Course+type@sequential+block@5b4bf8d7d41c4070b299abefed74155e", | ||
"objectType": "Activity", | ||
"definition": { | ||
"name": { "en": "Subsection" }, | ||
"type": "https://w3id.org/xapi/openedx/activity/timed-assessment", | ||
"extensions": { | ||
"https://w3id.org/xapi/openedx/extension/practice-exam": false, | ||
"https://w3id.org/xapi/openedx/extension/proctored-exam": false, | ||
"https://w3id.org/xapi/acrossx/extensions/time-limit": 60 | ||
} | ||
} | ||
}, | ||
"timestamp": "2023-09-08T16:20:53.604375+00:00", | ||
"context": { | ||
"contextActivities": { | ||
"parent": [ | ||
{ | ||
"id": "http://localhost:18000/course/course-v1:edX+DemoX+Demo_Course", | ||
"objectType": "Activity", | ||
"definition": { | ||
"name": { "en-US": "Demonstration Course" }, | ||
"type": "http://adlnet.gov/expapi/activities/course" | ||
} | ||
} | ||
], | ||
"grouping": [ | ||
{ | ||
"id": "438AD672-DE2C-4F0B-8876-35444E7DD746", | ||
"objectType": "Activity", | ||
"definition": { | ||
"name": { "en": "Subsection" }, | ||
"type": "http://adlnet.gov/expapi/activities/attempt", | ||
"extensions": { | ||
"https://w3id.org/xapi/openedx/extension/attempt-started": "2023-09-08T15:58:04.838598+00:00", | ||
"https://w3id.org/xapi/openedx/extension/attempt-completed": "2023-09-08T16:20:53.577698+00:00", | ||
"https://w3id.org/xapi/openedx/extension/attempt-time": 1368.7657, | ||
"https://w3id.org/xapi/openedx/extension/id": 1 | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
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