-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ralph for xAPI statements generation in backend #2582
base: master
Are you sure you want to change the base?
Conversation
c5d0957
to
ccab22a
Compare
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.
ccab22a
to
45c9636
Compare
@@ -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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you are not in a LTI request you will have no relevant information.
IMO if you need to have an information from the LTI request, you have to set it in the JWT token and then retrieve it in it when you need it.
And to add the origin_url in the jwt token you should add it here I think
marsha/src/backend/marsha/core/simple_jwt/tokens.py
Lines 179 to 184 in 8b7f32c
token.payload.update( | |
{ | |
"context_id": lti.context_id, | |
"consumer_site": str(lti.get_consumer_site().id), | |
} | |
) |
return ( | ||
jwt_token.payload["user"].get("username") | ||
if jwt_token.payload.get("user") | ||
else None | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ( | |
jwt_token.payload["user"].get("username") | |
if jwt_token.payload.get("user") | |
else None | |
) | |
return jwt_token.payload.get("user", {}).get("username") |
} | ||
return BaseXapiAgentWithAccount( | ||
account=BaseXapiAccount(homePage=homepage, name=str(user.id)), | ||
name=user.username, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
field of the actor is optionnal. Should we avoid setting it, facilitating our future work on anonymization?
If we decide to keep it, should'nt it be a full name instead of username?
"account": {"name": user_id, "homePage": homepage}, | ||
} | ||
return BaseXapiAgentWithAccount( | ||
name=username, account=BaseXapiAccount(homePage=homepage, name=user_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
statement = self.build_common_statement_properties( | ||
statement, homepage, user=user, user_id=user_id | ||
statement, homepage, user=user, user_id=user_id, username=username | ||
) | ||
|
||
statement["context"].update( | ||
{"contextActivities": {"category": [{"id": "https://w3id.org/xapi/lms"}]}} | ||
{ | ||
"contextActivities": { | ||
"category": [LMSProfileActivity().model_dump(exclude_none=True)] | ||
} | ||
} | ||
) | ||
|
||
statement["object"] = { | ||
"definition": { | ||
"type": "http://id.tincanapi.com/activitytype/document", | ||
"name": {self.get_locale(): document.title}, | ||
}, | ||
"id": f"uuid://{document.id}", | ||
"objectType": "Activity", | ||
} | ||
statement["object"] = DocumentActivity( | ||
definition=DocumentActivityDefinition( | ||
name={self.get_locale(): document.title} | ||
), | ||
id=f"uuid://{document.id}", | ||
).model_dump(exclude_none=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to use BaseXapiStatement
from ralph to build these core properties?
if statement["verb"]["id"] == "http://id.tincanapi.com/verb/downloaded": | ||
statement["context"].update( | ||
{ | ||
"contextActivities": { | ||
"category": [LMSProfileActivity().model_dump(exclude_none=True)] | ||
} | ||
} | ||
) | ||
else: | ||
statement["context"].update( | ||
{ | ||
"contextActivities": { | ||
"category": [ | ||
VideoProfileActivity().model_dump(exclude_none=True) | ||
] | ||
} | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, would it be possible to work with ralph pydantic models instead of modifying a dict directly?
We could use them without any validation using a .construct()
Purpose
We want to use Ralph to generate xAPI statements for videos, documents, webinar
and lives. Based on Pydantic models, it would strengthen validation to avoid potential
errors when statements are sent to a LRS.
Proposal