Skip to content

Commit

Permalink
✨(xapi) add ralph-malph library for statements generation
Browse files Browse the repository at this point in the history
Finally, we have integrated Ralph in marsha to help generate xAPI statements
with Pydantic! However the integration is partial as statements are initialized
from the frontend.
  • Loading branch information
quitterie-lcs committed May 6, 2024
1 parent 8b7f32c commit ccab22a
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 101 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).

### Added

- Integrate `ralph-malph` library for xAPI statements generation
- Add scaleway storage configuration
- Add Peertube pipeline to VOD
- Celery task queue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_xapi_statement_document_resource(self):

session_id = str(uuid.uuid4())
jwt_token = UserAccessTokenFactory()
print(jwt_token.__dict__)

data = {
"verb": {
Expand Down
96 changes: 74 additions & 22 deletions src/backend/marsha/core/tests/test_xapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def test_xapi_statement_missing_user(self):
"name": {"en-US": "test video xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -91,11 +90,17 @@ def test_xapi_statement_missing_user(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/video"}],
"category": [
{
"id": "https://w3id.org/xapi/video",
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
}
],
"parent": [
{
"id": "course-v1:ufr+mathematics+0001",
"objectType": "Activity",
"definition": {
"type": "http://adlnet.gov/expapi/activities/course"
},
Expand All @@ -121,6 +126,7 @@ def test_xapi_statement_enrich_statement(self):
session_id="326c0689-48c1-493e-8d2d-9fb0c289de7f",
context_id="course-v1:ufr+mathematics+0001",
user__id="b2584aa405540758db2a6278521b6478",
user__username="johndoe",
)

base_statement = {
Expand Down Expand Up @@ -153,6 +159,7 @@ def test_xapi_statement_enrich_statement(self):
self.assertEqual(
statement["actor"],
{
"name": "johndoe",
"objectType": "Agent",
"account": {
"name": "b2584aa405540758db2a6278521b6478",
Expand All @@ -168,7 +175,6 @@ def test_xapi_statement_enrich_statement(self):
"name": {"en-US": "test video xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -179,11 +185,17 @@ def test_xapi_statement_enrich_statement(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/video"}],
"category": [
{
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
"id": "https://w3id.org/xapi/video",
}
],
"parent": [
{
"id": "course-v1:ufr+mathematics+0001",
"objectType": "Activity",
"definition": {
"type": "http://adlnet.gov/expapi/activities/course"
},
Expand All @@ -210,6 +222,7 @@ def test_xapi_statement_live_video(self):
session_id="326c0689-48c1-493e-8d2d-9fb0c289de7f",
context_id="course-v1:ufr+mathematics+0001",
user__id="b2584aa405540758db2a6278521b6478",
user__username="johndoe",
)

base_statement = {
Expand Down Expand Up @@ -242,6 +255,7 @@ def test_xapi_statement_live_video(self):
self.assertEqual(
statement["actor"],
{
"name": "johndoe",
"objectType": "Agent",
"account": {
"name": "b2584aa405540758db2a6278521b6478",
Expand All @@ -257,7 +271,6 @@ def test_xapi_statement_live_video(self):
"name": {"en-US": "test video xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -268,11 +281,17 @@ def test_xapi_statement_live_video(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/video"}],
"category": [
{
"id": "https://w3id.org/xapi/video",
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
}
],
"parent": [
{
"id": "course-v1:ufr+mathematics+0001",
"objectType": "Activity",
"definition": {
"type": "http://adlnet.gov/expapi/activities/course"
},
Expand Down Expand Up @@ -300,6 +319,7 @@ def test_xapi_statement_live_video_ended(self):
session_id="326c0689-48c1-493e-8d2d-9fb0c289de7f",
context_id="course-v1:ufr+mathematics+0001",
user__id="b2584aa405540758db2a6278521b6478",
user__username="johndoe",
)

base_statement = {
Expand Down Expand Up @@ -332,6 +352,7 @@ def test_xapi_statement_live_video_ended(self):
self.assertEqual(
statement["actor"],
{
"name": "johndoe",
"objectType": "Agent",
"account": {
"name": "b2584aa405540758db2a6278521b6478",
Expand All @@ -347,7 +368,6 @@ def test_xapi_statement_live_video_ended(self):
"name": {"en-US": "test video xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -358,11 +378,17 @@ def test_xapi_statement_live_video_ended(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/video"}],
"category": [
{
"id": "https://w3id.org/xapi/video",
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
}
],
"parent": [
{
"id": "course-v1:ufr+mathematics+0001",
"objectType": "Activity",
"definition": {
"type": "http://adlnet.gov/expapi/activities/course"
},
Expand Down Expand Up @@ -434,7 +460,6 @@ def test_xapi_statement_missing_context_id(self):
"name": {"en-US": "test video xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -445,7 +470,14 @@ def test_xapi_statement_missing_context_id(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/video"}]
"category": [
{
"id": "https://w3id.org/xapi/video",
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
}
]
},
},
)
Expand All @@ -470,6 +502,7 @@ def test_xapi_statement_enrich_statement(self):
session_id="326c0689-48c1-493e-8d2d-9fb0c289de7f",
context_id="course-v1:ufr+mathematics+0001",
user__id="b2584aa405540758db2a6278521b6478",
user__username="johndoe",
)

base_statement = {
Expand All @@ -493,6 +526,7 @@ def test_xapi_statement_enrich_statement(self):
self.assertEqual(
statement["actor"],
{
"name": "johndoe",
"objectType": "Agent",
"account": {
"name": "b2584aa405540758db2a6278521b6478",
Expand All @@ -508,7 +542,6 @@ def test_xapi_statement_enrich_statement(self):
"name": {"en-US": "test document xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -519,11 +552,17 @@ def test_xapi_statement_enrich_statement(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/lms"}],
"category": [
{
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
"id": "https://w3id.org/xapi/lms",
}
],
"parent": [
{
"id": "course-v1:ufr+mathematics+0001",
"objectType": "Activity",
"definition": {
"type": "http://adlnet.gov/expapi/activities/course"
},
Expand All @@ -547,6 +586,7 @@ def test_xapi_statement_missing_context_id(self):
jwt_token = LTIPlaylistAccessTokenFactory(
session_id="326c0689-48c1-493e-8d2d-9fb0c289de7f",
user__id="b2584aa405540758db2a6278521b6478",
user__username="johndoe",
)
del jwt_token.payload["context_id"]

Expand All @@ -571,6 +611,7 @@ def test_xapi_statement_missing_context_id(self):
self.assertEqual(
statement["actor"],
{
"name": "johndoe",
"objectType": "Agent",
"account": {
"name": "b2584aa405540758db2a6278521b6478",
Expand All @@ -586,7 +627,6 @@ def test_xapi_statement_missing_context_id(self):
"name": {"en-US": "test document xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -597,7 +637,14 @@ def test_xapi_statement_missing_context_id(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/lms"}]
"category": [
{
"id": "https://w3id.org/xapi/lms",
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
}
]
},
},
)
Expand Down Expand Up @@ -655,7 +702,6 @@ def test_xapi_statement_missing_user_id(self):
"name": {"en-US": "test document xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -666,11 +712,17 @@ def test_xapi_statement_missing_user_id(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/lms"}],
"category": [
{
"id": "https://w3id.org/xapi/lms",
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
}
],
"parent": [
{
"id": "course-v1:ufr+mathematics+0001",
"objectType": "Activity",
"definition": {
"type": "http://adlnet.gov/expapi/activities/course"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def test_xapi_statement_enrich_statement(self):
self.assertEqual(
statement["actor"],
{
"name": f"{user.username}",
"objectType": "Agent",
"account": {
"name": f"{user.id}",
"homePage": "http://marsha.education",
"mbox": "mailto:[email protected]",
},
},
)
Expand All @@ -57,7 +57,6 @@ def test_xapi_statement_enrich_statement(self):
"name": {"en-US": "test document xapi"},
},
"id": "uuid://68333c45-4b8c-4018-a195-5d5e1706b838",
"objectType": "Activity",
},
)
self.assertEqual(
Expand All @@ -68,7 +67,14 @@ def test_xapi_statement_enrich_statement(self):
"43b4-8452-2037fed588df"
},
"contextActivities": {
"category": [{"id": "https://w3id.org/xapi/lms"}]
"category": [
{
"definition": {
"type": "http://adlnet.gov/expapi/activities/profile"
},
"id": "https://w3id.org/xapi/lms",
}
]
},
},
)
Expand Down
Loading

0 comments on commit ccab22a

Please sign in to comment.