From 1414fed3c2184c0ee74fe2ef68fde7cbd7d311bd Mon Sep 17 00:00:00 2001 From: sleblanc23 Date: Mon, 20 Nov 2023 15:39:54 -0600 Subject: [PATCH 1/2] initial commit for student school days build model --- .../edfi_3/bld_ef3__student_school_days.sql | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 models/build/edfi_3/bld_ef3__student_school_days.sql diff --git a/models/build/edfi_3/bld_ef3__student_school_days.sql b/models/build/edfi_3/bld_ef3__student_school_days.sql new file mode 100644 index 00000000..fa6bb37b --- /dev/null +++ b/models/build/edfi_3/bld_ef3__student_school_days.sql @@ -0,0 +1,85 @@ +with student_school_enr as ( + select * from {{ ref('fct_student_school_association') }} +), +student_section_enr as ( + select * from {{ ref('fct_student_section_association') }} +), +course_section as ( + select * from {{ ref('dim_course_section') }} +), +section_class_periods as ( + select * from {{ ref('stg_ef3__sections__class_periods') }} +), +class_period as ( + select * from {{ ref('dim_class_period') }} +), +bell_class_period as ( + select * from {{ ref('stg_ef3__bell_schedules__class_periods') }} +), +bell as ( + select * from {{ ref('stg_ef3__bell_schedules') }} +), +bell_dates as ( + select * from {{ ref('stg_ef3__bell_schedules__dates') }} +), +school_calendar as ( + select * from {{ ref('dim_school_calendar') }} +), +calendar_date as ( + select * from {{ ref('dim_calendar_date') }} +), +-- Find all class dates for a student based on their bell schedules +student_bell_schedule_dates as ( + select distinct + student_school_enr.k_student, + student_school_enr.k_student_xyear, + student_school_enr.k_school, + student_school_enr.k_school_calendar, + student_school_enr.entry_date, + student_school_enr.exit_withdraw_date, + bell_dates.calendar_date + from student_school_enr + inner join student_section_enr + on student_school_enr.k_student = student_section_enr.k_student + and student_school_enr.k_school = student_section_enr.k_school + inner join course_section + on student_section_enr.k_course_section = course_section.k_course_section + inner join section_class_periods + on student_section_enr.k_course_section = section_class_periods.k_course_section + inner join class_period + on section_class_periods.k_class_period = class_period.k_class_period + inner join bell_class_period + on class_period.k_class_period = bell_class_period.k_class_period + inner join bell + on bell_class_period.k_bell_schedule = bell.k_bell_schedule + inner join bell_dates + on bell.k_bell_schedule = bell_dates.k_bell_schedule + -- limit to the duration of the section enrollment + where bell_dates.calendar_date between student_section_enr.begin_date and student_section_enr.end_date + -- limit to the duration of the school enrollment + and bell_dates.calendar_date >= student_school_enr.entry_date + and (bell_dates.calendar_date <= student_school_enr.exit_withdraw_date + or student_school_enr.exit_withdraw_date is null) +), +-- Remove any non-instructional days +student_class_dates as ( + select + student_bell_schedule_dates.k_student, + student_bell_schedule_dates.k_student_xyear, + student_bell_schedule_dates.k_school, + calendar_date.k_calendar_date, + school_calendar.tenant_code, + school_calendar.school_year, + student_bell_schedule_dates.entry_date, + student_bell_schedule_dates.exit_withdraw_date, + calendar_date.calendar_date + from student_bell_schedule_dates + inner join school_calendar + on student_bell_schedule_dates.k_school_calendar = school_calendar.k_school_calendar + inner join calendar_date + on school_calendar.k_school_calendar = calendar_date.k_school_calendar + and student_bell_schedule_dates.calendar_date = calendar_date.calendar_date + where calendar_date.is_school_day +) +select * +from student_class_dates \ No newline at end of file From 856493a88cdfbcbae8b0a24236c25a1bdc5bd0e5 Mon Sep 17 00:00:00 2001 From: sleblanc23 Date: Mon, 20 Nov 2023 15:40:09 -0600 Subject: [PATCH 2/2] modify to use school day build model --- .../fct_student_daily_attendance.sql | 56 +++++++------------ 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/models/core_warehouse/fct_student_daily_attendance.sql b/models/core_warehouse/fct_student_daily_attendance.sql index 132d9a40..f5a94a71 100644 --- a/models/core_warehouse/fct_student_daily_attendance.sql +++ b/models/core_warehouse/fct_student_daily_attendance.sql @@ -10,13 +10,13 @@ }} with fct_student_school_att as ( - select * from {{ ref('fct_student_school_attendance_event') }} + select * from {{ ref(var("edu:attendance:daily_attendance_source", 'fct_student_school_attendance_event')) }} ), dim_calendar_date as ( select * from {{ ref('dim_calendar_date') }} ), -fct_student_school_assoc as ( - select * from {{ ref('fct_student_school_association') }} +bld_student_calendar as( + select * from {{ ref(var("edu:attendance:student_school_days_source", 'bld_ef3__student_school_days')) }} ), metric_absentee_categories as ( select * from {{ ref('absentee_categories') }} @@ -32,43 +32,25 @@ school_max_submitted as ( from fct_student_school_att join dim_calendar_date on fct_student_school_att.k_calendar_date = dim_calendar_date.k_calendar_date - group by 1 -), -attendance_calendar as ( - -- a dataset of all possible days on which school attendance could be recorded - select - dim_calendar_date.k_school, - dim_calendar_date.k_school_calendar, - dim_calendar_date.k_calendar_date, - dim_calendar_date.school_year, - dim_calendar_date.calendar_date - from dim_calendar_date - join school_max_submitted - on dim_calendar_date.k_school = school_max_submitted.k_school - -- only include instructional days in the attendance calendar - where dim_calendar_date.is_school_day -- don't include dates in the future, as of run-time - and dim_calendar_date.calendar_date <= current_date() - -- don't include dates beyond the max submitted attendance event by school - and dim_calendar_date.calendar_date <= school_max_submitted.max_date_by_school + where dim_calendar_date.calendar_date <= current_date() + group by 1 ), stu_enr_att_cal as ( - -- create an attendance calendar by student, conditional on enrollment + -- limit the student calendar to the date of the max submitted attendance event by school select - enr.k_student, - enr.k_student_xyear, - enr.k_school, - enr.tenant_code, - enr.entry_date, - attendance_calendar.k_calendar_date, - attendance_calendar.calendar_date, - enr.exit_withdraw_date - from fct_student_school_assoc as enr - join attendance_calendar - on enr.k_school_calendar = attendance_calendar.k_school_calendar - -- keep days from enrollment to current-date/end of year to assist with rolling - -- absenteeism metrics forward post-enrollment - where attendance_calendar.calendar_date >= enr.entry_date + student_calendar.k_student, + student_calendar.k_student_xyear, + student_calendar.k_school, + student_calendar.tenant_code, + student_calendar.k_calendar_date, + student_calendar.calendar_date, + student_calendar.entry_date, + student_calendar.exit_withdraw_date + from bld_student_calendar as student_calendar + join school_max_submitted + on student_calendar.k_school = school_max_submitted.k_school + where student_calendar.calendar_date <= school_max_submitted.max_date_by_school ), fill_positive_attendance as ( select @@ -188,4 +170,4 @@ metric_labels as ( and cumulative_attendance_rate <= metric_absentee_categories.threshold_upper ) select * from metric_labels -order by tenant_code, k_school, k_student, cumulative_days_enrolled +order by tenant_code, k_school, k_student, cumulative_days_enrolled \ No newline at end of file