-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add transformer to files downloaded event #35
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3c6bfdc
chore: include tincan package in base requirements
BryanttV aa3413f
feat: add backend for event-routing-backends package
BryanttV eef6554
feat: add transformer for files download event
BryanttV e338b4f
feat: update event
BryanttV 97a531d
test: add test backend
BryanttV b672668
chore: fix quality errors
BryanttV d4e8650
chore: address PR review
BryanttV 7c6c86f
chore: update bundle.js
BryanttV e8cfc02
fix: remove additional_fields and use xblock_id in activity id
BryanttV 169fd28
fix: change type of activity
BryanttV 9adc567
fix: send course_id in event endpoint
BryanttV 661be40
feat: add files downloaded in event data
BryanttV 3846521
chore: address PR review
BryanttV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.