-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add aggregate MVs for site wide stats
- Loading branch information
Showing
8 changed files
with
131 additions
and
143 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ | ||
config( | ||
materialized="materialized_view", | ||
schema=env_var("ASPECTS_XAPI_DATABASE", "xapi"), | ||
engine=get_engine("AggregatingMergeTree()"), | ||
order_by="(emission_hour)", | ||
partition_by="(toYYYYMM(emission_hour))", | ||
) | ||
}} | ||
|
||
select | ||
date_trunc('hour', emission_time) as emission_hour, | ||
uniqCombinedState(actor_id) as actors_cnt | ||
from {{ ref("xapi_events_all_parsed") }} | ||
group by emission_hour |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ | ||
config( | ||
materialized="materialized_view", | ||
schema=env_var("ASPECTS_XAPI_DATABASE", "xapi"), | ||
engine=get_engine("AggregatingMergeTree()"), | ||
order_by="(emission_hour)", | ||
partition_by="(toYYYYMM(emission_hour))", | ||
) | ||
}} | ||
|
||
select | ||
date_trunc('hour', emission_time) as emission_hour, | ||
uniqCombinedState(course_id) as courses_cnt | ||
from {{ ref("xapi_events_all_parsed") }} | ||
group by emission_hour |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{{ | ||
config( | ||
materialized="materialized_view", | ||
schema=env_var("ASPECTS_XAPI_DATABASE", "xapi"), | ||
engine=get_engine("SummingMergeTree()"), | ||
order_by="(emission_hour)", | ||
partition_by="(toYYYYMM(emission_hour))", | ||
) | ||
}} | ||
|
||
with | ||
enrollments as ( | ||
select | ||
emission_time, | ||
course_key, | ||
enrollment_mode, | ||
splitByString('/', verb_id)[-1] as enrollment_status | ||
from {{ ref("enrollment_events") }} | ||
) | ||
|
||
select | ||
date_trunc('hour', emission_time) as emission_hour, | ||
courses.course_name as course_name, | ||
enrollments.enrollment_mode as enrollment_mode, | ||
enrollments.enrollment_status as enrollment_status, | ||
count() as course_enrollment_mode_status_cnt | ||
from enrollments | ||
join {{ ref("course_names") }} courses on enrollments.course_key = courses.course_key | ||
group by emission_hour, course_name, enrollment_mode, enrollment_status |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ | ||
config( | ||
materialized="materialized_view", | ||
schema=env_var("ASPECTS_XAPI_DATABASE", "xapi"), | ||
engine=get_engine("AggregatingMergeTree()"), | ||
order_by="(emission_hour)", | ||
partition_by="(toYYYYMM(emission_hour))", | ||
) | ||
}} | ||
|
||
select | ||
date_trunc('hour', emission_time) as emission_hour, | ||
uniqCombinedState(event_id) as events_cnt | ||
from {{ ref("xapi_events_all_parsed") }} | ||
group by emission_hour |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: fact_instance_courses | ||
description: "A materialized view summarizing site-wide course activity" | ||
columns: | ||
- name: emission_hour | ||
data_type: datetime(64) | ||
description: "Time of summary, rounded to the nearest hour" | ||
- name: courses_cnt | ||
data_type: int | ||
description: "The number of xAPI courses active in the given hour" | ||
|
||
- name: fact_instance_events | ||
description: "A materialized view summarizing site-wide xAPI event activity" | ||
columns: | ||
- name: emission_hour | ||
data_type: datetime(64) | ||
description: "Time of summary, rounded to the nearest hour" | ||
- name: events_cnt | ||
data_type: int | ||
description: "The number of xAPI events that occurred in the given hour" | ||
|
||
- name: fact_instance_actors | ||
description: "A materialized view summarizing site-wide user activity" | ||
columns: | ||
- name: emission_hour | ||
data_type: datetime(64) | ||
description: "Time of summary, rounded to the nearest hour" | ||
- name: actors_cnt | ||
data_type: int | ||
description: "The number of xAPI actors active in the given hour" | ||
|
||
- name: fact_instance_enrollments | ||
description: "A materialized view for summarizing site-wide enrollment activity" | ||
columns: | ||
- name: emission_hour | ||
data_type: datetime(64) | ||
description: "Time of summary, rounded to the nearest hour" | ||
- name: course_name | ||
data_type: String | ||
description: "The name of the course" | ||
- name: enrollment_mode | ||
data_type: string | ||
description: "The name of the enrollment mode (ex: audit, honor)" | ||
- name: enrollment_status | ||
data_type: string | ||
description: "The type of enrollment event (ex: registered, unregistered)" | ||
tests: | ||
- accepted_values: | ||
values: [ "registered", "unregistered" ] | ||
- name: course_enrollment_mode_status_cnt | ||
data_type: int | ||
description: "The number of enrollment events for this mode that occurred in the given hour" |
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,17 +1 @@ | ||
select | ||
external_user_id, | ||
external_id_type, | ||
username, | ||
name, | ||
email, | ||
language, | ||
year_of_birth, | ||
gender, | ||
level_of_education, | ||
country, | ||
if( | ||
toInt32OrZero(year_of_birth) = 0, | ||
NULL, | ||
toYear(now()) - toInt32OrZero(year_of_birth) | ||
) as age | ||
from {{ ref("user_pii") }} user_pii | ||
select external_user_id, username, name, email from {{ ref("user_pii") }} user_pii |
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
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