From 53e4fa75575379bb8bbd732546872533f09b69f2 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 16 Feb 2024 16:15:08 -0500 Subject: [PATCH 1/6] fix: dinamically get the block-id version --- event_routing_backends/helpers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/event_routing_backends/helpers.py b/event_routing_backends/helpers.py index 788db60f..e737a3c6 100644 --- a/event_routing_backends/helpers.py +++ b/event_routing_backends/helpers.py @@ -242,7 +242,10 @@ def get_block_id_from_event_data(data, course_id): if data is not None and course_id is not None: data_array = data.split('_') course_id_array = course_id.split(':') - block_id = "block-v1:{}+type@problem+block@{}".format(course_id_array[1], data_array[1]) \ + block_version = "block-{0}".format(course_id_array[0].split("-")[-1]) + if "ccx" in course_id_array[0]: + block_version = "ccx-{block_version}".format(block_version=block_version) + block_id = "{}:{}+type@problem+block@{}".format(block_version, course_id_array[1], data_array[1]) \ if len(data_array) > 1 and len(course_id_array) > 1 else None else: block_id = None @@ -272,7 +275,7 @@ def get_problem_block_id(referrer, data, course_id): return block_id -def make_video_block_id(video_id, course_id, video_block_name='video', block_version='block-v1'): +def make_video_block_id(video_id, course_id, video_block_name='video'): """ Return formatted video block id for provided video and course. @@ -280,12 +283,14 @@ def make_video_block_id(video_id, course_id, video_block_name='video', block_ver video_id (str) : id for the video object course_id (str) : course key string video_block_name(str) : video block prefix to generate video id - block_version (str) : xBlock version Returns: str """ course_id_array = course_id.split(':') + block_version = "block-{0}".format(course_id_array[0].split("-")[-1]) + if "ccx" in course_id_array[0]: + block_version = "ccx-{block_version}".format(block_version=block_version) return '{block_version}:{course_id}+type@{video_block_name}+block@{video_id}'.format( block_version=block_version, course_id=course_id_array[1], From ff344de4b9145cb43121be272bd3ff23167ea71c Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Fri, 16 Feb 2024 17:11:08 -0500 Subject: [PATCH 2/6] test: add fixtures for ccx changes --- .../fixtures/current/play_video.ccx.json | 26 ++++++++++ .../current/problem_check(browser).ccx.json | 21 ++++++++ .../fixtures/expected/play_video.ccx.json | 48 +++++++++++++++++++ .../expected/problem_check(browser).ccx.json | 43 +++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 event_routing_backends/processors/tests/fixtures/current/play_video.ccx.json create mode 100644 event_routing_backends/processors/tests/fixtures/current/problem_check(browser).ccx.json create mode 100644 event_routing_backends/processors/xapi/tests/fixtures/expected/play_video.ccx.json create mode 100644 event_routing_backends/processors/xapi/tests/fixtures/expected/problem_check(browser).ccx.json diff --git a/event_routing_backends/processors/tests/fixtures/current/play_video.ccx.json b/event_routing_backends/processors/tests/fixtures/current/play_video.ccx.json new file mode 100644 index 00000000..cbe83e45 --- /dev/null +++ b/event_routing_backends/processors/tests/fixtures/current/play_video.ccx.json @@ -0,0 +1,26 @@ +{ + "context": { + "accept_language": "en-US,en;q=0.9", + "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", + "client_id": "667522224.1583394645", + "course_id": "ccx-v1:edX+DemoX+Demo_Course+ccx@1", + "event_source": "browser", + "host": "localhost:18000", + "ip": "172.18.0.1", + "org_id": "edX", + "page": "http://localhost:18000/courses/ccx-block-v1:edX+DemoX+Demo_Course+ccx@1/courseware/d8a6192ade314473a78242dfeedfbf5b/edx_introduction/?activate_block_id=block-v1%3AedX%2BDemoX%2BDemo_Course%2Btype%40sequential%2Bblock%40edx_introduction", + "path": "/event", + "referer": "http://localhost:18000/courses/ccx-block-v1:edX+DemoX+Demo_Course+ccx@1/courseware/d8a6192ade314473a78242dfeedfbf5b/edx_introduction/?activate_block_id=block-v1%3AedX%2BDemoX%2BDemo_Course%2Btype%40sequential%2Bblock%40edx_introduction", + "session": "993110e9c27848a545da74a74114158d", + "user_id": 3, + "username": "edx" + }, + "data": { + "code": "b7xgknqkQk8", + "currentTime": 0.03278805340576172, + "duration": 195, + "id": "0b9e39477cf34507a7a48f74be381fdd" + }, + "name": "play_video", + "timestamp": "2020-07-15T06:52:55.057099+00:00" +} diff --git a/event_routing_backends/processors/tests/fixtures/current/problem_check(browser).ccx.json b/event_routing_backends/processors/tests/fixtures/current/problem_check(browser).ccx.json new file mode 100644 index 00000000..890183b1 --- /dev/null +++ b/event_routing_backends/processors/tests/fixtures/current/problem_check(browser).ccx.json @@ -0,0 +1,21 @@ +{ + "context": { + "accept_language": "en-US,en;q=0.9", + "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36", + "client_id": "667522224.1583394645", + "course_id": "ccx-v1:edX+DemoX+Demo_Course+ccx@1", + "event_source": "browser", + "host": "localhost:18000", + "ip": "172.18.0.1", + "org_id": "edX", + "page": "http://localhost:18000/courses/ccx-block-v1:edX+DemoX+Demo_Course+ccx@1/courseware/8b66dcd2d6134eda9355089ece4f39f6/ef37eb3cf1724e38b7f88a9ce85a4842/?activate_block_id=block-v1%3AedX%2BDemoX%2BDemo_Course%2Btype%40sequential%2Bblock%40ef37eb3cf1724e38b7f88a9ce85a4842", + "path": "/event", + "referer": "http://localhost:18000/xblock/ccx-block-v1:edX+DemoX+Demo_Course+ccx@1+type@vertical+block@e3601c0abee6427d8c17e6d6f8fdddd1?show_title=0&show_bookmark_button=0&recheck_access=1&view=student_view", + "session": "6ad0a24d8303f49d14409a669d430b6f", + "user_id": 3, + "username": "edx" + }, + "data": "input_3fc5461f86764ad7bdbdf6cbdde61e66_2_1%5B%5D=choice_0&input_3fc5461f86764ad7bdbdf6cbdde61e66_2_1%5B%5D=choice_2", + "name": "problem_check", + "timestamp": "2020-07-14T14:39:26.580443+00:00" +} diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/play_video.ccx.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/play_video.ccx.json new file mode 100644 index 00000000..5b21504c --- /dev/null +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/play_video.ccx.json @@ -0,0 +1,48 @@ +{ + "id": "203e182c-6a2d-5458-9c61-a271297d459a", + "actor": { + "objectType": "Agent", + "account": {"homePage": "http://localhost:18000", "name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb"} + }, + "context": { + "contextActivities": { + "parent": [ + { + "id": "http://localhost:18000/course/ccx-v1:edX+DemoX+Demo_Course+ccx@1", + "objectType": "Activity", + "definition": { + "name": { + "en-US": "Demonstration Course" + }, + "type": "http://adlnet.gov/expapi/activities/course" + } + } + ] + }, + "extensions": { + "https://w3id.org/xapi/openedx/extension/transformer-version": "event-routing-backends@1.1.1", + "https://w3id.org/xapi/openedx/extensions/session-id": "993110e9c27848a545da74a74114158d", + "https://w3id.org/xapi/video/extensions/length": 195.0 + } + }, + "object": { + "definition": { + "type": "https://w3id.org/xapi/video/activity-type/video" + }, + "id": "http://localhost:18000/xblock/ccx-block-v1:edX+DemoX+Demo_Course+ccx@1+type@video+block@0b9e39477cf34507a7a48f74be381fdd", + "objectType": "Activity" + }, + "result": { + "extensions": { + "https://w3id.org/xapi/video/extensions/time": 0.033 + } + }, + "timestamp": "2020-07-15T06:52:55.057099+00:00", + "verb": { + "display": { + "en": "played" + }, + "id": "https://w3id.org/xapi/video/verbs/played" + }, + "version": "1.0.3" +} diff --git a/event_routing_backends/processors/xapi/tests/fixtures/expected/problem_check(browser).ccx.json b/event_routing_backends/processors/xapi/tests/fixtures/expected/problem_check(browser).ccx.json new file mode 100644 index 00000000..36031337 --- /dev/null +++ b/event_routing_backends/processors/xapi/tests/fixtures/expected/problem_check(browser).ccx.json @@ -0,0 +1,43 @@ +{ + "id": "2a1f0f7c-6636-52df-913b-59e2f197a58e", + "actor": { + "objectType": "Agent", + "account": {"homePage": "http://localhost:18000", "name": "32e08e30-f8ae-4ce2-94a8-c2bfe38a70cb"} + }, + "context": { + "contextActivities": { + "parent": [ + { + "id": "http://localhost:18000/course/ccx-v1:edX+DemoX+Demo_Course+ccx@1", + "objectType": "Activity", + "definition": { + "name": { + "en-US": "Demonstration Course" + }, + "type": "http://adlnet.gov/expapi/activities/course" + } + } + ] + }, + "extensions": { + "https://w3id.org/xapi/openedx/extension/transformer-version": "event-routing-backends@1.1.1", + "https://w3id.org/xapi/openedx/extensions/session-id": "6ad0a24d8303f49d14409a669d430b6f" + } + }, + "object": { + "definition": { + "interactionType": "other", + "type": "http://adlnet.gov/expapi/activities/cmi.interaction" + }, + "id": "http://localhost:18000/xblock/ccx-block-v1:edX+DemoX+Demo_Course+ccx@1+type@problem+block@3fc5461f86764ad7bdbdf6cbdde61e66", + "objectType": "Activity" + }, + "timestamp": "2020-07-14T14:39:26.580443+00:00", + "verb": { + "display": { + "en": "attempted" + }, + "id": "http://adlnet.gov/expapi/verbs/attempted" + }, + "version": "1.0.3" +} From fb626df99d9f13d865b00ed8398dfea5b99e99ca Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Wed, 21 Feb 2024 11:53:53 -0500 Subject: [PATCH 3/6] refactor: create method to get block_id version --- event_routing_backends/helpers.py | 47 ++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/event_routing_backends/helpers.py b/event_routing_backends/helpers.py index e737a3c6..088d4005 100644 --- a/event_routing_backends/helpers.py +++ b/event_routing_backends/helpers.py @@ -21,7 +21,7 @@ User = get_user_model() UTC_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%f' - +BLOCK_ID_FORMAT = '{block_version}:{course_id}+type@{block_type}+block@{block_id}' def get_uuid5(namespace_key, name): """ @@ -242,11 +242,16 @@ def get_block_id_from_event_data(data, course_id): if data is not None and course_id is not None: data_array = data.split('_') course_id_array = course_id.split(':') - block_version = "block-{0}".format(course_id_array[0].split("-")[-1]) - if "ccx" in course_id_array[0]: - block_version = "ccx-{block_version}".format(block_version=block_version) - block_id = "{}:{}+type@problem+block@{}".format(block_version, course_id_array[1], data_array[1]) \ - if len(data_array) > 1 and len(course_id_array) > 1 else None + block_version = get_block_version(course_id) + if len(data_array) > 1 and len(course_id_array) > 1: + block_id = BLOCK_ID_FORMAT.format( + block_version=block_version, + course_id=course_id_array[1], + block_type='problem', + block_id=data_array[1] + ) + else: + block_id = None else: block_id = None @@ -275,27 +280,24 @@ def get_problem_block_id(referrer, data, course_id): return block_id -def make_video_block_id(video_id, course_id, video_block_name='video'): +def make_video_block_id(video_id, course_id): """ Return formatted video block id for provided video and course. Arguments: video_id (str) : id for the video object course_id (str) : course key string - video_block_name(str) : video block prefix to generate video id Returns: str """ course_id_array = course_id.split(':') - block_version = "block-{0}".format(course_id_array[0].split("-")[-1]) - if "ccx" in course_id_array[0]: - block_version = "ccx-{block_version}".format(block_version=block_version) - return '{block_version}:{course_id}+type@{video_block_name}+block@{video_id}'.format( + block_version = get_block_version(course_id) + return BLOCK_ID_FORMAT.format( block_version=block_version, course_id=course_id_array[1], - video_block_name=video_block_name, - video_id=video_id + block_type='video', + block_id=video_id ) @@ -321,3 +323,20 @@ def get_business_critical_events(): 'edx.course.enrollment.deactivated', 'edx.course.grade.passed.first_time' ]) + +def get_block_version(course_id): + """ + Return versioned block id. + + Arguments: + course_id (str): course id + block_id (str): block id + + Returns: + str + """ + course_id_array = course_id.split(':') + block_version = "block-{0}".format(course_id_array[0].split("-")[-1]) + if "ccx" in course_id_array[0]: + block_version = "ccx-{block_version}".format(block_version=block_version) + return block_version From 94815362019bfb60531b26c05cd12449ed76d8cb Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Wed, 21 Feb 2024 12:08:59 -0500 Subject: [PATCH 4/6] chore: quality fixes --- event_routing_backends/helpers.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/event_routing_backends/helpers.py b/event_routing_backends/helpers.py index 088d4005..c0ed52b5 100644 --- a/event_routing_backends/helpers.py +++ b/event_routing_backends/helpers.py @@ -23,6 +23,7 @@ UTC_DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%f' BLOCK_ID_FORMAT = '{block_version}:{course_id}+type@{block_type}+block@{block_id}' + def get_uuid5(namespace_key, name): """ Create a UUID5 string based on custom namesapce and name. @@ -324,6 +325,7 @@ def get_business_critical_events(): 'edx.course.grade.passed.first_time' ]) + def get_block_version(course_id): """ Return versioned block id. From a591e61b4d4f32ef26c42fa0eb965dd677e7b0d8 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 22 Feb 2024 14:18:00 -0500 Subject: [PATCH 5/6] chore: add pragma no cover --- event_routing_backends/helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/event_routing_backends/helpers.py b/event_routing_backends/helpers.py index c0ed52b5..4cbda2e4 100644 --- a/event_routing_backends/helpers.py +++ b/event_routing_backends/helpers.py @@ -252,7 +252,7 @@ def get_block_id_from_event_data(data, course_id): block_id=data_array[1] ) else: - block_id = None + block_id = None # pragma: no cover else: block_id = None From 49eed4ce9ef6613468fe3ecbb10513591c5b5e42 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Thu, 22 Feb 2024 14:18:12 -0500 Subject: [PATCH 6/6] chore: bump version to 8.1.1 --- CHANGELOG.rst | 4 ++++ event_routing_backends/__init__.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d9ae9415..81c1d3f3 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,10 @@ Change Log Unreleased ~~~~~~~~~~ +[8.1.1] + +* Dinamically get the xblock version from the event. + [8.1.0] ~~~~~~~ diff --git a/event_routing_backends/__init__.py b/event_routing_backends/__init__.py index 786b8535..c0f405ca 100644 --- a/event_routing_backends/__init__.py +++ b/event_routing_backends/__init__.py @@ -2,4 +2,4 @@ Various backends for receiving edX LMS events.. """ -__version__ = '8.1.0' +__version__ = '8.1.1'