From 9f8f8f1dd577ca94b0c39f0ae12e613434232455 Mon Sep 17 00:00:00 2001 From: Kate Delaney <134744245+KatelynGit@users.noreply.github.com> Date: Wed, 22 Jan 2025 13:12:19 -0500 Subject: [PATCH] add engagement totals mart table marts__combined_total_course_engagements (#1444) * add engagement totals mart table marts__combined_total_course_engagements --- .../combined/_marts__combined__models.yml | 38 +++++++++++++ ...rts__combined_total_course_engagements.sql | 53 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/ol_dbt/models/marts/combined/marts__combined_total_course_engagements.sql diff --git a/src/ol_dbt/models/marts/combined/_marts__combined__models.yml b/src/ol_dbt/models/marts/combined/_marts__combined__models.yml index 609756915..a939a4c64 100644 --- a/src/ol_dbt/models/marts/combined/_marts__combined__models.yml +++ b/src/ol_dbt/models/marts/combined/_marts__combined__models.yml @@ -677,6 +677,44 @@ models: if courserun_start_on is in the past and blank courserun_end_on, or courserun_start_on is in the past and courserun_end_on is in the future. +- name: marts__combined_total_course_engagements + description: Total courserun engagement statistics from MITx Online, xPro, edX.org, + Residential MITx. + columns: + - name: platform + description: str, open edx platform, e.g., MITx Online, edX.org, xPro, Residential + MITx. + tests: + - not_null + - name: courserun_readable_id + description: str, the open edX course ID formatted as course-v1:{org}+{course + code}+{run_tag} for MITxOnline, xPro, Residential courses, {org}/{course}/{run_tag} + for edX.org courses. + tests: + - not_null + - name: total_courserun_problems + description: int, number of problems in a courserun + - name: total_courserun_videos + description: int, number of videos in a courserun + - name: total_courserun_discussions + description: int, number of discussions in a courserun + - name: courserun_title + description: str, title of the course run + - name: course_readable_id + description: str, Open edX ID formatted as course-v1:{org}+{course code} for MITx + Online, xPro or Residential courses, {org}/{course} for edX.org courses. + - name: courserun_is_current + description: boolean, indicating if the course run is currently running. True + if courserun_start_on is in the past and blank courserun_end_on, or courserun_start_on + is in the past and courserun_end_on is in the future. + - name: courserun_start_on + description: timestamp, datetime on when the course begins + - name: courserun_end_on + description: timestamp, datetime on when the course ends + tests: + - dbt_expectations.expect_compound_columns_to_be_unique: + column_list: ["platform", "courserun_readable_id"] + - name: marts__combined_course_engagements description: Learners daily course engagement statistics from MITx Online, xPro, edX.org, Residential MITx. diff --git a/src/ol_dbt/models/marts/combined/marts__combined_total_course_engagements.sql b/src/ol_dbt/models/marts/combined/marts__combined_total_course_engagements.sql new file mode 100644 index 000000000..cae6f5e9e --- /dev/null +++ b/src/ol_dbt/models/marts/combined/marts__combined_total_course_engagements.sql @@ -0,0 +1,53 @@ +with combined_engagements as ( + select + platform + , courserun_readable_id + , count( + distinct + case + when coursestructure_block_category = 'discussion' + then coursestructure_block_id + end + ) as total_courserun_discussions + , count( + distinct + case + when coursestructure_block_category = 'video' + then coursestructure_block_id + end + ) as total_courserun_videos + , count( + distinct + case + when coursestructure_block_category = 'problem' + then coursestructure_block_id + end + ) as total_courserun_problems + from {{ ref('int__combined__course_structure') }} + group by + platform + , courserun_readable_id +) + +, combined_runs as ( + select * + from {{ ref('int__combined__course_runs') }} + where courserun_readable_id is not null +) + +select + combined_runs.platform + , combined_runs.courserun_readable_id + , combined_engagements.total_courserun_problems + , combined_engagements.total_courserun_videos + , combined_engagements.total_courserun_discussions + , combined_runs.courserun_title + , combined_runs.course_readable_id + , combined_runs.courserun_is_current + , combined_runs.courserun_start_on + , combined_runs.courserun_end_on +from combined_runs +inner join combined_engagements + on + combined_runs.courserun_readable_id = combined_engagements.courserun_readable_id + and combined_runs.platform = combined_engagements.platform