-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds xApiTransforms for completion aggregator events (#205)
* chore: adds edx-event-routing-backends requirement @ 9.3.0 * chore: adds 'factory' as a test requirement because ERB tests needs it. * feat: adds xApiTransforms for completion aggregator events * feat: adds the completion_aggregator events to the event tracking whitelist in plugin settings * test: adds transformer and plugin_settings tests * test: make COMPLETION_AGGREGATOR_ASYNC_AGGREGATION consistent between test settings and plugin settings. * chore: bumps version to 4.2.0 * docs: adds note about xAPI to README --------- Co-authored-by: andrey-canon <[email protected]>
- Loading branch information
1 parent
27d448a
commit 2dfb6e2
Showing
28 changed files
with
909 additions
and
32 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -33,6 +33,7 @@ pip-log.txt | |
.tox | ||
coverage.xml | ||
htmlcov/ | ||
test_output/*.json | ||
|
||
# Translations | ||
*.mo | ||
|
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 |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
|
||
from __future__ import absolute_import, unicode_literals | ||
|
||
__version__ = '4.1.0' | ||
__version__ = '4.2.0' |
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
Transformers for completion aggregation. | ||
""" | ||
|
||
from event_routing_backends.processors.openedx_filters.decorators import openedx_filter | ||
from event_routing_backends.processors.xapi import constants | ||
from event_routing_backends.processors.xapi.registry import XApiTransformersRegistry | ||
from event_routing_backends.processors.xapi.transformer import XApiTransformer | ||
from tincan import Activity, ActivityDefinition, Extensions, LanguageMap, Result, Verb | ||
|
||
|
||
class BaseProgressTransformer(XApiTransformer): | ||
""" | ||
Base transformer for completion aggregator progress events. | ||
""" | ||
|
||
_verb = Verb( | ||
id=constants.XAPI_VERB_PROGRESSED, | ||
display=LanguageMap({constants.EN: constants.PROGRESSED}), | ||
) | ||
object_type = None | ||
additional_fields = ('result', ) | ||
|
||
@openedx_filter( | ||
filter_type="completion_aggregator.xapi.progress.get_object", | ||
) | ||
def get_object(self) -> Activity: | ||
""" | ||
Get object for xAPI transformed event. | ||
""" | ||
if not self.object_type: | ||
raise NotImplementedError() # pragma: no cover | ||
|
||
return Activity( | ||
id=self.get_object_iri("xblock", self.get_data("data.block_id")), | ||
definition=ActivityDefinition( | ||
type=self.object_type, | ||
), | ||
) | ||
|
||
def get_result(self) -> Result: | ||
""" | ||
Get result for xAPI transformed event. | ||
""" | ||
progress = self.get_data("data.percent") or 0 | ||
return Result( | ||
completion=progress == 1.0, | ||
extensions=Extensions({ | ||
constants.XAPI_ACTIVITY_PROGRESS: (progress * 100), | ||
}), | ||
) | ||
|
||
|
||
@XApiTransformersRegistry.register("openedx.completion_aggregator.progress.chapter") | ||
@XApiTransformersRegistry.register("openedx.completion_aggregator.progress.sequential") | ||
@XApiTransformersRegistry.register("openedx.completion_aggregator.progress.vertical") | ||
class ModuleProgressTransformer(BaseProgressTransformer): | ||
""" | ||
Transformer for event generated when a user makes progress in a section, subsection or unit. | ||
""" | ||
|
||
object_type = constants.XAPI_ACTIVITY_MODULE | ||
|
||
|
||
@XApiTransformersRegistry.register("openedx.completion_aggregator.progress.course") | ||
class CourseProgressTransformer(BaseProgressTransformer): | ||
""" | ||
Transformer for event generated when a user makes progress in a course. | ||
""" | ||
|
||
object_type = constants.XAPI_ACTIVITY_COURSE |
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
Oops, something went wrong.