diff --git a/pipeline/transform/models/marts/dim_school.sql b/pipeline/transform/models/marts/dim_school.sql index fe7702d..f11f5c8 100644 --- a/pipeline/transform/models/marts/dim_school.sql +++ b/pipeline/transform/models/marts/dim_school.sql @@ -71,12 +71,12 @@ select s.nursery_provision, s.admissions_policy_code, - -- Latest Ofsted (populated after monthly Ofsted pipeline runs) + -- Latest Ofsted (populated after monthly Ofsted pipeline runs). The grade + -- still in force and the latest visit, from int_ofsted_latest — never a + -- grade carried past a newer inspection. {% if ofsted_relation is not none %} - -- Prefer the graded overall effectiveness; fall back to the grade parsed - -- from the latest ungraded (Section 8) outcome when no graded grade exists. - coalesce(o.overall_effectiveness, o.ungraded_grade) as ofsted_grade, - o.inspection_date as ofsted_date, + o.current_grade as ofsted_grade, + o.latest_visit_date as ofsted_date, o.framework as ofsted_framework {% else %} null::text as ofsted_grade, diff --git a/pipeline/transform/models/marts/dim_school.yml b/pipeline/transform/models/marts/dim_school.yml new file mode 100644 index 0000000..8b5d555 --- /dev/null +++ b/pipeline/transform/models/marts/dim_school.yml @@ -0,0 +1,35 @@ +version: 2 + +unit_tests: + - name: dim_school_ofsted_grade_is_the_one_still_in_force + description: > + Rabbsfarm (102408). Its 2025 inspection gave no overall grade, so the 2020 + "School remains Good" must not reach dim_school (which feeds Typesense's + rating), and ofsted_date is the latest visit (audit C1, M1). + model: dim_school + given: + - input: ref('stg_gias_establishments') + rows: + - {urn: 102408, school_name: 'Rabbsfarm Primary School', status_code: 1, school_type_code: 1, local_authority_code: 312, phase_code: 2} + - input: ref('int_ofsted_latest') + rows: + - {urn: 102408, inspection_date: '2025-06-17', overall_effectiveness: null, ungraded_grade: 2, framework: 'Schools - S5', latest_visit_date: '2025-06-17', current_grade: null} + expect: + rows: + - {urn: 102408, ofsted_grade: null, ofsted_date: '2025-06-17', ofsted_framework: 'Schools - S5'} + + - name: dim_school_ofsted_grade_keeps_its_own_date_out_of_ofsted_date + description: > + Washwood Heath (139888). Good from a 2020 graded inspection; latest visit + an ungraded one in May 2025. ofsted_date is the latest visit. + model: dim_school + given: + - input: ref('stg_gias_establishments') + rows: + - {urn: 139888, school_name: 'Washwood Heath Academy', status_code: 1, school_type_code: 28, local_authority_code: 330, phase_code: 7} + - input: ref('int_ofsted_latest') + rows: + - {urn: 139888, inspection_date: '2020-03-03', overall_effectiveness: 2, ungraded_grade: null, framework: 'Schools - S5', latest_visit_date: '2025-05-21', current_grade: 2} + expect: + rows: + - {urn: 139888, ofsted_grade: 2, ofsted_date: '2025-05-21'}