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 e2e93b2
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 11 deletions.
51 changes: 51 additions & 0 deletions dumped.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"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"
}
},
"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"
}
},
"timestamp": "2023-08-22T20:16:25.500832+00:00",
"context": {
"contextActivities": {
"parent": [
{
"id": "http://localhost:18000/course/course-v1:edX+DemoX+Demo_Course",
"objectType": "Activity",
"definition": {
"name": {
"en-US": "Demonstration Course"
},
"type": "http://adlnet.gov/expapi/activities/course"
}
}
]
},
"extensions": {
"https://w3id.org/xapi/openedx/extension/transformer-version": "[email protected]",
"https://w3id.org/xapi/openedx/extensions/session-id": "056aca2a1c6b76742b283e73d3424453"
}
}
}
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
Expand Up @@ -110,4 +110,11 @@ def test_event_transformer(self, event_filename, mocked_uuid):

actual_transformed_event = self.registry.get_transformer(original_event).transform()

if expected_event_file_path.endswith('edx.completion.block_completion.changed.json'):
with open("dumped.json", "w") as f:
f.write(json.dumps(actual_transformed_event.as_version(), indent=4))

with open("expected.json", "w") as f:
f.write(json.dumps(expected_event, indent=4))

self.compare_events(actual_transformed_event, expected_event)
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
51 changes: 51 additions & 0 deletions expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"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"
}
},
"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"
}
},
"timestamp": "2023-08-22T20:16:25.500832+00:00",
"context": {
"contextActivities": {
"parent": [
{
"id": "http://localhost:18000/course/course-v1:edX+DemoX+Demo_Course",
"objectType": "Activity",
"definition": {
"name": {
"en-US": "Demonstration Course"
},
"type": "http://adlnet.gov/expapi/activities/course"
}
}
]
},
"extensions": {
"https://w3id.org/xapi/openedx/extension/transformer-version": "[email protected]",
"https://w3id.org/xapi/openedx/extensions/session-id": "056aca2a1c6b76742b283e73d3424453"
}
}
}

0 comments on commit e2e93b2

Please sign in to comment.