Skip to content

Commit

Permalink
Use the annotation counts to simplify the org activity calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Betts committed Jul 4, 2023
1 parent 2bcce85 commit a5cd43f
Showing 1 changed file with 12 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a5cd43f

Please sign in to comment.