Skip to content

Commit

Permalink
Change one org activity to be a thin view over another while we repla…
Browse files Browse the repository at this point in the history
…ce it
  • Loading branch information
Jon Betts committed Jul 4, 2023
1 parent 4016a94 commit 2bcce85
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,19 @@
DROP MATERIALIZED VIEW IF EXISTS report.organization_annotation_types CASCADE;
DROP VIEW IF EXISTS report.organization_annotation_types CASCADE;

-- A multifaceted look at organization annotation types over different
-- timescales

CREATE MATERIALIZED VIEW report.organization_annotation_types AS (
WITH
-- In order to get all the combinations of different types of data we
-- want in this table without writing an explosion of queries we first
-- create a "facets" CTE which represents all the different
-- combinations of values we want to be able to filter by.

-- We could probably do without this, but it makes it more like the
-- `organization_activity` query
weeks AS (
SELECT DISTINCT(created_week) AS timestamp_week
FROM report.group_annotation_counts
),

timescales AS (
SELECT column1 AS timescale FROM (
VALUES
('week'),
('month'),
('semester'),
('academic_year'),
('trailing_year'),
('all_time')
) AS data
),

facets AS (
SELECT
timestamp_week,
timescale::report.academic_timescale,
report.multi_truncate(timescale, timestamp_week) AS period
FROM weeks
CROSS JOIN timescales
)

CREATE VIEW report.organization_annotation_types AS (
SELECT
timescale,
period::DATE AS start_date,
(period + report.single_interval(timescale::text))::DATE AS end_date,
report.present_date(timescale::text, period) AS period,
group_map.organization_id,
group_annotation_counts.sub_type,
group_annotation_counts.shared,
SUM(group_annotation_counts.count) AS count
FROM facets
JOIN report.group_annotation_counts ON
group_annotation_counts.created_week = facets.timestamp_week
JOIN report.group_map ON
group_map.group_id = group_annotation_counts.group_id
MIN(start_date) AS start_date,
MAX(end_date) AS end_date,
period,
organization_id,
sub_type,
shared,
SUM(count) AS count
FROM report.organization_annotation_counts
GROUP BY period, timescale, sub_type, shared, organization_id
ORDER BY period, timescale, sub_type, shared, organization_id
) WITH NO DATA;
);

This file was deleted.

3 changes: 0 additions & 3 deletions lms/data_tasks/report/refresh/04_activity_counts_refresh.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,3 @@ ANALYSE report.organization_annotation_counts;

REFRESH MATERIALIZED VIEW CONCURRENTLY report.organization_activity;
ANALYSE report.organization_activity;

REFRESH MATERIALIZED VIEW CONCURRENTLY report.organization_annotation_types;
ANALYSE report.organization_annotation_types;

0 comments on commit 2bcce85

Please sign in to comment.