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 7, 2024
1 parent 8b7f32c commit 45c9636
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 128 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
3 changes: 3 additions & 0 deletions src/backend/marsha/core/api/xapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from marsha.core import permissions, serializers
from marsha.core.api.base import APIViewMixin
from marsha.core.defaults import XAPI_STATEMENT_ID_CACHE
from marsha.core.lti import LTI
from marsha.core.xapi import XAPI, get_xapi_statement


Expand All @@ -41,10 +42,12 @@ def _statement_from_lti(
xapi_logger = logging.getLogger(f"xapi.{consumer_site.domain}")

# xapi statement enriched with video and jwt_token information
lti = LTI(request, object_instance)
xapi_statement = statement_class.from_lti(
object_instance,
partial_xapi_statement.validated_data,
request.resource.token,
lti.origin_url
)

# Log the statement in the xapi logger
Expand Down
2 changes: 1 addition & 1 deletion src/backend/marsha/core/lti/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, request, resource_id=None):
request : django.http.request.HttpRequest
The request that holds the LTI parameters
resource_id : uuid.uuid4
The primary key of the video targetted by the LTI query as a UUID.
The primary key of the video targeted by the LTI query as a UUID.
"""
self.resource_id = resource_id
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from logging_ldp.formatters import LDPGELFFormatter

from marsha.core.defaults import XAPI_STATEMENT_ID_CACHE
from marsha.core.factories import VideoFactory
from marsha.core.factories import VideoFactory, UserFactory
from marsha.core.simple_jwt.factories import UserAccessTokenFactory


Expand Down Expand Up @@ -199,7 +199,8 @@ def test_xapi_statement_with_two_same_event(self):
"""
video = VideoFactory()
jwt_token = UserAccessTokenFactory()

user=UserFactory(username="johndoe")
print(user)
data = {
"id": "7b18195e-e183-4bbf-b8ef-5145ef64ae19",
"verb": {
Expand Down
Loading

0 comments on commit 45c9636

Please sign in to comment.