Skip to content

Commit

Permalink
feature/dim_student_script_level_activity (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-springer authored Sep 10, 2024
2 parents 202debd + 55af664 commit 1064164
Show file tree
Hide file tree
Showing 8 changed files with 512 additions and 318 deletions.
19 changes: 18 additions & 1 deletion dbt/dev/hoc/_hoc__models.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
version: 2

models:
- name: fct_hoc_activity
description: commonly tracked hoc metrics by hoc year and country
description: |
commonly tracked hoc metrics by month, school year, and country
columns:
- name: month
- name: school_year
- name: country
description: the country associated with the user's location
- name: total_new_teacher_accounts
description: the number of new teacher accounts created in the given month
- name: total_new_student_accounts
description: the number of new student accounts created in the given month
- name: total_event_registrations
description: the number of HoC events registered in the given month
- name: total_hoc_hits
description: the number of times an HoC activity was accessed

File renamed without changes.
146 changes: 146 additions & 0 deletions dbt/dev/students/dim_student_script_level_activity.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
with
course_structure as (
select *
from {{ ref('dim_course_structure') }}
where participant_audience = 'student'
),

user_levels as (
select
created_at

, case
when extract ('month' from created_at) in (7,8,9) then 'Q1'
when extract ('month' from created_at) in (10,11,12) then 'Q2'
when extract ('month' from created_at) in (1,2,3) then 'Q3'
when extract ('month' from created_at) in (4,5,6) then 'Q4'
end as school_year_quarter

, user_id
, script_id
, level_id

-- aggregates
, max(attempts) as total_attempts
, max(best_result) as best_result
, sum(time_spent) as time_spent_minutes

from {{ ref('stg_dashboard__user_levels') }}
{{ dbt_utils.group_by(5) }}
),

section_mapping as (
select *
from {{ ref('int_section_mapping') }}
),

school_years as (
select *
from {{ ref('int_school_years') }}
),

school_status as (
select *
from {{ ref('dim_school_status') }}
),

teacher_status as (
select *
from {{ ref('dim_teacher_status') }}
),

schools as (
select *
from {{ ref('dim_schools') }}
),

users as (
select *
from {{ ref('dim_users') }}
),

section_size as (
select
section_id
, count(distinct student_id) as section_size
from {{ ref('int_section_mapping') }}
group by section_id
),

final as (
select
ul.user_id as student_id
, ul.level_id as level_id
, ul.script_id as script_id
, date_trunc('day', ul.created_at) as activity_date
, ul.best_result
, ul.total_attempts
, ul.time_spent_minutes

-- time variables
--, date_trunc ('month', ul.created_at) as activity_month
, ul.school_year_quarter
, sy.school_year as activity_school_year

-- course, script, unit, lesson, and level characteristics
, cs.level_name as level_name
, cs.level_type as level_type
, cs.unit as unit_name
, cs.course_name
, cs.stage_name as lesson_name

-- section/teacher characteristics
, sm.section_id as section_id
, sm.teacher_id as section_teacher_id
, ssi.section_size as section_size
, ts.status as teacher_status

-- school characteristics
, ss.status as school_status
, sch.school_name as school_name
, sch.school_district_id as school_district_id
, sch.school_district_name as school_district_name
, sch.state as school_state
, sch.school_type as school_type
, sch.is_stage_el as school_is_stage_el
, sch.is_stage_mi as school_is_stage_mi
, sch.is_stage_hi as school_is_stage_hi
, sch.is_high_needs as school_is_high_needs
, sch.is_rural as school_is_rural

-- other
, u.us_intl
, u.country as activity_country
from user_levels as ul
join users as u
on ul.user_id = u.user_id

left join school_years as sy
on ul.created_at
between sy.started_at
and sy.ended_at

left join course_structure as cs
on ul.level_id = cs.level_id
and ul.script_id = cs.script_id

left join section_mapping as sm
on ul.user_id = sm.student_id
and sm.school_year = sy.school_year

left join section_size as ssi
on ssi.section_id = sm.section_id

left join teacher_status as ts
on sm.teacher_id = ts.teacher_id
and sy.school_year = ts.school_year

left join school_status as ss
on sm.school_id = ss.school_id
and sy.school_year = ss.school_year

left join schools as sch
on sm.school_id = sch.school_id )

select *
from final
32 changes: 16 additions & 16 deletions dbt/models/marts/hoc/_hoc__models.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
version: 2

models:
- name: fct_hoc_activity
description: |
commonly tracked hoc metrics by month, school year, and country
# - name: fct_hoc_activity
# description: |
# commonly tracked hoc metrics by month, school year, and country

columns:
- name: month
- name: school_year
- name: country
description: the country associated with the user's location
- name: total_new_teacher_accounts
description: the number of new teacher accounts created in the given month
- name: total_new_student_accounts
description: the number of new student accounts created in the given month
- name: total_event_registrations
description: the number of HoC events registered in the given month
- name: total_hoc_hits
description: the number of times an HoC activity was accessed
# columns:
# - name: month
# - name: school_year
# - name: country
# description: the country associated with the user's location
# - name: total_new_teacher_accounts
# description: the number of new teacher accounts created in the given month
# - name: total_new_student_accounts
# description: the number of new student accounts created in the given month
# - name: total_event_registrations
# description: the number of HoC events registered in the given month
# - name: total_hoc_hits
# description: the number of times an HoC activity was accessed

- name: dim_hoc_starts
description: |
Expand Down
96 changes: 0 additions & 96 deletions dbt/models/marts/hoc/fct_hoc_activity.sql

This file was deleted.

Loading

0 comments on commit 1064164

Please sign in to comment.