Skip to content

Commit e4f9b3a

Browse files
author
gnguyen87
committed
update 2: distinct bt unexcused v other att events
1 parent ce4bb2e commit e4f9b3a

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

models/core_warehouse/fct_student_daily_attendance.sql

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ stu_enr_att_cal as (
105105
-- absenteeism metrics forward post-enrollment
106106
where attendance_calendar.calendar_date >= enr.entry_date
107107
),
108+
consecutive_unexcused_absence as (
109+
select
110+
*,
111+
row_number() over (partition by k_student, k_school, grouping order by calendar_date) as nth_consec_unexcused_absence
112+
from
113+
(select
114+
stu_enr_att_cal.k_student,
115+
stu_enr_att_cal.k_school,
116+
stu_enr_att_cal.k_calendar_date,
117+
stu_enr_att_cal.calendar_date,
118+
attendance_event_category,
119+
dense_rank() over ( partition by stu_enr_att_cal.k_student, stu_enr_att_cal.k_school order by calendar_date )
120+
- dense_rank() over ( partition by stu_enr_att_cal.k_student,stu_enr_att_cal.k_school, fct_student_school_att.attendance_event_category order by calendar_date)
121+
as grouping
122+
from stu_enr_att_cal
123+
left join fct_student_school_att
124+
on stu_enr_att_cal.k_student = fct_student_school_att.k_student
125+
and stu_enr_att_cal.k_school = fct_student_school_att.k_school
126+
and stu_enr_att_cal.k_calendar_date = fct_student_school_att.k_calendar_date
127+
)
128+
where attendance_event_category ilike '%unexcused absence%'
129+
),
108130
fill_positive_attendance as (
109131
select
110132
stu_enr_att_cal.k_student,
@@ -152,7 +174,8 @@ fill_positive_attendance as (
152174
else 1.0
153175
end, 0.0) as is_present,
154176
fct_student_school_att.event_duration,
155-
fct_student_school_att.school_attendance_duration
177+
fct_student_school_att.school_attendance_duration,
178+
nth_consec_unexcused_absence
156179
from stu_enr_att_cal
157180
left join fct_student_school_att
158181
on stu_enr_att_cal.k_student = fct_student_school_att.k_student
@@ -166,6 +189,10 @@ fill_positive_attendance as (
166189
and stu_enr_att_cal.calendar_date between
167190
bld_attendance_sessions.session_begin_date and
168191
bld_attendance_sessions.session_end_date
192+
left join consecutive_unexcused_absence
193+
on stu_enr_att_cal.k_student = consecutive_unexcused_absence.k_student
194+
and stu_enr_att_cal.k_student = consecutive_unexcused_absence.k_student
195+
and stu_enr_att_cal.k_calendar_date = consecutive_unexcused_absence.k_calendar_date
169196
),
170197
positive_attendance_deduped as (
171198
-- account for multiple overlapping enrollments at the same school by ensuring
@@ -185,18 +212,6 @@ positive_attendance_deduped as (
185212
)
186213
}}
187214
),
188-
consecutive_unexcused_absence as (
189-
select
190-
*,
191-
row_number() over (partition by k_student, k_school, grouping order by calendar_date) as nth_consec_unexcused_absence
192-
from
193-
(select *,
194-
dense_rank() over ( partition by k_student, k_school order by calendar_date )
195-
- dense_rank() over ( partition by k_student,k_school, attendance_event_category order by calendar_date)
196-
as grouping
197-
from positive_attendance_deduped
198-
)
199-
),
200215
cumulatives as (
201216
select
202217
positive_attendance_deduped.k_student,
@@ -229,10 +244,6 @@ cumulatives as (
229244
positive_attendance_deduped.school_attendance_duration,
230245
nth_consec_unexcused_absence
231246
from positive_attendance_deduped
232-
left join consecutive_unexcused_absence
233-
on positive_attendance_deduped.k_student = consecutive_unexcused_absence.k_student
234-
and positive_attendance_deduped.k_student = consecutive_unexcused_absence.k_student
235-
and positive_attendance_deduped.calendar_date = consecutive_unexcused_absence.calendar_date
236247
),
237248
metric_labels as (
238249
select

packages.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
packages:
2-
- package: edanalytics/edu_edfi_source
3-
version: [">=0.5.1", "<0.6.0"]
2+
# - package: edanalytics/edu_edfi_source
3+
# version: [">=0.5.1", "<0.6.0"]
4+
- local: ~/code/edu_edfi_source
5+

0 commit comments

Comments
 (0)