-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change one org activity to be a thin view over another while we repla…
…ce it
- Loading branch information
Jon Betts
committed
Jul 4, 2023
1 parent
4016a94
commit 2bcce85
Showing
3 changed files
with
11 additions
and
64 deletions.
There are no files selected for viewing
60 changes: 11 additions & 49 deletions
60
...h/05_activity_counts/03_organizations/03_organization_annotation_types/01_create_view.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
); |
12 changes: 0 additions & 12 deletions
12
.../05_activity_counts/03_organizations/03_organization_annotation_types/02_initial_fill.sql
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters