From 3a21c16f15a87dc2f5358c96aa6ec8cc51c37f03 Mon Sep 17 00:00:00 2001 From: Cristhian Garcia Date: Wed, 22 May 2024 16:31:36 -0500 Subject: [PATCH] refactor: merge fact_problem_engagement --- models/problems/fact_problem_engagement.sql | 107 +++++------------- .../problems/fact_problem_engagement_v2.sql | 51 --------- 2 files changed, 27 insertions(+), 131 deletions(-) delete mode 100644 models/problems/fact_problem_engagement_v2.sql diff --git a/models/problems/fact_problem_engagement.sql b/models/problems/fact_problem_engagement.sql index e992da78..ca7c07be 100644 --- a/models/problems/fact_problem_engagement.sql +++ b/models/problems/fact_problem_engagement.sql @@ -1,104 +1,51 @@ with - subsection_counts as ( + subsection_engagement as ( select org, course_key, course_run, - section_with_name, - subsection_with_name, + content_level, actor_id, - item_count, - count(distinct problem_id) as problems_attempted, - case - when problems_attempted = 0 - then 'No problems attempted yet' - when problems_attempted = item_count - then 'All problems attempted' - else 'At least one problem attempted' - end as engagement_level, - username, - name, - email - from {{ ref("fact_problem_engagement_per_subsection") }} - group by - org, - course_key, - course_run, - section_with_name, - subsection_with_name, - actor_id, - item_count, - username, - name, - email + subsection_block_id as block_id, + section_subsection_problem_engagement + from {{ ref("subsection_problem_engagement") }} ), - section_counts as ( + section_engagement as ( select org, course_key, course_run, - section_with_name, + content_level, actor_id, - sum(item_count) as item_count, - sum(problems_attempted) as problems_attempted, - case - when problems_attempted = 0 - then 'No problems attempted yet' - when problems_attempted = item_count - then 'All problems attempted' - else 'At least one problem attempted' - end as engagement_level, - username, - name, - email - from subsection_counts - group by - org, - course_key, - course_run, - section_with_name, - actor_id, - username, - name, - email + section_block_id as block_id, + section_subsection_problem_engagement + from {{ ref("section_problem_engagement") }} ), problem_engagement as ( - select - org, - course_key, - course_run, - subsection_with_name as section_subsection_name, - 'subsection' as content_level, - actor_id as actor_id, - engagement_level as section_subsection_problem_engagement, - username, - name, - email - from subsection_counts + select * + from subsection_engagement union all - select - org, - course_key, - course_run, - section_with_name as section_subsection_name, - 'section' as content_level, - actor_id as actor_id, - engagement_level as section_subsection_problem_engagement, - username, - name, - email - from section_counts + select * + from section_engagement ) - select pe.org as org, pe.course_key as course_key, pe.course_run as course_run, - pe.section_subsection_name as section_subsection_name, + course_blocks.display_name_with_location as section_subsection_name, pe.content_level as content_level, pe.actor_id as actor_id, pe.section_subsection_problem_engagement as section_subsection_problem_engagement, - pe.username as username, - pe.name as name, - pe.email as email + users.username as username, + users.name as name, + users.email as email from problem_engagement pe +join + {{ ref("dim_course_blocks") }} course_blocks + on ( + pe.org = course_blocks.org + and pe.course_key = course_blocks.course_key + and pe.block_id = course_blocks.block_id + ) +left outer join + {{ ref("dim_user_pii") }} users on toUUID(pe.actor_id) = users.external_user_id diff --git a/models/problems/fact_problem_engagement_v2.sql b/models/problems/fact_problem_engagement_v2.sql deleted file mode 100644 index ca7c07be..00000000 --- a/models/problems/fact_problem_engagement_v2.sql +++ /dev/null @@ -1,51 +0,0 @@ -with - subsection_engagement as ( - select - org, - course_key, - course_run, - content_level, - actor_id, - subsection_block_id as block_id, - section_subsection_problem_engagement - from {{ ref("subsection_problem_engagement") }} - ), - section_engagement as ( - select - org, - course_key, - course_run, - content_level, - actor_id, - section_block_id as block_id, - section_subsection_problem_engagement - from {{ ref("section_problem_engagement") }} - ), - problem_engagement as ( - select * - from subsection_engagement - union all - select * - from section_engagement - ) -select - pe.org as org, - pe.course_key as course_key, - pe.course_run as course_run, - course_blocks.display_name_with_location as section_subsection_name, - pe.content_level as content_level, - pe.actor_id as actor_id, - pe.section_subsection_problem_engagement as section_subsection_problem_engagement, - users.username as username, - users.name as name, - users.email as email -from problem_engagement pe -join - {{ ref("dim_course_blocks") }} course_blocks - on ( - pe.org = course_blocks.org - and pe.course_key = course_blocks.course_key - and pe.block_id = course_blocks.block_id - ) -left outer join - {{ ref("dim_user_pii") }} users on toUUID(pe.actor_id) = users.external_user_id