diff --git a/lms/data_tasks/report/create_from_scratch/05_activity_counts/03_organizations/02_organization_activity/01_create_view.sql b/lms/data_tasks/report/create_from_scratch/05_activity_counts/03_organizations/02_organization_activity/01_create_view.sql index c56da68ddd..03c560ad9e 100644 --- a/lms/data_tasks/report/create_from_scratch/05_activity_counts/03_organizations/02_organization_activity/01_create_view.sql +++ b/lms/data_tasks/report/create_from_scratch/05_activity_counts/03_organizations/02_organization_activity/01_create_view.sql @@ -51,43 +51,20 @@ CREATE MATERIALIZED VIEW report.organization_activity AS ( -- Then we join onto this facets table and use it to group our data in -- all of the different combos. - user_annotation_counts AS ( + annotation_counts AS ( + -- The organization annotation counts has it's own identical + -- concept of facets, so we don't have to join onto it SELECT - period, - timescale, - group_map.organization_id, - SUM(annotation_count) AS annotation_count - -- We don't have annotation counts by teacher, so this is user only - -- so we'll use "periods" instead of the full "facets" - FROM periods - JOIN report.group_activity ON - group_activity.created_week = periods.timestamp_week - JOIN report.group_map ON - group_activity.group_id = group_map.group_id - GROUP BY - period, timescale, group_map.organization_id - ), - - -- We calculate this differently from the group above because it's - -- faster to it from the groups for users, but for teachers it's not - -- an option. Doing users this way results in similar, but slightly - -- different numbers - teacher_annotation_counts AS ( - SELECT - period, + -- This is a little weird, but period ends up as `start_date` + -- the actual period that pops out is a string + start_date AS period, timescale, + role, organization_id, - SUM(annotation_count) AS annotation_count - -- We don't have annotation counts by teacher, so this is user only - -- so we'll use "periods" instead of the full "facets" - FROM periods - JOIN report.user_activity ON - user_activity.created_week = periods.timestamp_week - JOIN report.organization_roles ON - user_activity.user_id = organization_roles.user_id - AND organization_roles.role = 'teacher' + SUM(count) AS annotation_count + FROM report.organization_annotation_counts GROUP BY - period, timescale, organization_id + start_date, timescale, role, organization_id ), active AS ( @@ -163,16 +140,9 @@ CREATE MATERIALIZED VIEW report.organization_activity AS ( unioned_metrics AS ( SELECT - period, timescale, organization_id, 'user'::report.roles AS role, - annotation_count, 0 AS active, 0 AS billable, 0 AS launch_count - FROM user_annotation_counts - - UNION ALL - - SELECT - period, timescale, organization_id, 'teacher'::report.roles AS role, + period, timescale, organization_id, role, annotation_count, 0 AS active, 0 AS billable, 0 AS launch_count - FROM teacher_annotation_counts + FROM annotation_counts UNION ALL