Skip to content

Commit

Permalink
fix: use result to store completion status
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Aug 24, 2023
1 parent 9ae82a6 commit dea7fe4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"user_id": 4,
"course_id": "course-v1:edX+DemoX+Demo_Course",
"context_key": "course-v1:edX+DemoX+Demo_Course",
"block_key": "block-v1:edX+DemoX+Demo_Course+type@problem+block@7c54b16c8ed34f9f8772015178c7a175",
"block_id": "block-v1:edX+DemoX+Demo_Course+type@problem+block@7c54b16c8ed34f9f8772015178c7a175",
"block_type": "problem",
"completion": 1.0,
"is_new": false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
"""
Transformers for forum related events.
"""
from tincan import Activity, ActivityDefinition, Extensions, LanguageMap, Verb
from tincan import Activity, ActivityDefinition, Extensions, LanguageMap, Result, Verb

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


@XApiTransformersRegistry.register('edx.completion.block_completion.changed')
@XApiTransformersRegistry.register("edx.completion.block_completion.changed")
class CompletionCreatedTransformer(XApiTransformer):
"""
Transformers for event generated when an student completion is created or updated.
"""

verb = Verb(
id=constants.XAPI_VERB_PROGRESSED,
display=LanguageMap({constants.EN: constants.PROGRESSED}),
)

additional_fields = ('result', )

def get_object(self):
"""
Get object for xAPI transformed event related to a thread.
Returns:
`Activity`
"""
print(f'\n\n\n BLOCK ID: {self.get_object_iri("xblock", self.get_data("data.block_id"))}\n\n\n')
return Activity(
id=self.get_object_iri('xblock', self.get_data('data.block_key')),
id=self.get_object_iri("xblock", self.get_data("data.block_id")),
definition=ActivityDefinition(
type=constants.XAPI_ACTIVITY_RESOURCE,
extensions=Extensions({
constants.XAPI_ACTIVITY_PROGRESS: self.get_data('data.completion')*100
})
),
)

def get_result(self):
"""
Get result for xAPI transformed event related to a thread.
Returns:
`Result`
"""
return Result(
completion=self.get_data("data.completion") == 1.0,
extensions=Extensions(
{constants.XAPI_ACTIVITY_PROGRESS: self.get_data("data.completion")*100}
),
)
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
{
"id": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"result": {
"completion": true,
"extensions": { "https://w3id.org/xapi/cmi5/result/extensions/progress": 100.0 }
},
"version": "1.0.3",
"actor": {
"objectType": "Agent",
"account": { "name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb", "homePage": "http://localhost:18000" }
"account": {
"name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb",
"homePage": "http://localhost:18000"
}
},
"verb": { "id": "http://adlnet.gov/expapi/verbs/progressed", "display": { "en": "progressed" } },
"verb": {
"id": "http://adlnet.gov/expapi/verbs/progressed",
"display": { "en": "progressed" }
},
"object": {
"id": "http://localhost:18000/xblock/block-v1:edX+DemoX+Demo_Course+type@problem+block@7c54b16c8ed34f9f8772015178c7a175",
"objectType": "Activity",
"definition": {
"type": "http://id.tincanapi.com/activitytype/resource",
"extensions": { "https://w3id.org/xapi/cmi5/result/extensions/progress": 100.0 }
"type": "http://id.tincanapi.com/activitytype/resource"
}
},
"timestamp": "2023-08-22T20:16:25.500832+00:00",
Expand Down

0 comments on commit dea7fe4

Please sign in to comment.