Skip to content

Commit

Permalink
Views for Course Utilization Dashboard (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
coryamanda authored Dec 13, 2024
2 parents e9a6a0e + c9cf952 commit 6dc14b3
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* Created 12/09/24: Section actitity for each Script, Lesson and Level for student-facing curriculum for the three most recent school years (current and two prior) for Course Utilization dashboard in Tableau
*/

with
school_years as (
select *
from {{ref('int_school_years')}}
where sysdate-(365*1) < ended_at and sysdate > started_at -- three most recent school years (current and two prior), to change the number of years, change the multiplier
)


, student_activity as (
select
sa.section_id
, date_trunc('month',sa.activity_date) month_activity_date
, sa.content_area
, sa.course_name
, sa.unit_name
, sa.script_id
, sa.level_id
, sa.school_year
, replace(sa.topic_tags,',survey','') as topic_tags
, case when sa.topic_tags like '%survey%' then 1 else 0 end is_survey
, sa.us_intl
, sa.country
from {{ ref('dim_student_script_level_activity') }} sa
join school_years sy on sa.school_year = sy.school_year -- limit to selected school years
where
sa.user_type = 'student'
and sa.content_area not in ('hoc', 'other')
and sa.topic_tags is not null -- limiting to create a small extract to enable publishing
{{ dbt_utils.group_by(12) }} -- grouping instead of select distinct to deduplicate records with better performance
)

, course_structure as ((
select distinct
cs.script_id
, cs.script_name
, cs.version_year
, cs.topic_tags
, cs.stage_name as lesson_name
, cs.stage_number as lesson_number
, cs.stage_number || ' - ' || cs.stage_name as lesson_number_name
, cs.level_id
, cs.level_name
, cs.level_number
, cs.level_number || ' - ' || cs.level_name as level_number_name
from {{ ref('dim_course_structure')}} cs
where
cs.content_area not in ('hoc', 'other')
))


select
sa.*
, cs.script_name
, cs.version_year
, cs.lesson_name
, cs.lesson_number
, cs.lesson_number_name
, cs.level_name
, cs.level_number
, cs.level_number_name
from student_activity sa
join course_structure cs
on sa.script_id = cs.script_id
and sa.level_id = cs.level_id
{{ dbt_utils.group_by(20) }} -- grouping instead of select distinct to deduplicate records with better performance
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* Created 12/11/24: View with activity data for student-facing curriculum for the three most recent school years (current and two prior) for Course Utilization dashboard in Tableau
*/

with
school_years as (
select *
from {{ref('int_school_years')}}
where sysdate-(365*1) < ended_at and sysdate > started_at -- three most recent school years (current and two prior), to change the number of years, change the multiplier
)


, student_activity as (
select sa.*
from {{ ref('dim_student_script_level_activity') }} sa
join school_years sy on sa.school_year = sy.school_year -- limit to selected school years
where
user_type = 'student'
and content_area not in ('hoc')
and sa.topic_tags is not null -- limiting to create a small extract to enable publishing
)



select
sa.section_id
, sa.school_year
, sa.content_area
, sa.course_name
, sa.us_intl
, sa.country
, listagg(distinct sa.unit_name,', ') within group (order by unit_name) unit_combination
from student_activity sa
where
sa.topic_tags not like '%survey%'
{{ dbt_utils.group_by(6) }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* Created 12/09/24: View with activity data for student-facing curriculum for the three most recent school years (current and two prior) for Course Utilization dashboard in Tableau
*/

with

school_years as (
select *
from {{ref('int_school_years')}}
where sysdate-(365*1) < ended_at and sysdate > started_at -- three most recent school years (current and two prior), to change the number of years, change the multiplier
)


, student_activity as (
select sa.*
, sy.started_at as sy_start_at
from {{ ref('dim_student_script_level_activity') }} sa
join school_years sy on sa.school_year = sy.school_year -- limit to selected school years
where
user_type = 'student'
and content_area not in ('hoc')
and sa.topic_tags is not null -- limiting to create a small extract to enable publishing
)


, schools as
(
select school_id
, case
when coalesce(dss.is_title_i,0) = 1
or coalesce(dss.frl_eligible_percent,0) > 0.4
or coalesce(dss.urg_no_tr_numerator_percent,0) > 0.3
or coalesce(dss.is_rural,0) = 1
then 1 else 0 end school_is_uu
from {{ref('dim_schools')}} dss
)



select
sa.student_id
, case
when date_trunc('week',sa.activity_date) < sa.sy_start_at then sa.sy_start_at -- if the start of the week falls before the start of the school year, then the start of the school year
else date_trunc('week',sa.activity_date)
end week_activity_date
, sa.content_area
, sa.course_name
, sa.unit_name
, sa.section_id
, sa.section_teacher_id as teacher_id
, sa.school_id
, sa.school_year
, replace(sa.topic_tags,',survey','') as topic_tags
, case when sa.topic_tags like '%survey%' then 1 else 0 end is_survey
, sa.us_intl
, sa.country
, coalesce(ss.school_is_uu,0) school_is_uu
, sa.school_state

from student_activity sa
left join schools ss on sa.school_id = ss.school_id
{{ dbt_utils.group_by(15) }} -- grouping instead of select distinct to deduplicate records with better performance
23 changes: 22 additions & 1 deletion dbt/models/reporting_views/_reporting_views.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ models:
config:
tags: ['reporting']

- name: view_course_utilization_units
description: |
Activity by student and unit, used for the Course Utilization Tableau dashboard.
config:
tags: ['reporting', 'tableau']

- name: view_course_utilization_unit_combinations
description: |
Combination of units engaged with by each section, used for the Course Utilization Tableau dashboard, Unit Combinations viz.
config:
tags: ['reporting', 'tableau']

- name: view_course_utilization_by_script_level
description: |
Activity by section, script and level, used for the Course Utilization Tableau dashboard, Course Utilization by Script, Stage, Level viz.
config:
tags: ['reporting', 'tableau']

## Daily participating students
- name: daily_participating_students
description: |
Expand Down Expand Up @@ -80,4 +101,4 @@ models:
data_tests:
- not_null
config:
tags: ['released']
tags: ['released']
34 changes: 0 additions & 34 deletions dbt/models/reporting_views/test_view_student_activity.sql

This file was deleted.

0 comments on commit 6dc14b3

Please sign in to comment.