-
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
* adds dependency on edx-event-routing-backends * adds transformers to xapi.completion and xapi.progress * adds the completion_aggregator events to the settings whitelist
- Loading branch information
1 parent
407a1d1
commit 2cd41b0
Showing
14 changed files
with
490 additions
and
24 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
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.
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,32 @@ | ||
""" | ||
xAPI Transformers for aggregation completion and progress events. | ||
""" | ||
|
||
from event_routing_backends.processors.xapi.transformer import XApiTransformer | ||
from tincan import Activity, ActivityDefinition | ||
|
||
|
||
class BaseAggregatorTransformer(XApiTransformer): | ||
""" | ||
Base transformer for all aggregator events. | ||
""" | ||
object_type = None | ||
|
||
def get_object(self): | ||
""" | ||
Get object for xAPI transformed event. | ||
Returns: | ||
`Activity` | ||
""" | ||
if not self.object_type: | ||
raise NotImplementedError() | ||
|
||
logger.critical("BaseAggregatorTransformer.get_object") | ||
|
||
return Activity( | ||
id=self.get_object_iri("xblock", self.get_data("data.block_id")), | ||
definition=ActivityDefinition( | ||
type=self.object_type, | ||
), | ||
) |
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,51 @@ | ||
""" | ||
xAPI Transformers for aggregation completion events. | ||
""" | ||
|
||
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 tincan import Extensions, LanguageMap, Verb | ||
|
||
from .base import BaseAggregatorTransformer | ||
|
||
|
||
class BaseCompletionTransformer(BaseAggregatorTransformer): | ||
""" | ||
Base transformer for aggregator completion events. | ||
""" | ||
_verb = Verb( | ||
id=constants.XAPI_VERB_COMPLETED, | ||
display=LanguageMap({constants.EN: constants.COMPLETED}), | ||
) | ||
object_type = None | ||
|
||
@openedx_filter( | ||
filter_type="completion_aggregator.xapi.base_completion.get_object", | ||
) | ||
def get_object(self): | ||
""" | ||
Get object for xAPI transformed event. | ||
Returns: | ||
`Activity` | ||
""" | ||
return super().get_object() | ||
|
||
|
||
@XApiTransformersRegistry.register("openedx.completion_aggregator.completion.chapter") | ||
@XApiTransformersRegistry.register("openedx.completion_aggregator.completion.sequential") | ||
@XApiTransformersRegistry.register("openedx.completion_aggregator.completion.vertical") | ||
class ModuleCompletionTransformer(BaseCompletionTransformer): | ||
""" | ||
Transformer for events generated when a user completes a section, subsection or unit. | ||
""" | ||
object_type = constants.XAPI_ACTIVITY_MODULE | ||
|
||
|
||
@XApiTransformersRegistry.register("openedx.completion_aggregator.completion.course") | ||
class CourseCompletionTransformer(BaseCompletionTransformer): | ||
""" | ||
Transformer for event generated when a user completes 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
xAPI Transformers for aggregation progress events. | ||
""" | ||
|
||
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 tincan import LanguageMap, Verb | ||
|
||
from .base import BaseAggregatorTransformer | ||
|
||
|
||
class BaseProgressTransformer(BaseAggregatorTransformer): | ||
""" | ||
Base transformer for 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.base_progress.get_object", | ||
) | ||
def get_object(self): | ||
""" | ||
Get object for xAPI transformed event. | ||
Returns: | ||
`Activity` | ||
""" | ||
return super().get_object() | ||
|
||
def get_result(self): | ||
""" | ||
Get result for xAPI transformed event. | ||
Returns: | ||
`Result` | ||
""" | ||
return Result( | ||
completion=self.get_data("data.percent") == 1.0, | ||
score={ | ||
"scaled": self.get_data("data.percent") or 0 | ||
} | ||
) | ||
|
||
|
||
@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.