Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/attendance calendars from bell schedules #88

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions models/build/edfi_3/bld_ef3__student_school_days.sql
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to handle nulls in end_date here

-- 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
54 changes: 18 additions & 36 deletions models/core_warehouse/fct_student_daily_attendance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ with fct_student_school_att as (
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') }}
Expand All @@ -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
Expand Down Expand Up @@ -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