-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add transformer to files downloaded event (#35)
- Loading branch information
Showing
29 changed files
with
317 additions
and
102 deletions.
There are no files selected for viewing
Empty file.
Empty file.
27 changes: 27 additions & 0 deletions
27
filesmanager/edxapp_wrapper/backends/event_routing_backends_p_v1.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,27 @@ | ||
"""Backend for event-routing-backends library. | ||
This is required since the library has explicit dependencies from openedx platform. | ||
https://github.com/openedx/event-routing-backends | ||
""" | ||
from event_routing_backends.processors.xapi.registry import XApiTransformersRegistry # pylint: disable=import-error | ||
from event_routing_backends.processors.xapi.transformer import XApiTransformer # pylint: disable=import-error | ||
|
||
|
||
def get_xapi_transformer_registry(): | ||
"""Allow to get the XApiTransformersRegistry class from | ||
https://github.com/openedx/event-routing-backends/blob/master/event_routing_backends/processors/xapi/registry.py#L7 | ||
Returns: | ||
XApiTransformersRegistry class. | ||
""" | ||
return XApiTransformersRegistry | ||
|
||
|
||
def get_xapi_transformer(): | ||
"""Allow to get the XApiTransformer class from | ||
https://github.com/openedx/event-routing-backends/blob/master/event_routing_backends/processors/xapi/transformer.py#L27 | ||
Returns: | ||
XApiTransformer class. | ||
""" | ||
return XApiTransformer |
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,16 @@ | ||
"""Wrapper for event-routing-backends library. | ||
This contains all the required dependencies from event-routing-backends. | ||
Attributes: | ||
XApiTransformer: Wrapper for the XApiTransformer class. | ||
XApiTransformersRegistry: Wrapper for the XApiTransformersRegistry class. | ||
""" | ||
from importlib import import_module | ||
|
||
from django.conf import settings | ||
|
||
backend = import_module(settings.FILES_MANAGER_EVENT_ROUTING_BACKEND) | ||
|
||
XApiTransformer = backend.get_xapi_transformer() | ||
XApiTransformersRegistry = backend.get_xapi_transformer_registry() |
Empty file.
27 changes: 27 additions & 0 deletions
27
filesmanager/edxapp_wrapper/test_backends/event_routing_backends_p_v1.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,27 @@ | ||
"""Backend for event-routing-backends library. | ||
This is required since the library has explicit dependencies from openedx platform. | ||
https://github.com/openedx/event-routing-backends | ||
""" | ||
from unittest.mock import Mock | ||
|
||
|
||
def get_xapi_transformer_registry(): | ||
"""Test backend for the XApiTransformersRegistry class. | ||
Returns: | ||
Mock class. | ||
""" | ||
XApiTransformersRegistry = Mock() | ||
XApiTransformersRegistry.register.return_value = lambda x: x | ||
|
||
return XApiTransformersRegistry | ||
|
||
|
||
def get_xapi_transformer(): | ||
"""Test backend for the XApiTransformer class. | ||
Returns: | ||
Mock class. | ||
""" | ||
return Mock() |
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
Empty file.
Empty file.
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,13 @@ | ||
"""Constants for xAPI specifications.""" | ||
|
||
# xAPI verbs | ||
XAPI_VERB_DOWNLOADED = "http://id.tincanapi.com/verb/downloaded" | ||
|
||
# xAPI activities | ||
XAPI_ACTIVITY_FILE = "http://activitystrea.ms/schema/1.0/file" | ||
|
||
# Languages | ||
EN = "en" | ||
|
||
# Display names | ||
DOWNLOADED = "downloaded" |
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,4 @@ | ||
""" | ||
All xAPI transformers. | ||
""" | ||
from filesmanager.processors.xapi.event_transformers.filesmanager_events import FilesDownloadedTransformer |
37 changes: 37 additions & 0 deletions
37
filesmanager/processors/xapi/event_transformers/filesmanager_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,37 @@ | ||
""" | ||
Transformers for filesmanager events. | ||
Classes: | ||
FilesDownloadedTransformer: Transformer for the event edunext.xblock.filesmanager.files.downloaded. | ||
""" | ||
|
||
from tincan import Activity, ActivityDefinition, LanguageMap, Verb | ||
|
||
from filesmanager.edxapp_wrapper.event_routing_backends import XApiTransformer, XApiTransformersRegistry | ||
from filesmanager.processors.xapi import constants | ||
|
||
|
||
@XApiTransformersRegistry.register("edunext.xblock.filesmanager.files.downloaded") | ||
class FilesDownloadedTransformer(XApiTransformer): | ||
""" | ||
Transformers for event generated when a student download files from xblock. | ||
""" | ||
|
||
_verb = Verb( | ||
id=constants.XAPI_VERB_DOWNLOADED, | ||
display=LanguageMap({constants.EN: constants.DOWNLOADED}), | ||
) | ||
|
||
def get_object(self): | ||
""" | ||
Get object for xAPI transformed event related to files download from xblock. | ||
Returns: | ||
`Activity` | ||
""" | ||
return Activity( | ||
id=self.get_object_iri("xblock", self.get_data("data.xblock_id", True)), | ||
definition=ActivityDefinition( | ||
type=constants.XAPI_ACTIVITY_FILE, | ||
), | ||
) |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ XBlock | |
xblock-utils | ||
celery | ||
edx-opaque-keys | ||
tincan |
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
Oops, something went wrong.