Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3728a63275 | ||
|
|
480ac4b9a9 | ||
|
|
93f17211b1 | ||
|
|
dfa4928641 | ||
|
|
e6babe21f5 | ||
|
|
358705bf39 | ||
|
|
3be902e98f | ||
|
|
12c52244ee | ||
|
|
b6e48c4930 | ||
|
|
9f4f2507cc | ||
|
|
e1373fb6df | ||
|
|
94bfac9caf | ||
|
|
65a2619e1d | ||
|
|
ccfa44389e | ||
|
|
423b27140c | ||
|
|
1c62e8247d | ||
|
|
da5d63593f | ||
|
|
ef4a2ccccb | ||
|
|
392ec29fdb | ||
|
|
03e44cf154 | ||
|
|
41d3f3b971 | ||
|
|
c013265cb4 | ||
|
|
ad9d3b67f7 | ||
|
|
ca47d08186 | ||
|
|
62a6bfaf0c | ||
|
|
e344298440 |
No files matched your search
+22
-7
@@ -634,6 +634,18 @@ def _with_whole_school_pupils(rows: pd.DataFrame, source: pd.DataFrame) -> pd.Da
|
|||||||
return rows.assign(total_pupils=whole)
|
return rows.assign(total_pupils=whole)
|
||||||
|
|
||||||
|
|
||||||
|
def _with_type_group(rows: pd.DataFrame) -> pd.DataFrame:
|
||||||
|
"""Name each row's search-filter type group, or None for a type in no group.
|
||||||
|
|
||||||
|
The school page and the search rows print it ("State school") in place of
|
||||||
|
the GIAS establishment type, and an independent school gets a Fee-paying
|
||||||
|
flag from it.
|
||||||
|
"""
|
||||||
|
if "school_type" not in rows.columns:
|
||||||
|
return rows
|
||||||
|
return rows.assign(type_group=rows["school_type"].map(type_group_for))
|
||||||
|
|
||||||
|
|
||||||
# Input validation helpers
|
# Input validation helpers
|
||||||
def _names_in_group(names: pd.Series, in_group) -> set:
|
def _names_in_group(names: pd.Series, in_group) -> set:
|
||||||
"""The distinct names in a column that a group predicate accepts.
|
"""The distinct names in a column that a group predicate accepts.
|
||||||
@@ -965,7 +977,7 @@ async def get_schools(
|
|||||||
total = len(schools_df)
|
total = len(schools_df)
|
||||||
start_idx = (page - 1) * page_size
|
start_idx = (page - 1) * page_size
|
||||||
end_idx = start_idx + page_size
|
end_idx = start_idx + page_size
|
||||||
schools_df = schools_df.iloc[start_idx:end_idx]
|
schools_df = _with_type_group(schools_df.iloc[start_idx:end_idx])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"schools": clean_for_json(schools_df),
|
"schools": clean_for_json(schools_df),
|
||||||
@@ -1029,11 +1041,14 @@ async def get_school_details(request: Request, urn: int):
|
|||||||
"school_name": latest.get("school_name", ""),
|
"school_name": latest.get("school_name", ""),
|
||||||
"local_authority": latest.get("local_authority", ""),
|
"local_authority": latest.get("local_authority", ""),
|
||||||
"school_type": latest.get("school_type", ""),
|
"school_type": latest.get("school_type", ""),
|
||||||
|
"type_group": type_group_for(latest.get("school_type")),
|
||||||
"address": latest.get("address", ""),
|
"address": latest.get("address", ""),
|
||||||
"religious_denomination": latest.get("religious_denomination", ""),
|
"religious_denomination": latest.get("religious_denomination", ""),
|
||||||
"age_range": latest.get("age_range", ""),
|
"age_range": latest.get("age_range", ""),
|
||||||
"has_sixth_form": latest.get("has_sixth_form"),
|
"has_sixth_form": latest.get("has_sixth_form"),
|
||||||
"nursery_provision": latest.get("nursery_provision"),
|
"nursery_provision": latest.get("nursery_provision"),
|
||||||
|
# The header's Selective flag reads it (lib/schoolFacts).
|
||||||
|
"admissions_policy": latest.get("admissions_policy"),
|
||||||
"status": latest.get("status"),
|
"status": latest.get("status"),
|
||||||
"latitude": latest.get("latitude"),
|
"latitude": latest.get("latitude"),
|
||||||
"longitude": latest.get("longitude"),
|
"longitude": latest.get("longitude"),
|
||||||
@@ -1522,13 +1537,12 @@ async def get_place(request: Request, kind: str, slug: str,
|
|||||||
# warning. Ordered de-duplication keeps the column order and the warning
|
# warning. Ordered de-duplication keeps the column order and the warning
|
||||||
# cannot come back.
|
# cannot come back.
|
||||||
#
|
#
|
||||||
# nursery_provision and parliamentary_constituency are not in
|
# parliamentary_constituency is not in SCHOOL_COLUMNS and the place table
|
||||||
# SCHOOL_COLUMNS and the place table shows both. The `in rows.columns`
|
# shows it. The `in rows.columns` guard is what keeps a mart the pipeline
|
||||||
# guard is what keeps a mart the pipeline has not rebuilt working: those
|
# has not rebuilt working: it and nursery_provision are the optional GIAS
|
||||||
# two are the optional GIAS columns data_loader degrades to NULL.
|
# columns data_loader degrades to NULL.
|
||||||
cols = [c for c in dict.fromkeys(
|
cols = [c for c in dict.fromkeys(
|
||||||
SCHOOL_COLUMNS + ["latitude", "longitude", "phase",
|
SCHOOL_COLUMNS + ["latitude", "longitude", "phase",
|
||||||
"nursery_provision",
|
|
||||||
"parliamentary_constituency",
|
"parliamentary_constituency",
|
||||||
"rwm_expected_pct", "attainment_8_score",
|
"rwm_expected_pct", "attainment_8_score",
|
||||||
"total_pupils"])
|
"total_pupils"])
|
||||||
@@ -1558,7 +1572,8 @@ async def get_place(request: Request, kind: str, slug: str,
|
|||||||
# variants that exist rather than 404s.
|
# variants that exist rather than 404s.
|
||||||
"phases": [ph for ph in ("primary", "secondary")
|
"phases": [ph for ph in ("primary", "secondary")
|
||||||
if place.publishes_phase(ph)]},
|
if place.publishes_phase(ph)]},
|
||||||
"schools": clean_for_json(_with_whole_school_pupils(rows[cols], rows)),
|
"schools": clean_for_json(
|
||||||
|
_with_type_group(_with_whole_school_pupils(rows[cols], rows))),
|
||||||
"averages": averages,
|
"averages": averages,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -569,6 +569,7 @@ SCHOOL_COLUMNS = [
|
|||||||
"religious_denomination",
|
"religious_denomination",
|
||||||
"age_range",
|
"age_range",
|
||||||
"has_sixth_form",
|
"has_sixth_form",
|
||||||
|
"nursery_provision",
|
||||||
"status",
|
"status",
|
||||||
"gender",
|
"gender",
|
||||||
"admissions_policy",
|
"admissions_policy",
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
"""The school page's header flags (nextjs-app/lib/schoolFacts.ts) read seven
|
||||||
|
school_info fields, so the detail payload must carry every one.
|
||||||
|
|
||||||
|
It lacked admissions_policy, so no school page could flag Selective while its
|
||||||
|
search row did: Tiffin and The Grammar School at Leeds showed the tag in
|
||||||
|
search and nothing on their own pages.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
# The fields schoolFlags() picks from School (FlagFields in lib/schoolFacts.ts).
|
||||||
|
FLAG_FIELDS = (
|
||||||
|
"type_group", "admissions_policy", "gender", "religious_denomination",
|
||||||
|
"nursery_provision", "has_sixth_form", "phase",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _school_df() -> pd.DataFrame:
|
||||||
|
return pd.DataFrame([{
|
||||||
|
"urn": 136910, "school_name": "Tiffin School", "phase": "Secondary",
|
||||||
|
"school_type": "Academy converter", "admissions_policy": "Selective",
|
||||||
|
"gender": "Boys", "religious_denomination": "Christian",
|
||||||
|
"nursery_provision": "Not applicable", "has_sixth_form": True,
|
||||||
|
"age_range": "11-18", "local_authority": "Kingston upon Thames",
|
||||||
|
"address": "Queen Elizabeth Road, Kingston upon Thames, KT2 6RL",
|
||||||
|
"postcode": "KT2 6RL", "latitude": 51.41, "longitude": -0.30,
|
||||||
|
"year": 202425, "attainment_8_score": 75.0, "total_pupils": 200,
|
||||||
|
"gias_total_pupils": 1478, "ofsted_grade": np.nan,
|
||||||
|
}])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def client(monkeypatch):
|
||||||
|
from backend import app as app_module
|
||||||
|
|
||||||
|
monkeypatch.setattr(app_module, "load_school_data", _school_df)
|
||||||
|
monkeypatch.setattr(app_module, "load_latest_school_data", _school_df)
|
||||||
|
monkeypatch.setattr(app_module, "get_supplementary_data", lambda db, urn: {})
|
||||||
|
monkeypatch.setattr(app_module, "_place_registry", None)
|
||||||
|
return TestClient(app_module.app, raise_server_exceptions=False)
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_school_page_carries_every_field_its_flags_read(client):
|
||||||
|
resp = client.get("/api/schools/136910")
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
info = resp.json()["school_info"]
|
||||||
|
assert [f for f in FLAG_FIELDS if f not in info] == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_school_page_says_a_selective_school_is_selective(client):
|
||||||
|
info = client.get("/api/schools/136910").json()["school_info"]
|
||||||
|
assert info["admissions_policy"] == "Selective"
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
"""Payloads name each school's type group.
|
||||||
|
|
||||||
|
The school page and the search rows say "State school" or "Independent
|
||||||
|
school" in the search filter's own terms, not GIAS's 34 establishment types,
|
||||||
|
and an independent school gets a Fee-paying flag. A type in no group keeps a
|
||||||
|
null group, and the page prints the register's own name for it. Search rows
|
||||||
|
also carry nursery_provision, for their "Nursery class" flag.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
|
||||||
|
def _schools_df() -> pd.DataFrame:
|
||||||
|
base = {
|
||||||
|
"local_authority": "Essex", "phase": "Primary", "year": 202425,
|
||||||
|
"ofsted_grade": 2.0, "ofsted_date": None, "attainment_8_score": np.nan,
|
||||||
|
"town": "Brentwood", "postcode": "CM13 1AA", "status": "Open",
|
||||||
|
"address": "1 Test Street", "latitude": 51.6, "longitude": 0.3,
|
||||||
|
"rwm_expected_pct": 60.0, "nursery_provision": "No Nursery Classes",
|
||||||
|
}
|
||||||
|
rows = [
|
||||||
|
{**base, "urn": 100001, "school_name": "Alpha Academy",
|
||||||
|
"school_type": "Academy converter", "nursery_provision": "Has Nursery Classes"},
|
||||||
|
{**base, "urn": 100002, "school_name": "Beta Prep",
|
||||||
|
"school_type": "Other independent school"},
|
||||||
|
{**base, "urn": 100003, "school_name": "Gamma Unit",
|
||||||
|
"school_type": "Secure units"},
|
||||||
|
]
|
||||||
|
# Enough schools in one town for it to have a place page.
|
||||||
|
rows += [
|
||||||
|
{**base, "urn": 100010 + i, "school_name": f"Delta Primary {i}",
|
||||||
|
"school_type": "Community school"}
|
||||||
|
for i in range(3)
|
||||||
|
]
|
||||||
|
return pd.DataFrame(rows)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def client(monkeypatch):
|
||||||
|
from backend import app as app_module
|
||||||
|
|
||||||
|
monkeypatch.setattr(app_module, "load_latest_school_data", _schools_df)
|
||||||
|
monkeypatch.setattr(app_module, "load_school_data", _schools_df)
|
||||||
|
monkeypatch.setattr(app_module, "get_supplementary_data", lambda db, urn: {})
|
||||||
|
monkeypatch.setattr(app_module, "_place_registry", None)
|
||||||
|
return TestClient(app_module.app, raise_server_exceptions=False)
|
||||||
|
|
||||||
|
|
||||||
|
def _by_urn(schools: list[dict]) -> dict[int, dict]:
|
||||||
|
return {s["urn"]: s for s in schools}
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_list_names_each_type_group(client):
|
||||||
|
resp = client.get("/api/schools?page_size=50")
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
schools = _by_urn(resp.json()["schools"])
|
||||||
|
assert schools[100001]["type_group"] == "state"
|
||||||
|
assert schools[100002]["type_group"] == "independent"
|
||||||
|
assert schools[100003]["type_group"] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_list_carries_nursery_provision(client):
|
||||||
|
schools = _by_urn(client.get("/api/schools?page_size=50").json()["schools"])
|
||||||
|
assert schools[100001]["nursery_provision"] == "Has Nursery Classes"
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_school_page_names_its_type_group(client):
|
||||||
|
resp = client.get("/api/schools/100002")
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
assert resp.json()["school_info"]["type_group"] == "independent"
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_place_page_names_each_type_group(client):
|
||||||
|
resp = client.get("/api/places/town/brentwood")
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
schools = _by_urn(resp.json()["schools"])
|
||||||
|
assert schools[100001]["type_group"] == "state"
|
||||||
|
assert schools[100003]["type_group"] is None
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,257 @@
|
|||||||
|
# Ofsted Current Status — Design
|
||||||
|
|
||||||
|
**Date:** 2026-10-05
|
||||||
|
**Status:** approved design, not yet implemented
|
||||||
|
**Scope:** `pipeline/transform` Ofsted models, `backend/data_loader.py`, list and
|
||||||
|
detail API Ofsted fields, search and map badges, school-page Ofsted section,
|
||||||
|
compare Ofsted rows, Typesense rating, sitemap
|
||||||
|
**Fixes:** audit findings C1, M1 and (as a side effect) M2 and part of H3,
|
||||||
|
from the 3 Oct 2026 accuracy audit
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
|
||||||
|
Never show an Ofsted grade under a date it was not awarded or confirmed on, and
|
||||||
|
always date "Inspected" by the school's latest visit.
|
||||||
|
|
||||||
|
## The problem
|
||||||
|
|
||||||
|
Ofsted's management information gives each school at most three inspections:
|
||||||
|
the latest graded inspection (date G, an overall grade or "Not judged", area
|
||||||
|
grades), the latest ungraded inspection (date U, an outcome sentence) and the
|
||||||
|
latest report card (date RC).
|
||||||
|
|
||||||
|
The site derives a grade and a date from these with two independent rules:
|
||||||
|
|
||||||
|
- grade = the graded inspection's overall grade, or else the grade parsed from
|
||||||
|
the ungraded outcome ("School remains Good" → 2);
|
||||||
|
- date = G, or else U.
|
||||||
|
|
||||||
|
The two rules can pick different inspections. Every inspection from
|
||||||
|
September 2024 to November 2025 was graded with "Not judged" overall, so the
|
||||||
|
grade falls back to an older ungraded visit while the date stays the new one.
|
||||||
|
|
||||||
|
- **C1.** Rabbsfarm Primary School (102408) shows "Good · 2025". Ofsted's
|
||||||
|
17 June 2025 inspection gave no overall grade and rated quality of education,
|
||||||
|
behaviour and leadership Requires Improvement. The "Good" comes from an
|
||||||
|
ungraded visit on 6 February 2020. Site-wide, 932 badges pair a
|
||||||
|
carried-forward grade with a newer inspection's year, and 147 of them say Good
|
||||||
|
or Outstanding while that inspection rated an area Requires Improvement or
|
||||||
|
Inadequate. Acre Wood Academy (151783) reads "Good · 2024" though the
|
||||||
|
October 2024 inspection rated all four areas Inadequate.
|
||||||
|
- **M1.** When a newer ungraded visit exists, the page shows the older graded
|
||||||
|
date. Washwood Heath Academy (139888) reads "Inspected 3 Mar 2020 · 4+ years
|
||||||
|
ago"; Ofsted visited on 21 May 2025. 667 schools.
|
||||||
|
|
||||||
|
Ofsted's own provider page for Rabbsfarm leads with the 2025 area judgements and
|
||||||
|
"From September 2024, Ofsted no longer makes an overall effectiveness
|
||||||
|
judgement". It shows no overall grade.
|
||||||
|
|
||||||
|
The rule is also implemented four times: `dim_school.ofsted_grade` (feeds
|
||||||
|
Typesense), the list SQL in `data_loader.py`, `_ofsted_block`, and two separate
|
||||||
|
"latest row" picks over `marts.fact_ofsted_inspection` by `inspection_date`,
|
||||||
|
which tie arbitrarily on duplicate monthly rows.
|
||||||
|
|
||||||
|
## Non-goals
|
||||||
|
|
||||||
|
- Predecessor inspections (audit M10): a grade Ofsted attributes to a previous
|
||||||
|
URN stays unlabelled.
|
||||||
|
- Post-16 and ISI-inspected schools (H4) and the "Not yet inspected" label.
|
||||||
|
- The compare page's broken Ofsted link (M4).
|
||||||
|
- Report-card display, which is unchanged.
|
||||||
|
|
||||||
|
## The rule
|
||||||
|
|
||||||
|
Computed once per URN in `int_ofsted_latest`.
|
||||||
|
|
||||||
|
**Latest visit:** the newest of RC, G and U.
|
||||||
|
|
||||||
|
- `latest_visit_date`
|
||||||
|
- `latest_visit_kind`: `report_card`, `graded` or `ungraded`
|
||||||
|
- `latest_visit_outcome`: the ungraded outcome text when the kind is `ungraded`,
|
||||||
|
otherwise null
|
||||||
|
|
||||||
|
**Current grade:** the overall grade still in force, if any.
|
||||||
|
|
||||||
|
| Situation | `current_grade` | `current_grade_date` | `current_grade_basis` |
|
||||||
|
|---|---|---|---|
|
||||||
|
| A report card exists | null | null | null |
|
||||||
|
| Latest is graded, overall 1–4 | that grade | G | `graded` |
|
||||||
|
| Latest is graded, "Not judged" | null | null | null |
|
||||||
|
| Latest is ungraded, outcome "School remains X…" (any qualifier) | X | U | `confirmed` |
|
||||||
|
| Latest is ungraded, any other outcome ("Standards maintained", "Improved significantly", "Some aspects not as strong") | the graded inspection's overall grade if it is 1–4, else null | G when a grade is kept | `graded` when a grade is kept |
|
||||||
|
| No inspection | null | null | null |
|
||||||
|
|
||||||
|
A report card replaced overall grades, so no legacy grade stays in force beside
|
||||||
|
one. The latest visit is read from the dates, not assumed: report cards began in
|
||||||
|
November 2025, after the last legacy graded and ungraded inspections, and in
|
||||||
|
Ofsted's 31 Aug 2026 data no school has a legacy visit newer than its report
|
||||||
|
card, but the rule does not depend on that. Ties between G, U and RC on the same
|
||||||
|
date resolve in the order report card, graded, ungraded.
|
||||||
|
|
||||||
|
Invariants: `current_grade` is null or 1–4; `current_grade_date <=
|
||||||
|
latest_visit_date`; `current_grade_basis` is null exactly when `current_grade`
|
||||||
|
is null.
|
||||||
|
|
||||||
|
### Expected results (Ofsted MI as at 31 Aug 2026)
|
||||||
|
|
||||||
|
| URN | School | Ofsted data | Latest visit | Current grade |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| 102408 | Rabbsfarm Primary School | G 17 Jun 2025 Not judged; U 6 Feb 2020 remains Good | graded, 17 Jun 2025 | none |
|
||||||
|
| 151783 | Acre Wood Academy | G 1 Oct 2024 Not judged; U 14 Mar 2023 remains Good (Concerns) | graded, 1 Oct 2024 | none |
|
||||||
|
| 139888 | Washwood Heath Academy | G 3 Mar 2020 Good; U 21 May 2025 Standards maintained | ungraded, 21 May 2025, "Standards maintained" | Good, 3 Mar 2020, graded |
|
||||||
|
| 104762 | Robins Lane Community Primary | G 7 Jan 2020 Good; U 18 Jul 2024 School remains Good | ungraded, 18 Jul 2024 | Good, 18 Jul 2024, confirmed |
|
||||||
|
| 100094 | Royal Free Hospital Children's School | G 9 Oct 2019 Outstanding; U 5 Feb 2025 Some aspects not as strong | ungraded, 5 Feb 2025 | Outstanding, 9 Oct 2019, graded |
|
||||||
|
| 136454 | Oakgrove School | U 13 Nov 2024 Standards maintained only | ungraded, 13 Nov 2024 | none |
|
||||||
|
| 137086 | Bishop Stopford School | G 1 Apr 2025 Not judged | graded, 1 Apr 2025 | none |
|
||||||
|
| 110048 | The Willink School | U 5 Oct 2023 remains Good; RC 6 May 2026 | report card, 6 May 2026 | none (report card shown) |
|
||||||
|
| 149612 | St Michael's Catholic School | RC 10 Feb 2026 only | report card, 10 Feb 2026 | none (report card shown) |
|
||||||
|
|
||||||
|
## What each page shows
|
||||||
|
|
||||||
|
**Search and map badge** (`buildOfstedListBadge`), first match wins:
|
||||||
|
|
||||||
|
1. Report card: "Report Card · *RC year*" (unchanged)
|
||||||
|
2. Current grade: "*Grade* · *year of `current_grade_date`*"
|
||||||
|
3. Latest visit: "Inspected · *year of `latest_visit_date`*"
|
||||||
|
4. "Not yet inspected" (unchanged)
|
||||||
|
|
||||||
|
**School page** (`OfstedSection`, both phases):
|
||||||
|
|
||||||
|
- Title date: "Inspected *latest visit date*".
|
||||||
|
- Headline: the report card; or the current grade with a source line
|
||||||
|
("Graded inspection, 6 July 2016" or "Confirmed at an ungraded inspection,
|
||||||
|
14 March 2023"); or "No overall grade" with "Ofsted stopped giving overall
|
||||||
|
grades in September 2024".
|
||||||
|
- "Latest visit" line when the latest visit is not the grade's source, e.g.
|
||||||
|
"Ungraded inspection, 13 Nov 2024: Standards maintained".
|
||||||
|
- The area grid shows the graded inspection's judgements through
|
||||||
|
`ofstedLegacyAreas()`, dated by that inspection when it is not the latest
|
||||||
|
visit. The primary and secondary no-grade branches merge into one; the
|
||||||
|
secondary branch's four hard-coded areas (audit M2) go with it.
|
||||||
|
|
||||||
|
**Compare:** `ofstedDisplay` returns `report_card`, `graded`, `confirmed`,
|
||||||
|
`no_overall_grade` or `none`. The "Latest Ofsted inspection", "Result" and
|
||||||
|
"Inspected" rows use the same fields as the school page.
|
||||||
|
|
||||||
|
## Delivery
|
||||||
|
|
||||||
|
Two pull requests. The mart columns exist before anything reads them, so
|
||||||
|
neither needs compatibility code.
|
||||||
|
|
||||||
|
### PR 1: pipeline (additive)
|
||||||
|
|
||||||
|
- `stg_ofsted_inspections`: keep `graded_inspection_date`,
|
||||||
|
`ungraded_inspection_date` and `rc_inspection_date` as separate typed
|
||||||
|
columns, with the report-card date's existing guard. Keep `inspection_date`
|
||||||
|
(graded, else ungraded) for the current backend. Keep a row when any of the
|
||||||
|
three dates is present, so report-card-only schools are no longer dropped
|
||||||
|
(part of H3: 123 schools).
|
||||||
|
- `int_ofsted_latest`: pick one row per URN by `latest_visit_date` descending,
|
||||||
|
then `rc_inspection_date`, `ungraded_inspection_date` and
|
||||||
|
`graded_inspection_date` descending (nulls last). A duplicate monthly row that
|
||||||
|
carries a newer report card therefore always wins. Add the five status
|
||||||
|
columns.
|
||||||
|
- New mart `marts.fact_ofsted_latest`: one row per URN from `int_ofsted_latest`
|
||||||
|
with every column the pages need (status, area grades, report-card grades,
|
||||||
|
ungraded outcome, report URL). It does not join `dim_school`, so only the
|
||||||
|
monthly Ofsted DAG builds it.
|
||||||
|
- `dim_school` is not changed in PR 1: the daily DAG does not rebuild
|
||||||
|
`int_ofsted_latest`, and reading a column that the monthly DAG has not yet
|
||||||
|
built would fail the daily run.
|
||||||
|
- Visible effect: report-card-only schools gain their report card, because the
|
||||||
|
backend's existing reads of `fact_ofsted_inspection` now see their rows.
|
||||||
|
Nothing else changes.
|
||||||
|
|
||||||
|
### PR 2: backend and UI (after the Ofsted DAG has run on PR 1)
|
||||||
|
|
||||||
|
- `data_loader.py`: the list query and the batch query read
|
||||||
|
`marts.fact_ofsted_latest` instead of picking the latest row of
|
||||||
|
`fact_ofsted_inspection`. `_ofsted_block` reads the status columns and loses
|
||||||
|
its fallback to `ungraded_grade`.
|
||||||
|
- List rows: `ofsted_grade` becomes `current_grade`; `ofsted_date` becomes
|
||||||
|
`latest_visit_date`; new `ofsted_grade_date`. `ofsted_rc_date` stays.
|
||||||
|
- `ofsted` block: `overall_effectiveness` and `inspection_date` are the graded
|
||||||
|
inspection's own result and date (they label the area grid); new
|
||||||
|
`current_grade` `{grade, date, basis}` (or null) and `latest_visit`
|
||||||
|
`{date, kind, outcome}`; `grade_source` is removed. Report-card fields are
|
||||||
|
unchanged.
|
||||||
|
- `dim_school.ofsted_grade` becomes `current_grade` (Typesense's rating follows
|
||||||
|
at the next sync); `ofsted_date` becomes `latest_visit_date`.
|
||||||
|
- Sitemap: `lastmod` from `latest_visit_date`; `_PUBLISHABLE_FIELDS` also counts
|
||||||
|
a latest visit, so schools that lose a carried grade keep their sitemap entry.
|
||||||
|
- Front end: `lib/types.ts`, `buildOfstedListBadge`, `OfstedSection`,
|
||||||
|
`PrimarySchoolSections`, `SecondarySchoolSections`, `compareLogic.ofstedDisplay`,
|
||||||
|
`CompareAtAGlance`, `CompareOfsted`. Place-page counts need no change.
|
||||||
|
- Delete `buildOfstedHeroChip` and `buildSchoolSummary` in their own commit:
|
||||||
|
nothing renders them and they encode the old rule.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
**PR 1**
|
||||||
|
|
||||||
|
- dbt unit tests on `int_ofsted_latest`, one per table row above plus
|
||||||
|
"report-card only" and "duplicate rows, newer report card wins".
|
||||||
|
- Schema tests on `fact_ofsted_latest`: unique, not-null `urn`; accepted values
|
||||||
|
for `latest_visit_kind` and `current_grade_basis`; `current_grade` null or
|
||||||
|
1–4; `current_grade_date <= latest_visit_date`.
|
||||||
|
- Run locally against a throwaway Postgres from `pgserver` (no Docker here). If
|
||||||
|
that fails, they still run in the Ofsted DAG's `dbt build`, which fails on any
|
||||||
|
broken case.
|
||||||
|
- `pipeline/tests/test_dag_selectors.py` (PR #181) keeps passing.
|
||||||
|
|
||||||
|
**PR 2**
|
||||||
|
|
||||||
|
- pytest: contract test for the list and `ofsted` fields (style of
|
||||||
|
`test_school_page_flag_fields.py`); `_ofsted_block` from a
|
||||||
|
`fact_ofsted_latest` row; sitemap publishability.
|
||||||
|
- Jest: a badge case per table row; `OfstedSection` for graded, confirmed, no
|
||||||
|
grade, the latest-visit line and a sixth-form area; `ofstedDisplay` kinds.
|
||||||
|
Rewrite tests that assert `carried_forward`.
|
||||||
|
- E2E (same PR): Rabbsfarm's search row says "Inspected · 2025" and its page
|
||||||
|
says "No overall grade" with quality of education Requires Improvement; a
|
||||||
|
confirmed school says "Confirmed at an ungraded inspection". The existing
|
||||||
|
report-card journey stays.
|
||||||
|
|
||||||
|
## Rollout and verification
|
||||||
|
|
||||||
|
1. Merge PR 1. On staging, run `school_data_monthly_ofsted`, then:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- one row per school
|
||||||
|
select count(*) = count(distinct urn) from marts.fact_ofsted_latest;
|
||||||
|
-- the examples above
|
||||||
|
select urn, latest_visit_date, latest_visit_kind, latest_visit_outcome,
|
||||||
|
current_grade, current_grade_date, current_grade_basis
|
||||||
|
from marts.fact_ofsted_latest
|
||||||
|
where urn in (102408, 151783, 139888, 104762, 100094, 136454, 137086, 110048, 149612);
|
||||||
|
-- C1: a grade in force although the latest inspection gave none (expect 0)
|
||||||
|
select count(*) from marts.fact_ofsted_latest
|
||||||
|
where current_grade is not null and latest_visit_kind = 'graded'
|
||||||
|
and overall_effectiveness is null;
|
||||||
|
-- invariant (expect 0)
|
||||||
|
select count(*) from marts.fact_ofsted_latest where current_grade_date > latest_visit_date;
|
||||||
|
```
|
||||||
|
|
||||||
|
Check through the API that St Michael's Catholic School (149612) shows its
|
||||||
|
report card.
|
||||||
|
2. Promote PR 1 to production; run the Ofsted DAG there; repeat the checks.
|
||||||
|
3. Merge PR 2. Let the daily DAG run (or trigger it) so `dim_school` and
|
||||||
|
Typesense pick up the change; run the E2E journeys; re-run the audit's C1,
|
||||||
|
M1 and M2 checks against staging: expect 0.
|
||||||
|
4. Promote PR 2; repeat the audit checks on production.
|
||||||
|
|
||||||
|
## Expected visible change
|
||||||
|
|
||||||
|
About 932 schools change from a grade badge dated by a no-grade inspection
|
||||||
|
("Good · 2025") to "Inspected · 2025". Counts of Good and Outstanding schools
|
||||||
|
on place pages fall by the same schools, and Typesense's rating changes for
|
||||||
|
them. Dates beside a grade can move earlier (to the inspection that awarded
|
||||||
|
it); "Inspected" dates move later (to the latest visit).
|
||||||
|
|
||||||
|
## Risks
|
||||||
|
|
||||||
|
- Ofsted changes its MI columns most months. Unknown grade text parses to null
|
||||||
|
(`safe_numeric`), which degrades to "Inspected · year", never to a wrong grade.
|
||||||
|
- PR 2 depends on the Ofsted DAG having run on the target environment after PR
|
||||||
|
1. If PR 2 is promoted first, the backend reads a missing table: promote in
|
||||||
|
order.
|
||||||
@@ -510,9 +510,10 @@ test('school detail page shows GIAS identity/contact details and drops the unwir
|
|||||||
if (info.telephone) {
|
if (info.telephone) {
|
||||||
await expect(page.locator('a[href^="tel:"]').first()).toBeVisible();
|
await expect(page.locator('a[href^="tel:"]').first()).toBeVisible();
|
||||||
}
|
}
|
||||||
if (info.parliamentary_constituency) {
|
// Constituency and county left the header in the facts-and-flags redesign:
|
||||||
await expect(page.getByText('Constituency:').first()).toBeVisible();
|
// neither helps a parent decide. The place pages keep both.
|
||||||
}
|
await expect(page.getByText('Constituency:')).toHaveCount(0);
|
||||||
|
await expect(page.getByText('County:')).toHaveCount(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('header details collapse behind a "Show all details" toggle on mobile', async ({ page }) => {
|
test('header details collapse behind a "Show all details" toggle on mobile', async ({ page }) => {
|
||||||
@@ -3384,6 +3385,65 @@ test('a girls\' secondary header names it properly and shows Nursery only when i
|
|||||||
const header = page.locator('header', { has: page.getByRole('heading', { level: 1 }) });
|
const header = page.locator('header', { has: page.getByRole('heading', { level: 1 }) });
|
||||||
await expect(header.getByText("Girls' school", { exact: true })).toBeVisible({ timeout: 15_000 });
|
await expect(header.getByText("Girls' school", { exact: true })).toBeVisible({ timeout: 15_000 });
|
||||||
await expect(header.getByText(/'s school/)).toHaveCount(0);
|
await expect(header.getByText(/'s school/)).toHaveCount(0);
|
||||||
await expect(header.getByText('Nursery', { exact: true }))
|
await expect(header.getByText('Nursery class', { exact: true }))
|
||||||
.toHaveCount(detail.school_info.nursery_provision === 'Has Nursery Classes' ? 1 : 0);
|
.toHaveCount(detail.school_info.nursery_provision === 'Has Nursery Classes' ? 1 : 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The header states facts in fixed slots and flags only what applies: a
|
||||||
|
* selective school is flagged Selective, and its type reads in the search
|
||||||
|
* filter's words, not as a GIAS establishment type. The search row carries
|
||||||
|
* the same flag. Data-invariant: the school comes from the API.
|
||||||
|
*/
|
||||||
|
const TYPE_GROUP_LABELS: Record<string, string> = {
|
||||||
|
state: 'State school', independent: 'Independent school', special: 'Special school (SEND)',
|
||||||
|
post16: 'Sixth form or college', alternative: 'Alternative provision',
|
||||||
|
};
|
||||||
|
|
||||||
|
test('a selective school is flagged Selective, on its page and in search', async ({ page }) => {
|
||||||
|
const res = await page.request.get(
|
||||||
|
'/api/schools?search=school&phase=secondary&admissions_policy=selective&page_size=1');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const [school] = (await res.json()).schools ?? [];
|
||||||
|
test.skip(!school, 'no selective secondary in this environment');
|
||||||
|
expect(school.admissions_policy, 'the admissions filter was ignored').toBe('Selective');
|
||||||
|
expect(school, 'the list must name the type group').toHaveProperty('type_group');
|
||||||
|
|
||||||
|
await page.goto(`/school/${school.urn}`);
|
||||||
|
const header = page.locator('header', { has: page.getByRole('heading', { level: 1 }) });
|
||||||
|
const flags = header.getByRole('list', { name: 'Admission and provision' });
|
||||||
|
await expect(flags.getByText('Selective', { exact: true })).toBeVisible({ timeout: 15_000 });
|
||||||
|
const typeLabel = TYPE_GROUP_LABELS[school.type_group] ?? school.school_type;
|
||||||
|
await expect(header.getByText(typeLabel, { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
const tags = await rowTags(page, school);
|
||||||
|
await expect(tags.getByText('Selective', { exact: true })).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The Admissions section repeated the search rows' old tag logic: "selective"
|
||||||
|
* matched inside "Non-selective", and "None" counted as a faith, so Burntwood
|
||||||
|
* read "this school has a faith-based admissions priority (None)". The
|
||||||
|
* Selective half stayed hidden only because the school page's API did not
|
||||||
|
* send admissions_policy. Data-invariant: the school comes from the API, and
|
||||||
|
* must have an Admissions section to read.
|
||||||
|
*/
|
||||||
|
test('a non-selective school with no faith makes neither claim in its Admissions section', async ({ page }) => {
|
||||||
|
const res = await page.request.get(
|
||||||
|
'/api/schools?search=school&phase=secondary&faith=none&admissions_policy=non-selective&page_size=20');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
let urn: number | null = null;
|
||||||
|
for (const s of ((await res.json()).schools ?? []).slice(0, 8)) {
|
||||||
|
if (s.religious_denomination !== 'None') continue;
|
||||||
|
const detail = await (await page.request.get(`/api/schools/${s.urn}`)).json();
|
||||||
|
if (detail.admissions) { urn = s.urn; break; }
|
||||||
|
}
|
||||||
|
test.skip(urn == null, 'no non-selective, no-faith secondary with admissions data here');
|
||||||
|
|
||||||
|
await page.goto(`/school/${urn}`);
|
||||||
|
const admissions = page.locator('section#admissions');
|
||||||
|
await expect(admissions).toBeVisible({ timeout: 15_000 });
|
||||||
|
await expect(admissions.getByText('Selective:', { exact: true })).toHaveCount(0);
|
||||||
|
await expect(admissions.getByText('Faith priority:', { exact: true })).toHaveCount(0);
|
||||||
|
await expect(admissions.getByText(/\(None\)/)).toHaveCount(0);
|
||||||
|
});
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from '@testing-library/react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
nearbyNoun,
|
|
||||||
NearbySchoolsSection,
|
NearbySchoolsSection,
|
||||||
shouldRenderNearby,
|
shouldRenderNearby,
|
||||||
} from '@/components/school/NearbySchoolsSection';
|
} from '@/components/school/NearbySchoolsSection';
|
||||||
@@ -43,13 +42,7 @@ function school(overrides: Partial<NearbySchool> = {}): NearbySchool {
|
|||||||
|
|
||||||
function renderSection(nearby: NearbySchool[]) {
|
function renderSection(nearby: NearbySchool[]) {
|
||||||
return render(
|
return render(
|
||||||
<NearbySchoolsSection
|
<NearbySchoolsSection urn={100001} thisMetricValue={72} nearby={nearby} />,
|
||||||
urn={100001}
|
|
||||||
schoolName="Meadowbrook Primary School"
|
|
||||||
phase="Primary"
|
|
||||||
thisMetricValue={72}
|
|
||||||
nearby={nearby}
|
|
||||||
/>,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,15 +83,10 @@ describe('what the section claims', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('shows no chips at all when nothing is shared, rather than inventing one', () => {
|
it('shows no chips at all when nothing is shared, rather than inventing one', () => {
|
||||||
const { container } = render(
|
const { container } = renderSection([
|
||||||
<NearbySchoolsSection
|
school({ shared: [] }),
|
||||||
urn={100001}
|
school({ urn: 100003, shared: [] }),
|
||||||
schoolName="Meadowbrook Primary School"
|
]);
|
||||||
phase="Primary"
|
|
||||||
thisMetricValue={72}
|
|
||||||
nearby={[school({ shared: [] }), school({ urn: 100003, shared: [] })]}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
// The card still carries its distance, name, type and figure — just no
|
// The card still carries its distance, name, type and figure — just no
|
||||||
// claim of likeness.
|
// claim of likeness.
|
||||||
expect(container.querySelectorAll('li ul').length).toBe(0);
|
expect(container.querySelectorAll('li ul').length).toBe(0);
|
||||||
@@ -106,37 +94,6 @@ describe('what the section claims', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('what the lede calls the set', () => {
|
|
||||||
it.each([
|
|
||||||
['Primary', 'primary schools'],
|
|
||||||
['Middle deemed primary', 'primary schools'],
|
|
||||||
['Secondary', 'secondary schools'],
|
|
||||||
['Middle deemed secondary', 'secondary schools'],
|
|
||||||
['All-through', 'all-through schools'],
|
|
||||||
// GIAS phase 6. Its candidates span the whole secondary group, so no
|
|
||||||
// single noun fits and it takes the honest general one.
|
|
||||||
['16 plus', 'schools and colleges'],
|
|
||||||
['', 'schools'],
|
|
||||||
[null, 'schools'],
|
|
||||||
])('calls a %s school\'s neighbours "%s"', (phase, expected) => {
|
|
||||||
expect(nearbyNoun(phase)).toBe(expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('never calls a sixth form college\'s neighbours primary schools', () => {
|
|
||||||
render(
|
|
||||||
<NearbySchoolsSection
|
|
||||||
urn={100001}
|
|
||||||
schoolName="Barnet Sixth Form College"
|
|
||||||
phase="16 plus"
|
|
||||||
thisMetricValue={null}
|
|
||||||
nearby={[school(), school({ urn: 100003 })]}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
expect(screen.getByText(/Other schools and colleges near Barnet Sixth Form College/)).toBeInTheDocument();
|
|
||||||
expect(screen.queryByText(/primary schools/)).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('cards', () => {
|
describe('cards', () => {
|
||||||
it('links each school to its canonical slug', () => {
|
it('links each school to its canonical slug', () => {
|
||||||
renderSection([school(), school({ urn: 100003, school_name: 'Oakfield Primary School' })]);
|
renderSection([school(), school({ urn: 100003, school_name: 'Oakfield Primary School' })]);
|
||||||
|
|||||||
@@ -34,3 +34,21 @@ describe('SchoolRow religious character', () => {
|
|||||||
expect(screen.getByText('Church of England')).toBeInTheDocument();
|
expect(screen.getByText('Church of England')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('SchoolRow shares the school page flags', () => {
|
||||||
|
it("prints the type in the search filter's terms", () => {
|
||||||
|
render(<SchoolRow school={{ ...base, type_group: 'state' }} />);
|
||||||
|
expect(screen.getByText('State school')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Free schools')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('flags a nursery class', () => {
|
||||||
|
render(<SchoolRow school={{ ...base, nursery_provision: 'Has Nursery Classes' }} />);
|
||||||
|
expect(screen.getByText('Nursery class')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("flags a boys' school", () => {
|
||||||
|
render(<SchoolRow school={{ ...base, gender: 'Boys' }} />);
|
||||||
|
expect(screen.getByText("Boys' school")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -79,7 +79,7 @@ describe('SecondarySchoolRow admissions tag', () => {
|
|||||||
expect(screen.queryByText('Selective')).not.toBeInTheDocument();
|
expect(screen.queryByText('Selective')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(['None', 'Does not apply', '', null])(
|
it.each(['None', 'Does not apply'])(
|
||||||
'gives no faith tag when the religious character is %p',
|
'gives no faith tag when the religious character is %p',
|
||||||
(religious_denomination) => {
|
(religious_denomination) => {
|
||||||
render(
|
render(
|
||||||
@@ -87,16 +87,32 @@ describe('SecondarySchoolRow admissions tag', () => {
|
|||||||
school={{ ...base, admissions_policy: 'Not applicable', religious_denomination }}
|
school={{ ...base, admissions_policy: 'Not applicable', religious_denomination }}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
expect(screen.queryByText(religious_denomination)).not.toBeInTheDocument();
|
||||||
expect(screen.queryByText('Faith priority')).not.toBeInTheDocument();
|
expect(screen.queryByText('Faith priority')).not.toBeInTheDocument();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
it('tags a school with a religious character', () => {
|
it('tags the religious character the register records, not "Faith priority"', () => {
|
||||||
render(
|
render(
|
||||||
<SecondarySchoolRow
|
<SecondarySchoolRow
|
||||||
school={{ ...base, admissions_policy: 'Not applicable', religious_denomination: 'Church of England' }}
|
school={{ ...base, admissions_policy: 'Not applicable', religious_denomination: 'Church of England' }}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
expect(screen.getByText('Faith priority')).toBeInTheDocument();
|
expect(screen.getByText('Church of England')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Faith priority')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SecondarySchoolRow shares the school page flags', () => {
|
||||||
|
it("prints the type in the search filter's terms", () => {
|
||||||
|
render(<SecondarySchoolRow school={{ ...base, type_group: 'state' }} />);
|
||||||
|
expect(screen.getByText('State school')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Academy')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("flags a girls' school and fees", () => {
|
||||||
|
render(<SecondarySchoolRow school={{ ...base, type_group: 'independent', gender: 'Girls' }} />);
|
||||||
|
expect(screen.getByText("Girls' school")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Fee-paying')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* The facts row under the school name.
|
* The school header: one fact line (phase, ages, type, pupils), then flags
|
||||||
|
* only for what applies, then the address and the details.
|
||||||
*
|
*
|
||||||
* nursery_provision is GIAS text, not a boolean: "Has Nursery Classes",
|
* nursery_provision is GIAS text, not a boolean: "Has Nursery Classes",
|
||||||
* "No Nursery Classes" or "Not applicable". Tested for truthiness, every one
|
* "No Nursery Classes" or "Not applicable". Tested for truthiness, every one
|
||||||
* of those read as a nursery, so secondaries aged 11–18 showed "Nursery".
|
* of those read as a nursery, so secondaries aged 11–18 showed "Nursery".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { screen } from '@testing-library/react';
|
import { screen, within } from '@testing-library/react';
|
||||||
import type { School } from '@/lib/types';
|
import type { School } from '@/lib/types';
|
||||||
import { primaryFixture, secondaryFixture } from '../support/schoolFixtures';
|
import { primaryFixture, secondaryFixture } from '../support/schoolFixtures';
|
||||||
import { renderSchoolDetail, renderSecondarySchoolDetail } from '../support/renderSchoolDetail';
|
import { renderSchoolDetail, renderSecondarySchoolDetail } from '../support/renderSchoolDetail';
|
||||||
@@ -35,22 +36,54 @@ function withSchool<T extends { schoolInfo: School }>(fixture: T, info: Partial<
|
|||||||
return { ...fixture, schoolInfo: { ...fixture.schoolInfo, ...info } };
|
return { ...fixture, schoolInfo: { ...fixture.schoolInfo, ...info } };
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('school header nursery chip', () => {
|
const flagList = () => screen.queryByRole('list', { name: 'Admission and provision' });
|
||||||
it('shows Nursery when GIAS says the school has nursery classes', () => {
|
const flagLabels = () => within(flagList()!).getAllByRole('listitem').map((li) => li.textContent);
|
||||||
|
|
||||||
|
describe('school header fact line', () => {
|
||||||
|
it('states phase, ages, type and pupils, in that order', () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, { type_group: 'state' }));
|
||||||
|
const line = screen.getByText('Ages 4–11').parentElement!;
|
||||||
|
expect(line).toHaveTextContent(/^PrimaryAges 4–11State school420 pupils$/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prints the register's type name for a type in no group", () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, { type_group: null, school_type: 'Secure units' }));
|
||||||
|
expect(screen.getByText('Secure units')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('no longer prints the GIAS establishment type', () => {
|
||||||
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, { type_group: 'state' }));
|
||||||
|
expect(screen.queryByText('Academy converter')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('school header flags', () => {
|
||||||
|
it('shows no flag list for a school with nothing to flag', () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, { type_group: 'state' }));
|
||||||
|
expect(flagList()).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lists who-can-apply flags, then what the school offers', () => {
|
||||||
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, {
|
||||||
|
type_group: 'independent', admissions_policy: 'Selective', gender: 'Girls',
|
||||||
|
religious_denomination: 'Church of England', has_sixth_form: true,
|
||||||
|
}));
|
||||||
|
expect(flagLabels()).toEqual(['Fee-paying', 'Selective', "Girls' school", 'Church of England', 'Sixth form']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows Nursery class when GIAS says the school has nursery classes', () => {
|
||||||
renderSchoolDetail(withSchool(primaryFixture, { nursery_provision: 'Has Nursery Classes' }));
|
renderSchoolDetail(withSchool(primaryFixture, { nursery_provision: 'Has Nursery Classes' }));
|
||||||
expect(screen.getByText('Nursery', { selector: 'span' })).toBeInTheDocument();
|
expect(flagLabels()).toEqual(['Nursery class']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(['No Nursery Classes', 'Not applicable', null])(
|
it.each(['No Nursery Classes', 'Not applicable', null])(
|
||||||
'hides Nursery when GIAS says %p',
|
'shows no nursery flag when GIAS says %p',
|
||||||
(value) => {
|
(value) => {
|
||||||
renderSecondarySchoolDetail(withSchool(secondaryFixture, { nursery_provision: value }));
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, { nursery_provision: value }));
|
||||||
expect(screen.queryByText('Nursery', { selector: 'span' })).not.toBeInTheDocument();
|
expect(screen.queryByText(/^Nursery/)).not.toBeInTheDocument();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
|
||||||
|
|
||||||
describe('school header single-sex chip', () => {
|
|
||||||
it.each([['Girls', "Girls' school"], ['Boys', "Boys' school"]])(
|
it.each([['Girls', "Girls' school"], ['Boys', "Boys' school"]])(
|
||||||
'labels a %s school with a plural possessive',
|
'labels a %s school with a plural possessive',
|
||||||
(gender, label) => {
|
(gender, label) => {
|
||||||
@@ -65,3 +98,44 @@ describe('school header single-sex chip', () => {
|
|||||||
expect(screen.queryByText(/^(Girls|Boys|Mixed)'s? school$/)).not.toBeInTheDocument();
|
expect(screen.queryByText(/^(Girls|Boys|Mixed)'s? school$/)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('school header address', () => {
|
||||||
|
it('names the council after the postcode', () => {
|
||||||
|
renderSchoolDetail(primaryFixture);
|
||||||
|
expect(screen.getByText(/TE1 1ST · Westshire/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('leaves the council out when the address already names it', () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, { local_authority: 'Testville' }));
|
||||||
|
expect(screen.queryByText(/· Testville/)).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('school header details', () => {
|
||||||
|
const detailed = {
|
||||||
|
headteacher_name: 'Mrs A Head', capacity: 426, county: 'Surrey',
|
||||||
|
parliamentary_constituency: 'Putney', religious_denomination: 'Church of England',
|
||||||
|
};
|
||||||
|
|
||||||
|
it('drops county, constituency and religious character', () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, detailed));
|
||||||
|
expect(screen.queryByText('County:')).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Constituency:')).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Religious character:')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the capacity', () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, detailed));
|
||||||
|
expect(screen.getByText('Capacity:').parentElement).toHaveTextContent('Capacity: 426');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('names an academy trust', () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, { trust_name: 'BURNTWOOD TRUST' }));
|
||||||
|
expect(screen.getByText('Academy trust:').parentElement).toHaveTextContent('BURNTWOOD TRUST');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("hides a trust that has the school's own name", () => {
|
||||||
|
renderSchoolDetail(withSchool(primaryFixture, { trust_name: 'TEST PRIMARY SCHOOL' }));
|
||||||
|
expect(screen.queryByText('Academy trust:')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -43,14 +43,13 @@ function withoutCensus(schoolTotal: number | null) {
|
|||||||
describe('pupil count without a census record', () => {
|
describe('pupil count without a census record', () => {
|
||||||
it('uses the register count in the header, not the results cohort', () => {
|
it('uses the register count in the header, not the results cohort', () => {
|
||||||
renderSecondarySchoolDetail(withoutCensus(1462));
|
renderSecondarySchoolDetail(withoutCensus(1462));
|
||||||
const pupils = screen.getByText('Pupils:').parentElement!;
|
expect(screen.getByText('1,462 pupils')).toBeInTheDocument();
|
||||||
expect(pupils).toHaveTextContent('1,462');
|
expect(screen.queryByText('245 pupils')).not.toBeInTheDocument();
|
||||||
expect(pupils).not.toHaveTextContent('245');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows no count rather than the results cohort when the register has none', () => {
|
it('shows no count rather than the results cohort when the register has none', () => {
|
||||||
renderSecondarySchoolDetail(withoutCensus(null));
|
renderSecondarySchoolDetail(withoutCensus(null));
|
||||||
expect(screen.queryByText('Pupils:')).not.toBeInTheDocument();
|
expect(screen.queryByText(/^[\d,]+ pupils$/)).not.toBeInTheDocument();
|
||||||
expect(screen.queryByText('Total pupils')).not.toBeInTheDocument();
|
expect(screen.queryByText('Total pupils')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/**
|
||||||
|
* The Admissions section's Selective and faith notes.
|
||||||
|
*
|
||||||
|
* It tested the policy with includes('selective'), which "Non-selective"
|
||||||
|
* passes, and excluded only "Does not apply" from the religious character, so
|
||||||
|
* Burntwood (no religious character, recorded as "None") read "this school
|
||||||
|
* has a faith-based admissions priority (None)". The Selective half never
|
||||||
|
* fired only because the school page's API did not send admissions_policy.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { screen, within } from '@testing-library/react';
|
||||||
|
import type { School } from '@/lib/types';
|
||||||
|
import { secondaryFixture } from '../support/schoolFixtures';
|
||||||
|
import { renderSecondarySchoolDetail } from '../support/renderSchoolDetail';
|
||||||
|
|
||||||
|
jest.mock('@/lib/analytics', () => ({
|
||||||
|
track: jest.fn(),
|
||||||
|
getNavigationSource: () => 'direct',
|
||||||
|
}));
|
||||||
|
jest.mock('@/components/PerformanceChart', () => ({
|
||||||
|
PerformanceChart: () => <div data-testid="performance-chart" />,
|
||||||
|
}));
|
||||||
|
jest.mock('@/components/AdmissionsTrendChart', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: () => <div data-testid="admissions-trend-chart" />,
|
||||||
|
}));
|
||||||
|
jest.mock('@/components/SchoolHeroMap', () => ({
|
||||||
|
SchoolHeroMap: () => <div data-testid="hero-map" />,
|
||||||
|
__esModule: true,
|
||||||
|
}));
|
||||||
|
|
||||||
|
function admissionsOf(info: Partial<School>) {
|
||||||
|
renderSecondarySchoolDetail({ ...secondaryFixture, schoolInfo: { ...secondaryFixture.schoolInfo, ...info } });
|
||||||
|
return within(screen.getByRole('heading', { name: 'Admissions' }).closest('section')!);
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Admissions section notes', () => {
|
||||||
|
it('notes the entrance test for a selective school', () => {
|
||||||
|
const section = admissionsOf({ admissions_policy: 'Selective', religious_denomination: 'None' });
|
||||||
|
expect(section.getByText('Selective:')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not call a non-selective school selective', () => {
|
||||||
|
const section = admissionsOf({ admissions_policy: 'Non-selective', religious_denomination: 'None' });
|
||||||
|
expect(section.queryByText('Selective:')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(['None', 'Does not apply'])('claims no faith priority when the register says %p', (religious_denomination) => {
|
||||||
|
// Not "Non-selective": a misread Selective would win and hide this case.
|
||||||
|
const section = admissionsOf({ admissions_policy: 'Not applicable', religious_denomination });
|
||||||
|
expect(section.queryByText('Faith priority:')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('notes the religious character of a faith school', () => {
|
||||||
|
const section = admissionsOf({ admissions_policy: 'Non-selective', religious_denomination: 'Church of England' });
|
||||||
|
expect(section.getByText('Faith priority:')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -157,6 +157,13 @@ describe('compareToCutoff', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('describeCutoffAbsence', () => {
|
describe('describeCutoffAbsence', () => {
|
||||||
|
it('does not read "Non-selective" as selective', () => {
|
||||||
|
// A substring test matched "selective" inside "Non-selective".
|
||||||
|
const s = describeCutoffAbsence({ localAuthority: 'Wandsworth', admissionsPolicy: 'Non-selective' });
|
||||||
|
expect(s).not.toMatch(/entrance test/);
|
||||||
|
expect(s).toMatch(/^Wandsworth has not published/);
|
||||||
|
});
|
||||||
|
|
||||||
it('explains a selective school by how it admits, not as missing data', () => {
|
it('explains a selective school by how it admits, not as missing data', () => {
|
||||||
const s = describeCutoffAbsence({ localAuthority: 'Kent', admissionsPolicy: 'Selective' });
|
const s = describeCutoffAbsence({ localAuthority: 'Kent', admissionsPolicy: 'Selective' });
|
||||||
expect(s).toContain('entrance test');
|
expect(s).toContain('entrance test');
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/**
|
||||||
|
* The facts the school header and the search rows print: a type in the search
|
||||||
|
* filter's terms, and flags only for what applies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { schoolFlags, schoolTypeLabel } from '@/lib/schoolFacts';
|
||||||
|
import type { School } from '@/lib/types';
|
||||||
|
|
||||||
|
const school = (over: Partial<School>): School =>
|
||||||
|
({ urn: 1, school_name: 'Test School', ...over }) as School;
|
||||||
|
|
||||||
|
const labels = (over: Partial<School>) => schoolFlags(school(over)).map((f) => f.label);
|
||||||
|
|
||||||
|
describe('schoolTypeLabel', () => {
|
||||||
|
it.each([
|
||||||
|
['state', 'State school'],
|
||||||
|
['independent', 'Independent school'],
|
||||||
|
['special', 'Special school (SEND)'],
|
||||||
|
['post16', 'Sixth form or college'],
|
||||||
|
['alternative', 'Alternative provision'],
|
||||||
|
])("names the %s group in the search filter's terms", (type_group, label) => {
|
||||||
|
expect(schoolTypeLabel(school({ type_group, school_type: 'Academy converter' }))).toBe(label);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("prints the register's own name for a type in no group", () => {
|
||||||
|
expect(schoolTypeLabel(school({ type_group: null, school_type: 'Secure units' }))).toBe('Secure units');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns null when there is no type at all', () => {
|
||||||
|
expect(schoolTypeLabel(school({}))).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('schoolFlags', () => {
|
||||||
|
it('flags nothing for a mixed, non-faith, non-selective state school', () => {
|
||||||
|
expect(labels({
|
||||||
|
type_group: 'state', gender: 'Mixed', admissions_policy: 'Non-selective',
|
||||||
|
religious_denomination: 'None', nursery_provision: 'No Nursery Classes',
|
||||||
|
has_sixth_form: false, phase: 'Secondary',
|
||||||
|
})).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lists who-can-apply flags first, then what the school offers, in a fixed order', () => {
|
||||||
|
expect(labels({
|
||||||
|
type_group: 'independent', admissions_policy: 'Selective', gender: 'Boys',
|
||||||
|
religious_denomination: 'Christian', nursery_provision: 'Has Nursery Classes',
|
||||||
|
has_sixth_form: true, phase: 'All-through',
|
||||||
|
})).toEqual(['Fee-paying', 'Selective', "Boys' school", 'Christian', 'Nursery class', 'Sixth form']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('marks who-can-apply flags as conditions and offers as provision', () => {
|
||||||
|
const kinds = Object.fromEntries(
|
||||||
|
schoolFlags(school({ admissions_policy: 'Selective', has_sixth_form: true, phase: 'Secondary' }))
|
||||||
|
.map((f) => [f.label, f.kind]),
|
||||||
|
);
|
||||||
|
expect(kinds).toEqual({ Selective: 'condition', 'Sixth form': 'provision' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('never prints Non-selective, and never a no-faith value', () => {
|
||||||
|
expect(labels({ admissions_policy: 'Non-selective', religious_denomination: 'Does not apply' })).toEqual([]);
|
||||||
|
expect(labels({ admissions_policy: 'Not applicable', religious_denomination: 'None' })).toEqual([]);
|
||||||
|
// PlaceView's rule: GIAS sometimes says "Not applicable" for no faith too.
|
||||||
|
expect(labels({ religious_denomination: 'Not applicable' })).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prints the religious character as the register records it', () => {
|
||||||
|
expect(labels({ religious_denomination: 'Church of England/Methodist' })).toEqual(['Church of England/Methodist']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not flag a nursery class on a nursery school, or a sixth form on a post-16 one', () => {
|
||||||
|
expect(labels({ phase: 'Nursery', nursery_provision: 'Has Nursery Classes' })).toEqual([]);
|
||||||
|
expect(labels({ phase: '16 plus', has_sixth_form: true })).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -100,6 +100,19 @@
|
|||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Changes who can apply or what it costs. Outlined, not tinted: a fact, not
|
||||||
|
a verdict. An inset ring keeps the box the size of its neighbours. */
|
||||||
|
.conditionTag {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.0625rem 0.4rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.4;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(var(--ink-rgb), 0.4);
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
/* Line 3: stats */
|
/* Line 3: stats */
|
||||||
.line3 {
|
.line3 {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
* Four-line row for primary school search results
|
* Four-line row for primary school search results
|
||||||
*
|
*
|
||||||
* Line 1: School name · Ofsted badge (framework-aware)
|
* Line 1: School name · Ofsted badge (framework-aware)
|
||||||
* Line 2: School type · Age range · Denomination · Gender
|
* Line 2: Phase · Type · Age range · the school page's flags (lib/schoolFacts)
|
||||||
* Line 3: Reading, Writing & Maths % · trend arrow · vs-national delta · Pupils
|
* Line 3: Reading, Writing & Maths % · trend arrow · vs-national delta · Pupils
|
||||||
* Line 4: Local authority · Distance
|
* Line 4: Local authority · Distance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { School } from '@/lib/types';
|
import type { School } from '@/lib/types';
|
||||||
import { formatPercentage, calculateTrend, getPhaseStyle, schoolUrl, buildOfstedListBadge, formatAgeRange, hasReligiousCharacter, isProposedToClose, isSpecialSchool, listRwmValue } from '@/lib/utils';
|
import { formatPercentage, calculateTrend, getPhaseStyle, schoolUrl, buildOfstedListBadge, formatAgeRange, isProposedToClose, isSpecialSchool, listRwmValue } from '@/lib/utils';
|
||||||
|
import { schoolFlags, schoolTypeLabel } from '@/lib/schoolFacts';
|
||||||
import styles from './SchoolRow.module.css';
|
import styles from './SchoolRow.module.css';
|
||||||
|
|
||||||
interface SchoolRowProps {
|
interface SchoolRowProps {
|
||||||
@@ -33,8 +34,8 @@ export function SchoolRow({
|
|||||||
const phase = getPhaseStyle(school.phase);
|
const phase = getPhaseStyle(school.phase);
|
||||||
const ofstedBadge = buildOfstedListBadge(school);
|
const ofstedBadge = buildOfstedListBadge(school);
|
||||||
|
|
||||||
const showGender = school.gender && school.gender.toLowerCase() !== 'mixed';
|
const typeLabel = schoolTypeLabel(school);
|
||||||
const showDenomination = hasReligiousCharacter(school.religious_denomination);
|
const flags = schoolFlags(school);
|
||||||
|
|
||||||
// The school's OWN figure and its year-over-year trend are same-school
|
// The school's OWN figure and its year-over-year trend are same-school
|
||||||
// measures — shown whenever there's a real value (not the all-zero
|
// measures — shown whenever there's a real value (not the all-zero
|
||||||
@@ -77,10 +78,16 @@ export function SchoolRow({
|
|||||||
{phase.label}
|
{phase.label}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{school.school_type && <span className={styles.attr}>{school.school_type}</span>}
|
{typeLabel && <span className={styles.attr}>{typeLabel}</span>}
|
||||||
{school.age_range && <span className={styles.attr}>{formatAgeRange(school.age_range)}</span>}
|
{school.age_range && <span className={styles.attr}>{formatAgeRange(school.age_range)}</span>}
|
||||||
{showDenomination && <span className={styles.attr}>{school.religious_denomination}</span>}
|
{flags.map((flag) => (
|
||||||
{showGender && <span className={styles.attr}>{school.gender}</span>}
|
<span
|
||||||
|
key={flag.label}
|
||||||
|
className={flag.kind === 'condition' ? styles.conditionTag : styles.attr}
|
||||||
|
>
|
||||||
|
{flag.label}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
{isProposedToClose(school) && (
|
{isProposedToClose(school) && (
|
||||||
<span className={`${styles.attr} ${styles.attrClosing}`}>⚠ Proposed to close</span>
|
<span className={`${styles.attr} ${styles.attrClosing}`}>⚠ Proposed to close</span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -183,9 +183,17 @@
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.selectiveTag {
|
/* Changes who can apply or what it costs. Outlined, not tinted: a fact, not
|
||||||
background: rgba(var(--status-below-rgb), 0.1);
|
a verdict. An inset ring keeps the box the size of its neighbours. */
|
||||||
color: var(--status-below);
|
.conditionTag {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0.0625rem 0.4rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.4;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: inset 0 0 0 1px rgba(var(--ink-rgb), 0.4);
|
||||||
|
color: var(--text-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Ofsted badge ────────────────────────────────────── */
|
/* ── Ofsted badge ────────────────────────────────────── */
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* Four-line row for secondary school search results
|
* Four-line row for secondary school search results
|
||||||
*
|
*
|
||||||
* Line 1: School name · Ofsted badge
|
* Line 1: School name · Ofsted badge
|
||||||
* Line 2: School type · Age range · Gender · Sixth form · Admissions tag
|
* Line 2: Phase · Type · Age range · the school page's flags (lib/schoolFacts)
|
||||||
* Line 3: Attainment 8 (large) · ±LA avg delta · Pupils
|
* Line 3: Attainment 8 (large) · ±LA avg delta · Pupils
|
||||||
* Line 4: LA name · distance
|
* Line 4: LA name · distance
|
||||||
*/
|
*/
|
||||||
@@ -11,22 +11,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { School } from '@/lib/types';
|
import type { School } from '@/lib/types';
|
||||||
import { buildOfstedListBadge, getPhaseStyle, schoolUrl, formatAgeRange, hasReligiousCharacter, isProposedToClose, isSpecialSchool } from '@/lib/utils';
|
import { buildOfstedListBadge, getPhaseStyle, schoolUrl, formatAgeRange, isProposedToClose, isSpecialSchool } from '@/lib/utils';
|
||||||
|
import { schoolFlags, schoolTypeLabel } from '@/lib/schoolFacts';
|
||||||
import styles from './SecondarySchoolRow.module.css';
|
import styles from './SecondarySchoolRow.module.css';
|
||||||
|
|
||||||
function detectAdmissionsTag(school: School): string | null {
|
|
||||||
// Exact match: "Non-selective" contains "selective", so a substring test
|
|
||||||
// tagged every comprehensive as Selective.
|
|
||||||
if (school.admissions_policy?.trim().toLowerCase() === 'selective') return 'Selective';
|
|
||||||
if (hasReligiousCharacter(school.religious_denomination)) return 'Faith priority';
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function hasSixthForm(school: School): boolean {
|
|
||||||
// GIAS OfficialSixthForm flag; missing (pipeline not yet re-run) => false.
|
|
||||||
return school.has_sixth_form ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface SecondarySchoolRowProps {
|
interface SecondarySchoolRowProps {
|
||||||
school: School;
|
school: School;
|
||||||
isLocationSearch?: boolean;
|
isLocationSearch?: boolean;
|
||||||
@@ -64,9 +52,8 @@ export function SecondarySchoolRow({
|
|||||||
? att8 - laAvgAttainment8
|
? att8 - laAvgAttainment8
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const admissionsTag = detectAdmissionsTag(school);
|
const typeLabel = schoolTypeLabel(school);
|
||||||
const sixthForm = hasSixthForm(school);
|
const flags = schoolFlags(school);
|
||||||
const showGender = school.gender && school.gender.toLowerCase() !== 'mixed';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`${styles.row} ${phase.key ? styles[`phase${phase.key}`] : ''} ${isInCompare ? styles.rowInCompare : ''}`}>
|
<div className={`${styles.row} ${phase.key ? styles[`phase${phase.key}`] : ''} ${isInCompare ? styles.rowInCompare : ''}`}>
|
||||||
@@ -90,19 +77,16 @@ export function SecondarySchoolRow({
|
|||||||
{phase.label}
|
{phase.label}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{school.school_type && <span className={styles.attr}>{school.school_type}</span>}
|
{typeLabel && <span className={styles.attr}>{typeLabel}</span>}
|
||||||
{school.age_range && <span className={styles.attr}>{formatAgeRange(school.age_range)}</span>}
|
{school.age_range && <span className={styles.attr}>{formatAgeRange(school.age_range)}</span>}
|
||||||
{showGender && (
|
{flags.map((flag) => (
|
||||||
<span className={styles.provisionTag}>{school.gender}</span>
|
<span
|
||||||
)}
|
key={flag.label}
|
||||||
{sixthForm && (
|
className={flag.kind === 'condition' ? styles.conditionTag : styles.provisionTag}
|
||||||
<span className={styles.provisionTag}>Sixth form</span>
|
>
|
||||||
)}
|
{flag.label}
|
||||||
{admissionsTag && (
|
|
||||||
<span className={`${styles.provisionTag} ${admissionsTag === 'Selective' ? styles.selectiveTag : ''}`}>
|
|
||||||
{admissionsTag}
|
|
||||||
</span>
|
</span>
|
||||||
)}
|
))}
|
||||||
{isProposedToClose(school) && (
|
{isProposedToClose(school) && (
|
||||||
<span className={`${styles.provisionTag} ${styles.closingTag}`}>⚠ Proposed to close</span>
|
<span className={`${styles.provisionTag} ${styles.closingTag}`}>⚠ Proposed to close</span>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
.heading { font-family: var(--font-display); font-size: 1.4rem; letter-spacing: -0.4px; margin: 0; }
|
.heading { font-family: var(--font-display); font-size: 1.4rem; letter-spacing: -0.4px; margin: 0; }
|
||||||
.lede { margin: 0.5rem 0 1.25rem; color: var(--text-secondary); max-width: 64ch; }
|
|
||||||
.caption { margin: 1rem 0 0; font-size: 0.72rem; color: var(--text-muted); }
|
.caption { margin: 1rem 0 0; font-size: 0.72rem; color: var(--text-muted); }
|
||||||
|
|
||||||
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
|
.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
|
||||||
.arrows { display: flex; gap: 0.5rem; flex: none; }
|
.arrows { display: flex; gap: 0.5rem; flex: none; }
|
||||||
.arrow { width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--bg-card); color: var(--brand); }
|
.arrow { width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer; border: 1px solid var(--border-strong); border-radius: 999px; background: var(--bg-card); color: var(--brand); }
|
||||||
.arrow:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-bg); }
|
.arrow:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-bg); }
|
||||||
@@ -15,10 +14,10 @@
|
|||||||
.scroller { display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - 1.8rem) / 3); gap: 0.9rem; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px; margin: -2px; list-style: none; scrollbar-width: none; -ms-overflow-style: none; }
|
.scroller { display: grid; grid-auto-flow: column; grid-auto-columns: calc((100% - 1.8rem) / 3); gap: 0.9rem; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px; margin: -2px; list-style: none; scrollbar-width: none; -ms-overflow-style: none; }
|
||||||
.scroller::-webkit-scrollbar { display: none; }
|
.scroller::-webkit-scrollbar { display: none; }
|
||||||
@media (max-width: 820px) { .scroller { grid-auto-columns: calc((100% - 0.9rem) / 2); } }
|
@media (max-width: 820px) { .scroller { grid-auto-columns: calc((100% - 0.9rem) / 2); } }
|
||||||
/* Touch widths (MOBILE.md): the arrows would take 96px from a 328px card and
|
/* Touch widths (MOBILE.md): the arrows would take 96px from a 328px card, for
|
||||||
crush the lede into four lines, for a control swiping already provides. They
|
a control swiping already provides. They go, and the documented right-edge
|
||||||
go, and the documented right-edge fade carries the affordance — lifting at
|
fade carries the affordance — lifting at the end of the travel, where there
|
||||||
the end of the travel, where there is nothing more to hint at. */
|
is nothing more to hint at. */
|
||||||
@media (max-width: 640px) {
|
@media (max-width: 640px) {
|
||||||
.top { display: block; }
|
.top { display: block; }
|
||||||
.arrows { display: none; }
|
.arrows { display: none; }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* The scroller and its arrows.
|
* The scroller and its arrows.
|
||||||
*
|
*
|
||||||
* `children` are the server-rendered cards and `header` the server-rendered
|
* `children` are the server-rendered cards and `header` the server-rendered
|
||||||
* heading and lede: both stay server components, passed through, so this file
|
* heading: both stay server components, passed through, so this file
|
||||||
* owns a DOM ref and nothing else. That is what keeps all six links in the
|
* owns a DOM ref and nothing else. That is what keeps all six links in the
|
||||||
* initial HTML — a carousel that mounted cards on click would put four of the
|
* initial HTML — a carousel that mounted cards on click would put four of the
|
||||||
* six beyond a crawler and beyond a reader with no JavaScript.
|
* six beyond a crawler and beyond a reader with no JavaScript.
|
||||||
|
|||||||
@@ -13,8 +13,10 @@
|
|||||||
* reached on their behalf.
|
* reached on their behalf.
|
||||||
*
|
*
|
||||||
* There is deliberately no "how these are chosen" panel: the method is already
|
* There is deliberately no "how these are chosen" panel: the method is already
|
||||||
* visible in the lede, the chips and the distances. The single caption line is
|
* visible in the chips and the distances. The single caption line is not a
|
||||||
* not a method note — it is the one thing a card cannot self-correct.
|
* method note — it is the one thing a card cannot self-correct.
|
||||||
|
*
|
||||||
|
* Nor is there a lede: "Other primary schools near X" only restated the heading.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
@@ -32,28 +34,6 @@ export function shouldRenderNearby(nearby?: NearbySchool[] | null): boolean {
|
|||||||
return (nearby?.length ?? 0) >= MINIMUM;
|
return (nearby?.length ?? 0) >= MINIMUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* What the lede calls the set of schools it is showing.
|
|
||||||
*
|
|
||||||
* Derived from the school's own GIAS phase rather than the template it renders
|
|
||||||
* with, because those disagree for "16 plus" (GIAS phase 6): a sixth-form
|
|
||||||
* college renders the primary template — computeSchoolFlags tests for the
|
|
||||||
* substring "secondary" — while the backend correctly matches it against the
|
|
||||||
* secondary group. Taking the noun from the template would print "Other primary
|
|
||||||
* schools near <sixth form college>" above a row of secondaries.
|
|
||||||
*
|
|
||||||
* A 16-plus school's candidates span the whole secondary group, so no single
|
|
||||||
* noun fits and it gets the honest general one.
|
|
||||||
*/
|
|
||||||
export function nearbyNoun(phase: string | null | undefined): string {
|
|
||||||
const text = (phase ?? '').trim().toLowerCase();
|
|
||||||
if (text === 'all-through') return 'all-through schools';
|
|
||||||
if (text === '16 plus') return 'schools and colleges';
|
|
||||||
if (text.includes('secondary')) return 'secondary schools';
|
|
||||||
if (text.includes('primary')) return 'primary schools';
|
|
||||||
return 'schools';
|
|
||||||
}
|
|
||||||
|
|
||||||
function metricLabel(key: string): string {
|
function metricLabel(key: string): string {
|
||||||
return key === 'attainment_8_score' ? 'Attainment 8' : 'Reading, writing & maths';
|
return key === 'attainment_8_score' ? 'Attainment 8' : 'Reading, writing & maths';
|
||||||
}
|
}
|
||||||
@@ -65,25 +45,16 @@ function formatMetric(value: number | null, key: string): string {
|
|||||||
|
|
||||||
export function NearbySchoolsSection({
|
export function NearbySchoolsSection({
|
||||||
urn,
|
urn,
|
||||||
schoolName,
|
|
||||||
phase,
|
|
||||||
thisMetricValue,
|
thisMetricValue,
|
||||||
nearby,
|
nearby,
|
||||||
}: {
|
}: {
|
||||||
urn: number;
|
urn: number;
|
||||||
schoolName: string;
|
|
||||||
/** The school's own GIAS phase, not the template it renders with. */
|
|
||||||
phase: string | null | undefined;
|
|
||||||
thisMetricValue: number | null;
|
thisMetricValue: number | null;
|
||||||
nearby?: NearbySchool[] | null;
|
nearby?: NearbySchool[] | null;
|
||||||
}) {
|
}) {
|
||||||
if (!shouldRenderNearby(nearby)) return null;
|
if (!shouldRenderNearby(nearby)) return null;
|
||||||
const schools = nearby as NearbySchool[];
|
const schools = nearby as NearbySchool[];
|
||||||
|
|
||||||
// One card matched on phase alone, so the section may not claim the set
|
|
||||||
// shares an intake with this school.
|
|
||||||
const metricKey = schools[0].metric_key;
|
const metricKey = schools[0].metric_key;
|
||||||
const noun = nearbyNoun(phase);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section id="nearby">
|
<Section id="nearby">
|
||||||
@@ -91,12 +62,9 @@ export function NearbySchoolsSection({
|
|||||||
count={schools.length}
|
count={schools.length}
|
||||||
labelledBy="nearby-schools-heading"
|
labelledBy="nearby-schools-heading"
|
||||||
header={
|
header={
|
||||||
<div>
|
|
||||||
<h2 id="nearby-schools-heading" className={styles.heading}>
|
<h2 id="nearby-schools-heading" className={styles.heading}>
|
||||||
Other schools nearby
|
Other schools nearby
|
||||||
</h2>
|
</h2>
|
||||||
<p className={styles.lede}>{`Other ${noun} near ${schoolName}.`}</p>
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{schools.map((school) => (
|
{schools.map((school) => (
|
||||||
|
|||||||
@@ -154,8 +154,6 @@ export function PrimarySchoolSections({
|
|||||||
{/* Last: it is where the reader goes next, not part of this school. */}
|
{/* Last: it is where the reader goes next, not part of this school. */}
|
||||||
<NearbySchoolsSection
|
<NearbySchoolsSection
|
||||||
urn={schoolInfo.urn}
|
urn={schoolInfo.urn}
|
||||||
schoolName={schoolInfo.school_name}
|
|
||||||
phase={schoolInfo.phase}
|
|
||||||
thisMetricValue={flags.latestResults?.rwm_expected_pct ?? null}
|
thisMetricValue={flags.latestResults?.rwm_expected_pct ?? null}
|
||||||
nearby={nearbySchools}
|
nearby={nearbySchools}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -145,20 +145,90 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.meta {
|
/* Fact line: the phase pill, then plain register values joined by dots.
|
||||||
|
The line starts 1.125rem left of the column and clips that strip, so a
|
||||||
|
value that wraps to the start of a line loses the dot in front of it
|
||||||
|
instead of opening the line with one. */
|
||||||
|
.facts {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
gap: 0.5rem;
|
align-items: center;
|
||||||
margin-bottom: 0.5rem;
|
row-gap: 0.25rem;
|
||||||
|
margin: 0 0 0.5rem -1.125rem;
|
||||||
|
clip-path: inset(0 0 0 1.125rem);
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.metaItem {
|
.facts > * {
|
||||||
font-size: 0.8125rem;
|
margin-left: 1.125rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.fact {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.fact::before {
|
||||||
|
content: "·";
|
||||||
|
position: absolute;
|
||||||
|
left: -0.75rem;
|
||||||
|
color: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* The search rows' phase pill, in the same phase colours. */
|
||||||
|
.phasePill {
|
||||||
|
padding: 0.0625rem 0.4rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.4;
|
||||||
|
border-radius: 4px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phasePillPrimary { background: var(--phase-primary-bg); color: var(--phase-primary-text); }
|
||||||
|
.phasePillSecondary { background: var(--phase-secondary-bg); color: var(--phase-secondary-text); }
|
||||||
|
.phasePillAllThrough { background: var(--phase-all-through-bg); color: var(--phase-all-through-text); }
|
||||||
|
.phasePillPost16 { background: var(--phase-post16-bg); color: var(--phase-post16-text); }
|
||||||
|
.phasePillNursery { background: var(--phase-nursery-bg); color: var(--phase-nursery-text); }
|
||||||
|
|
||||||
|
|
||||||
|
/* Flags are facts, not verdicts, so they carry no hue. Outlined changes who
|
||||||
|
can apply or what it costs; filled is what the school offers. Text may
|
||||||
|
wrap: the longest religious character runs past a 360px line. */
|
||||||
|
.flags {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.375rem;
|
||||||
|
margin: 0 0 0.625rem;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.flagCondition,
|
||||||
|
.flagProvision {
|
||||||
|
padding: 0.0625rem 0.5rem;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.4;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.flagCondition {
|
||||||
|
border-color: rgba(var(--ink-rgb), 0.4);
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.flagProvision {
|
||||||
|
background: rgba(var(--ink-rgb), 0.07);
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
padding: 0.125rem 0.5rem;
|
|
||||||
background: var(--bg-secondary);
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -703,17 +773,8 @@
|
|||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pills wrap horizontally instead of stacking — short tokens like
|
/* Secondary header info (headteacher, website, phone, trust, capacity)
|
||||||
"Manchester" / "Voluntary aided" fit 2 per row instead of 3 full
|
isn't needed above the fold on phones/tablets, so it's
|
||||||
rows of empty horizontal space. */
|
|
||||||
.meta {
|
|
||||||
flex-direction: row;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 0.375rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Secondary header info (headteacher, website, pupil count, trust,
|
|
||||||
contact, area) isn't needed above the fold on phones/tablets, so it's
|
|
||||||
collapsed by default and revealed on demand via the "Show all details"
|
collapsed by default and revealed on demand via the "Show all details"
|
||||||
link — reclaiming the vertical space so the metrics surface sooner. */
|
link — reclaiming the vertical space so the metrics surface sooner. */
|
||||||
.detailsToggle {
|
.detailsToggle {
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { useComparison } from '@/hooks/useComparison';
|
import { useComparison } from '@/hooks/useComparison';
|
||||||
import { SchoolHeroMap, type SchoolHeroMapHandle } from '../SchoolHeroMap';
|
import { SchoolHeroMap, type SchoolHeroMapHandle } from '../SchoolHeroMap';
|
||||||
import type { School, SchoolResult, SchoolCensus } from '@/lib/types';
|
import type { School, SchoolCensus } from '@/lib/types';
|
||||||
import { formatAgeRange, hasNurseryClasses, isProposedToClose, singleSexLabel } from '@/lib/utils';
|
import { formatAgeRange, getPhaseStyle, isProposedToClose } from '@/lib/utils';
|
||||||
|
import { schoolFlags, schoolTypeLabel } from '@/lib/schoolFacts';
|
||||||
import type { NavItem } from '@/lib/schoolSections';
|
import type { NavItem } from '@/lib/schoolSections';
|
||||||
import { track, getNavigationSource } from '@/lib/analytics';
|
import { track, getNavigationSource } from '@/lib/analytics';
|
||||||
import styles from './SchoolDetailShell.module.css';
|
import styles from './SchoolDetailShell.module.css';
|
||||||
@@ -41,6 +42,12 @@ export interface SchoolDetailShellProps {
|
|||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Equal ignoring case and punctuation: "TIFFIN SCHOOL" is Tiffin School. */
|
||||||
|
function sameName(a: string, b: string): boolean {
|
||||||
|
const key = (s: string) => s.toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||||
|
return key(a) === key(b);
|
||||||
|
}
|
||||||
|
|
||||||
export function SchoolDetailShell({
|
export function SchoolDetailShell({
|
||||||
schoolInfo, census, navItems, children,
|
schoolInfo, census, navItems, children,
|
||||||
}: SchoolDetailShellProps) {
|
}: SchoolDetailShellProps) {
|
||||||
@@ -61,7 +68,7 @@ export function SchoolDetailShell({
|
|||||||
const heroMapRef = useRef<SchoolHeroMapHandle>(null);
|
const heroMapRef = useRef<SchoolHeroMapHandle>(null);
|
||||||
// "All ▾" jump menu listing every section.
|
// "All ▾" jump menu listing every section.
|
||||||
const [sectionsOpen, setSectionsOpen] = useState(false);
|
const [sectionsOpen, setSectionsOpen] = useState(false);
|
||||||
// Header details (headteacher, contact, trust, area) collapse behind a
|
// Header details (headteacher, contact, trust, capacity) collapse behind a
|
||||||
// "Show all details" link on mobile/tablet, where they're below the fold.
|
// "Show all details" link on mobile/tablet, where they're below the fold.
|
||||||
const [detailsOpen, setDetailsOpen] = useState(false);
|
const [detailsOpen, setDetailsOpen] = useState(false);
|
||||||
|
|
||||||
@@ -125,9 +132,28 @@ export function SchoolDetailShell({
|
|||||||
// composers; recomputing them here would duplicate that work for values
|
// composers; recomputing them here would duplicate that work for values
|
||||||
// this component never renders.
|
// this component never renders.
|
||||||
const phase = schoolInfo.phase ?? '';
|
const phase = schoolInfo.phase ?? '';
|
||||||
const isAllThrough = phase.toLowerCase() === 'all-through';
|
|
||||||
const hasLocation = schoolInfo.latitude != null && schoolInfo.longitude != null;
|
const hasLocation = schoolInfo.latitude != null && schoolInfo.longitude != null;
|
||||||
const singleSex = singleSexLabel(schoolInfo.gender);
|
|
||||||
|
// Header facts: each is one register value in a fixed slot (lib/schoolFacts).
|
||||||
|
const phasePill = getPhaseStyle(schoolInfo.phase);
|
||||||
|
// Never latestResults.total_pupils: that is the results cohort, which for a
|
||||||
|
// secondary is the GCSE year group alone.
|
||||||
|
const pupils = census?.total_pupils ?? schoolInfo.total_pupils ?? null;
|
||||||
|
const facts = [
|
||||||
|
formatAgeRange(schoolInfo.age_range),
|
||||||
|
schoolTypeLabel(schoolInfo),
|
||||||
|
pupils != null ? `${pupils.toLocaleString()} pupils` : null,
|
||||||
|
].filter((fact): fact is string => !!fact);
|
||||||
|
const flags = schoolFlags(schoolInfo);
|
||||||
|
// The council, unless the address already names it.
|
||||||
|
const council = schoolInfo.local_authority
|
||||||
|
&& !(schoolInfo.address ?? '').toLowerCase().includes(schoolInfo.local_authority.toLowerCase())
|
||||||
|
? schoolInfo.local_authority
|
||||||
|
: null;
|
||||||
|
// A single-academy trust carries the school's own name, which says nothing.
|
||||||
|
const trust = schoolInfo.trust_name && !sameName(schoolInfo.trust_name, schoolInfo.school_name)
|
||||||
|
? schoolInfo.trust_name
|
||||||
|
: null;
|
||||||
|
|
||||||
const handleComparisonToggle = () => {
|
const handleComparisonToggle = () => {
|
||||||
if (isInComparison) {
|
if (isInComparison) {
|
||||||
@@ -202,27 +228,31 @@ export function SchoolDetailShell({
|
|||||||
<div className={styles.headerContent}>
|
<div className={styles.headerContent}>
|
||||||
<div className={styles.titleSection}>
|
<div className={styles.titleSection}>
|
||||||
<h1 className={styles.schoolName}>{schoolInfo.school_name}</h1>
|
<h1 className={styles.schoolName}>{schoolInfo.school_name}</h1>
|
||||||
<div className={styles.meta}>
|
{(phasePill.label || facts.length > 0) && (
|
||||||
{schoolInfo.local_authority && (
|
<div className={styles.facts}>
|
||||||
<span className={styles.metaItem}>{schoolInfo.local_authority}</span>
|
{phasePill.label && (
|
||||||
)}
|
<span className={`${styles.phasePill} ${styles[`phasePill${phasePill.key}`]}`}>
|
||||||
{schoolInfo.school_type && (
|
{phasePill.label}
|
||||||
<span className={styles.metaItem}>{schoolInfo.school_type}</span>
|
</span>
|
||||||
)}
|
|
||||||
{isAllThrough && (
|
|
||||||
<span className={styles.metaItem}>All-through (primary & secondary)</span>
|
|
||||||
)}
|
|
||||||
{singleSex && <span className={styles.metaItem}>{singleSex}</span>}
|
|
||||||
{schoolInfo.age_range && (
|
|
||||||
<span className={styles.metaItem}>{formatAgeRange(schoolInfo.age_range)}</span>
|
|
||||||
)}
|
|
||||||
{hasNurseryClasses(schoolInfo.nursery_provision) && (
|
|
||||||
<span className={styles.metaItem}>Nursery</span>
|
|
||||||
)}
|
|
||||||
{schoolInfo.has_sixth_form && (
|
|
||||||
<span className={styles.metaItem}>Sixth form</span>
|
|
||||||
)}
|
)}
|
||||||
|
{facts.map((fact) => (
|
||||||
|
<span key={fact} className={styles.fact}>{fact}</span>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
{flags.length > 0 && (
|
||||||
|
// role="list": list-style: none drops list semantics in Safari.
|
||||||
|
<ul role="list" className={styles.flags} aria-label="Admission and provision">
|
||||||
|
{flags.map((flag) => (
|
||||||
|
<li
|
||||||
|
key={flag.label}
|
||||||
|
className={flag.kind === 'condition' ? styles.flagCondition : styles.flagProvision}
|
||||||
|
>
|
||||||
|
{flag.label}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
{isProposedToClose(schoolInfo) && (
|
{isProposedToClose(schoolInfo) && (
|
||||||
<div className={styles.closingStrip} role="note">
|
<div className={styles.closingStrip} role="note">
|
||||||
<strong>⚠ Proposed to close.</strong> Check with the local authority before
|
<strong>⚠ Proposed to close.</strong> Check with the local authority before
|
||||||
@@ -232,6 +262,7 @@ export function SchoolDetailShell({
|
|||||||
{schoolInfo.address && (
|
{schoolInfo.address && (
|
||||||
<p className={styles.address}>
|
<p className={styles.address}>
|
||||||
{schoolInfo.address}{schoolInfo.postcode && `, ${schoolInfo.postcode}`}
|
{schoolInfo.address}{schoolInfo.postcode && `, ${schoolInfo.postcode}`}
|
||||||
|
{council && ` · ${council}`}
|
||||||
{hasLocation && (
|
{hasLocation && (
|
||||||
<>
|
<>
|
||||||
{' · '}
|
{' · '}
|
||||||
@@ -278,23 +309,6 @@ export function SchoolDetailShell({
|
|||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{(() => {
|
|
||||||
// Never latestResults.total_pupils: that is the results
|
|
||||||
// cohort, which for a secondary is the GCSE year group alone.
|
|
||||||
const total = census?.total_pupils ?? schoolInfo.total_pupils ?? null;
|
|
||||||
if (total == null) return null;
|
|
||||||
return (
|
|
||||||
<span className={styles.headerDetail}>
|
|
||||||
<strong>Pupils:</strong> {total.toLocaleString()}
|
|
||||||
{schoolInfo.capacity != null && ` (capacity: ${schoolInfo.capacity})`}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
{schoolInfo.trust_name && (
|
|
||||||
<span className={styles.headerDetail}>
|
|
||||||
Part of <strong>{schoolInfo.trust_name}</strong>
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{schoolInfo.telephone && (
|
{schoolInfo.telephone && (
|
||||||
<span className={styles.headerDetail}>
|
<span className={styles.headerDetail}>
|
||||||
<strong>Phone:</strong>{' '}
|
<strong>Phone:</strong>{' '}
|
||||||
@@ -303,22 +317,14 @@ export function SchoolDetailShell({
|
|||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{schoolInfo.religious_denomination && (
|
{trust && (
|
||||||
<span className={styles.headerDetail}>
|
<span className={styles.headerDetail}>
|
||||||
<strong>Religious character:</strong>{' '}
|
<strong>Academy trust:</strong> {trust}
|
||||||
{['Does not apply', 'None'].includes(schoolInfo.religious_denomination)
|
|
||||||
? 'None'
|
|
||||||
: schoolInfo.religious_denomination}
|
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{schoolInfo.county && (
|
{schoolInfo.capacity != null && (
|
||||||
<span className={styles.headerDetail}>
|
<span className={styles.headerDetail}>
|
||||||
<strong>County:</strong> {schoolInfo.county}
|
<strong>Capacity:</strong> {schoolInfo.capacity.toLocaleString()}
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{schoolInfo.parliamentary_constituency && (
|
|
||||||
<span className={styles.headerDetail}>
|
|
||||||
<strong>Constituency:</strong> {schoolInfo.parliamentary_constituency}
|
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { School, SchoolAdmissions, SchoolAdmissionDistance } from '@/lib/types';
|
import type { School, SchoolAdmissions, SchoolAdmissionDistance } from '@/lib/types';
|
||||||
import { formatPercentage } from '@/lib/utils';
|
import { formatPercentage, hasReligiousCharacter, isSelective } from '@/lib/utils';
|
||||||
import { Section, sectionStyles as styles } from './sectionShared';
|
import { Section, sectionStyles as styles } from './sectionShared';
|
||||||
import {
|
import {
|
||||||
describeCutoff, describeCutoffAbsence,
|
describeCutoff, describeCutoffAbsence,
|
||||||
@@ -33,10 +33,8 @@ export function SecondaryAdmissionsSection({
|
|||||||
const featureOn = admissionDistance !== undefined;
|
const featureOn = admissionDistance !== undefined;
|
||||||
// Moved with this section from SecondarySchoolDetailView, its only consumer.
|
// Moved with this section from SecondarySchoolDetailView, its only consumer.
|
||||||
const admissionsTag = (() => {
|
const admissionsTag = (() => {
|
||||||
const policy = schoolInfo.admissions_policy?.toLowerCase() ?? '';
|
if (isSelective(schoolInfo.admissions_policy)) return 'Selective';
|
||||||
if (policy.includes('selective')) return 'Selective';
|
if (hasReligiousCharacter(schoolInfo.religious_denomination)) return 'Faith priority';
|
||||||
const denom = schoolInfo.religious_denomination ?? '';
|
|
||||||
if (denom && denom !== 'Does not apply') return 'Faith priority';
|
|
||||||
return null;
|
return null;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -148,8 +148,6 @@ export function SecondarySchoolSections({
|
|||||||
{/* Last: it is where the reader goes next, not part of this school. */}
|
{/* Last: it is where the reader goes next, not part of this school. */}
|
||||||
<NearbySchoolsSection
|
<NearbySchoolsSection
|
||||||
urn={schoolInfo.urn}
|
urn={schoolInfo.urn}
|
||||||
schoolName={schoolInfo.school_name}
|
|
||||||
phase={schoolInfo.phase}
|
|
||||||
thisMetricValue={flags.latestResults?.attainment_8_score ?? null}
|
thisMetricValue={flags.latestResults?.attainment_8_score ?? null}
|
||||||
nearby={nearbySchools}
|
nearby={nearbySchools}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { SchoolAdmissionDistance } from '@/lib/types';
|
import type { SchoolAdmissionDistance } from '@/lib/types';
|
||||||
import { formatCutoffDistance, formatMiles, formatEntryYear } from '@/lib/utils';
|
import { formatCutoffDistance, formatMiles, formatEntryYear, isSelective } from '@/lib/utils';
|
||||||
|
|
||||||
export interface CutoffDisplay {
|
export interface CutoffDisplay {
|
||||||
/** Headline figure, e.g. "0.31 miles". */
|
/** Headline figure, e.g. "0.31 miles". */
|
||||||
@@ -193,8 +193,7 @@ export function describeCutoffAbsence({
|
|||||||
admissionsPolicy,
|
admissionsPolicy,
|
||||||
admissionsHistory = [],
|
admissionsHistory = [],
|
||||||
}: AbsenceInput): string {
|
}: AbsenceInput): string {
|
||||||
const policy = (admissionsPolicy ?? '').toLowerCase();
|
if (isSelective(admissionsPolicy)) {
|
||||||
if (policy.includes('selective')) {
|
|
||||||
return 'Places at this school are ranked by the entrance test rather than by '
|
return 'Places at this school are ranked by the entrance test rather than by '
|
||||||
+ 'distance, so no cut-off distance applies.';
|
+ 'distance, so no cut-off distance applies.';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* The facts the school header and the search rows print, so a parent reads
|
||||||
|
* the same words in the list and on the page.
|
||||||
|
*
|
||||||
|
* Every value comes from one register field. Nothing is inferred or explained
|
||||||
|
* inline, and a missing field prints nothing.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { School } from './types';
|
||||||
|
import { hasNurseryClasses, hasReligiousCharacter, isSelective, singleSexLabel } from './utils';
|
||||||
|
|
||||||
|
/** The search filter's type groups (backend/school_groups.py), without its
|
||||||
|
* parenthesised notes: fees have a flag of their own. */
|
||||||
|
const TYPE_GROUP_LABELS: Record<string, string> = {
|
||||||
|
state: 'State school',
|
||||||
|
independent: 'Independent school',
|
||||||
|
special: 'Special school (SEND)',
|
||||||
|
post16: 'Sixth form or college',
|
||||||
|
alternative: 'Alternative provision',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** The school's type in the search filter's terms, or the register's own name
|
||||||
|
* for a type in no group (secure units, online providers). */
|
||||||
|
export function schoolTypeLabel(school: Pick<School, 'type_group' | 'school_type'>): string | null {
|
||||||
|
const grouped = school.type_group ? TYPE_GROUP_LABELS[school.type_group] : undefined;
|
||||||
|
return grouped ?? (school.school_type?.trim() || null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "condition": changes who can apply or what it costs.
|
||||||
|
* "provision": what the school offers. */
|
||||||
|
export type SchoolFlagKind = 'condition' | 'provision';
|
||||||
|
|
||||||
|
export interface SchoolFlag {
|
||||||
|
label: string;
|
||||||
|
kind: SchoolFlagKind;
|
||||||
|
}
|
||||||
|
|
||||||
|
type FlagFields = Pick<
|
||||||
|
School,
|
||||||
|
'type_group' | 'admissions_policy' | 'gender' | 'religious_denomination'
|
||||||
|
| 'nursery_provision' | 'has_sixth_form' | 'phase'
|
||||||
|
>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flags for what applies, in a fixed order: conditions first, then provision.
|
||||||
|
*
|
||||||
|
* Selective needs the exact value. The register files a partly selective
|
||||||
|
* school as "Non-selective", so that value is never printed.
|
||||||
|
*/
|
||||||
|
export function schoolFlags(school: FlagFields): SchoolFlag[] {
|
||||||
|
const flags: SchoolFlag[] = [];
|
||||||
|
const condition = (label: string) => flags.push({ label, kind: 'condition' });
|
||||||
|
const provision = (label: string) => flags.push({ label, kind: 'provision' });
|
||||||
|
const phase = school.phase?.trim().toLowerCase();
|
||||||
|
|
||||||
|
if (school.type_group === 'independent') condition('Fee-paying');
|
||||||
|
if (isSelective(school.admissions_policy)) condition('Selective');
|
||||||
|
const singleSex = singleSexLabel(school.gender);
|
||||||
|
if (singleSex) condition(singleSex);
|
||||||
|
if (hasReligiousCharacter(school.religious_denomination)) {
|
||||||
|
condition(school.religious_denomination!.trim());
|
||||||
|
}
|
||||||
|
if (hasNurseryClasses(school.nursery_provision) && phase !== 'nursery') provision('Nursery class');
|
||||||
|
if (school.has_sixth_form && phase !== '16 plus') provision('Sixth form');
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
@@ -17,6 +17,8 @@ export interface School {
|
|||||||
local_authority_code: number | null;
|
local_authority_code: number | null;
|
||||||
school_type: string | null;
|
school_type: string | null;
|
||||||
school_type_code: string | null;
|
school_type_code: string | null;
|
||||||
|
/** Search-filter type group ("state", "independent"…), null for a type in none. */
|
||||||
|
type_group?: string | null;
|
||||||
religious_denomination: string | null;
|
religious_denomination: string | null;
|
||||||
age_range: string | null;
|
age_range: string | null;
|
||||||
has_sixth_form?: boolean | null;
|
has_sixth_form?: boolean | null;
|
||||||
|
|||||||
+13
-3
@@ -923,12 +923,22 @@ export function isSpecialSchool(school: { school_type?: string | null }): boolea
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether GIAS records a religious character. "None" and "Does not apply" are
|
* Whether GIAS records a religious character. "None", "Does not apply" and
|
||||||
* the register's two ways of saying it has none, and neither is a faith.
|
* "Not applicable" are the register's ways of saying it has none; the place
|
||||||
|
* table (PlaceView's NO_FAITH) reads the same three.
|
||||||
*/
|
*/
|
||||||
export function hasReligiousCharacter(value: string | null | undefined): boolean {
|
export function hasReligiousCharacter(value: string | null | undefined): boolean {
|
||||||
const v = value?.trim().toLowerCase() ?? '';
|
const v = value?.trim().toLowerCase() ?? '';
|
||||||
return v !== '' && v !== 'none' && v !== 'does not apply';
|
return v !== '' && v !== 'none' && v !== 'does not apply' && v !== 'not applicable';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether GIAS records the school as selective. Exact: "Non-selective"
|
||||||
|
* contains "selective", so a substring test read every comprehensive as
|
||||||
|
* selective. (The register files a partly selective school as non-selective.)
|
||||||
|
*/
|
||||||
|
export function isSelective(admissionsPolicy: string | null | undefined): boolean {
|
||||||
|
return admissionsPolicy?.trim().toLowerCase() === 'selective';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -106,9 +106,12 @@ print(f'Validation passed: {{count}} GIAS rows')
|
|||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Marts fed by annual EES staging models are rebuilt by the EES DAG, even
|
||||||
|
# when they join dim_school. Selecting them here fails in any database
|
||||||
|
# where that DAG hasn't run (pipeline/tests/test_dag_selectors.py).
|
||||||
dbt_build = BashOperator(
|
dbt_build = BashOperator(
|
||||||
task_id="dbt_build",
|
task_id="dbt_build",
|
||||||
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_gias_establishments+ stg_gias_links+ gias_code_names+ --exclude int_ks2_with_lineage+ int_ks4_with_lineage+",
|
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_gias_establishments+ stg_gias_links+ gias_code_names+ --exclude int_ks2_with_lineage+ int_ks4_with_lineage+ stg_ees_ks4_destinations+ stg_ees_ks5_destinations+",
|
||||||
)
|
)
|
||||||
|
|
||||||
sync_typesense = BashOperator(
|
sync_typesense = BashOperator(
|
||||||
@@ -143,7 +146,7 @@ with DAG(
|
|||||||
|
|
||||||
dbt_build_ofsted = BashOperator(
|
dbt_build_ofsted = BashOperator(
|
||||||
task_id="dbt_build",
|
task_id="dbt_build",
|
||||||
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_ofsted_inspections+ int_ofsted_latest+ fact_ofsted_inspection+ dim_school+",
|
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_ofsted_inspections+ int_ofsted_latest+ fact_ofsted_inspection+ dim_school+ --exclude stg_ees_ks4_destinations+ stg_ees_ks5_destinations+",
|
||||||
)
|
)
|
||||||
|
|
||||||
sync_typesense_ofsted = BashOperator(
|
sync_typesense_ofsted = BashOperator(
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
"""Read a GIAS extract from the raw bytes of the download.
|
||||||
|
|
||||||
|
GIAS writes its CSVs in Windows-1252 and sends no charset, so `resp.text`
|
||||||
|
leaves requests to guess the codec. On 3 Oct 2026 it guessed windows-1250 and
|
||||||
|
"à" became "ŕ". Decode the bytes ourselves instead.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
GIAS_ENCODING = "cp1252"
|
||||||
|
|
||||||
|
|
||||||
|
def read_gias_csv(content: bytes, logger=None) -> pd.DataFrame:
|
||||||
|
"""Every column as a string; a blank cell stays ''."""
|
||||||
|
# Windows-1252 leaves five bytes undefined. One stray byte must not stop
|
||||||
|
# the daily refresh of every school, so it becomes U+FFFD and is logged.
|
||||||
|
text = content.decode(GIAS_ENCODING, errors="replace")
|
||||||
|
undecodable = text.count("�")
|
||||||
|
if undecodable and logger is not None:
|
||||||
|
logger.warning("%d byte(s) in the GIAS extract could not be decoded as %s",
|
||||||
|
undecodable, GIAS_ENCODING)
|
||||||
|
return pd.read_csv(io.StringIO(text), dtype=str, keep_default_na=False)
|
||||||
@@ -7,6 +7,8 @@ from datetime import date, timedelta
|
|||||||
from singer_sdk import Stream, Tap
|
from singer_sdk import Stream, Tap
|
||||||
from singer_sdk import typing as th
|
from singer_sdk import typing as th
|
||||||
|
|
||||||
|
from tap_uk_gias.gias_csv import read_gias_csv
|
||||||
|
|
||||||
GIAS_URL_TEMPLATE = (
|
GIAS_URL_TEMPLATE = (
|
||||||
"https://ea-edubase-api-prod.azurewebsites.net"
|
"https://ea-edubase-api-prod.azurewebsites.net"
|
||||||
"/edubase/downloads/public/edubasealldata{date}.csv"
|
"/edubase/downloads/public/edubasealldata{date}.csv"
|
||||||
@@ -74,9 +76,6 @@ class GIASEstablishmentsStream(Stream):
|
|||||||
|
|
||||||
def get_records(self, context):
|
def get_records(self, context):
|
||||||
"""Download GIAS CSV and yield rows."""
|
"""Download GIAS CSV and yield rows."""
|
||||||
import io
|
|
||||||
|
|
||||||
import pandas as pd
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
today = date.today()
|
today = date.today()
|
||||||
@@ -94,12 +93,7 @@ class GIASEstablishmentsStream(Stream):
|
|||||||
|
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
df = pd.read_csv(
|
df = read_gias_csv(resp.content, self.logger)
|
||||||
io.StringIO(resp.text),
|
|
||||||
encoding="latin-1",
|
|
||||||
dtype=str,
|
|
||||||
keep_default_na=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
record = row.to_dict()
|
record = row.to_dict()
|
||||||
@@ -126,9 +120,6 @@ class GIASLinksStream(Stream):
|
|||||||
|
|
||||||
def get_records(self, context):
|
def get_records(self, context):
|
||||||
"""Download GIAS links CSV and yield rows."""
|
"""Download GIAS links CSV and yield rows."""
|
||||||
import io
|
|
||||||
|
|
||||||
import pandas as pd
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
today = date.today()
|
today = date.today()
|
||||||
@@ -146,12 +137,7 @@ class GIASLinksStream(Stream):
|
|||||||
|
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
df = pd.read_csv(
|
df = read_gias_csv(resp.content, self.logger)
|
||||||
io.StringIO(resp.text),
|
|
||||||
encoding="latin-1",
|
|
||||||
dtype=str,
|
|
||||||
keep_default_na=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
record = row.to_dict()
|
record = row.to_dict()
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
"""Every scheduled dbt build must only build models whose parents exist.
|
||||||
|
|
||||||
|
The daily GIAS build selects `stg_gias_establishments+`, so any mart that joins
|
||||||
|
dim_school joins the daily build too. When such a mart also reads a staging
|
||||||
|
model that only the manually triggered EES DAG builds, the daily build fails in
|
||||||
|
any database where that DAG has not run since. Sync and cache invalidation then
|
||||||
|
never run either. The destinations marts did this from late August 2026.
|
||||||
|
|
||||||
|
The graph is read from the model SQL, because CI has no dbt.
|
||||||
|
"""
|
||||||
|
import re
|
||||||
|
from collections import defaultdict
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
PIPELINE = Path(__file__).resolve().parents[1]
|
||||||
|
MODELS = PIPELINE / 'transform' / 'models'
|
||||||
|
DAG_FILE = PIPELINE / 'dags' / 'school_data_pipeline.py'
|
||||||
|
|
||||||
|
REF = re.compile(r"ref\(\s*'([a-z0-9_]+)'\s*\)")
|
||||||
|
DBT_BUILD = re.compile(r'dbt_build\w*\s*=\s*BashOperator\(.*?build --profiles-dir \. --target production ([^"]+)"', re.S)
|
||||||
|
DAG_ID = re.compile(r'dag_id="([a-z0-9_]+)"')
|
||||||
|
|
||||||
|
DAILY = 'school_data_daily'
|
||||||
|
|
||||||
|
# dim_school reads int_ofsted_latest only when the relation exists
|
||||||
|
# (adapter.get_relation), so a missing table is not a failure.
|
||||||
|
OPTIONAL_PARENTS = {'int_ofsted_latest'}
|
||||||
|
|
||||||
|
|
||||||
|
def model_parents():
|
||||||
|
"""{model: models it refs}. Seeds are left out: they are loaded once and always exist."""
|
||||||
|
sql = {p.stem: p.read_text() for p in MODELS.rglob('*.sql')}
|
||||||
|
return {name: set(REF.findall(text)) & set(sql) for name, text in sql.items()}
|
||||||
|
|
||||||
|
|
||||||
|
def downstream(node, children):
|
||||||
|
seen, stack = {node}, [node]
|
||||||
|
while stack:
|
||||||
|
for child in children[stack.pop()]:
|
||||||
|
if child not in seen:
|
||||||
|
seen.add(child)
|
||||||
|
stack.append(child)
|
||||||
|
return seen
|
||||||
|
|
||||||
|
|
||||||
|
def expand(tokens, children):
|
||||||
|
out = set()
|
||||||
|
for token in tokens:
|
||||||
|
out |= downstream(token[:-1], children) if token.endswith('+') else {token}
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def scheduled_builds():
|
||||||
|
"""{dag_id: dbt selection arguments} for every dbt build in the DAG file."""
|
||||||
|
text = DAG_FILE.read_text()
|
||||||
|
starts = [(m.start(), m.group(1)) for m in DAG_ID.finditer(text)]
|
||||||
|
builds = {}
|
||||||
|
for i, (start, dag_id) in enumerate(starts):
|
||||||
|
end = starts[i + 1][0] if i + 1 < len(starts) else len(text)
|
||||||
|
found = DBT_BUILD.search(text, start, end)
|
||||||
|
if found:
|
||||||
|
builds[dag_id] = found.group(1)
|
||||||
|
return builds
|
||||||
|
|
||||||
|
|
||||||
|
def selected_models(args, parents):
|
||||||
|
children = defaultdict(set)
|
||||||
|
for model, ps in parents.items():
|
||||||
|
for p in ps:
|
||||||
|
children[p].add(model)
|
||||||
|
select = re.search(r'--select (.+?)(?= --exclude|$)', args).group(1).split()
|
||||||
|
excluded = re.search(r'--exclude (.+)$', args)
|
||||||
|
exclude = excluded.group(1).split() if excluded else []
|
||||||
|
return (expand(select, children) - expand(exclude, children)) & set(parents)
|
||||||
|
|
||||||
|
|
||||||
|
PARENTS = model_parents()
|
||||||
|
BUILDS = scheduled_builds()
|
||||||
|
DAILY_MODELS = selected_models(BUILDS[DAILY], PARENTS)
|
||||||
|
|
||||||
|
|
||||||
|
def test_every_dag_with_a_dbt_build_is_parsed():
|
||||||
|
assert set(BUILDS) == {
|
||||||
|
'school_data_daily', 'school_data_monthly_ofsted', 'school_data_annual_ees',
|
||||||
|
'school_data_annual_idaci', 'school_data_annual_distance',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('dag_id', sorted(BUILDS))
|
||||||
|
def test_selected_models_only_read_models_that_exist(dag_id):
|
||||||
|
selected = selected_models(BUILDS[dag_id], PARENTS)
|
||||||
|
# The daily build is the base layer: other DAGs may rely on what it builds.
|
||||||
|
available = selected | OPTIONAL_PARENTS | (DAILY_MODELS if dag_id != DAILY else set())
|
||||||
|
missing = {model: sorted(PARENTS[model] - available) for model in sorted(selected)
|
||||||
|
if PARENTS[model] - available}
|
||||||
|
assert missing == {}, f'{dag_id} builds models whose parents it never builds: {missing}'
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
"""GIAS publishes its extracts in Windows-1252 and declares no charset.
|
||||||
|
|
||||||
|
The tap used to hand pandas `resp.text`, so requests guessed the codec.
|
||||||
|
On 3 Oct 2026 it guessed windows-1250, and "St Thomas à Becket" was stored
|
||||||
|
as "St Thomas ŕ Becket". The `encoding=` passed to read_csv did nothing,
|
||||||
|
because the text was already decoded.
|
||||||
|
"""
|
||||||
|
import importlib.util
|
||||||
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
MODULE = (Path(__file__).resolve().parents[1] / 'plugins' / 'extractors' / 'tap-uk-gias'
|
||||||
|
/ 'tap_uk_gias' / 'gias_csv.py')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def gias_csv():
|
||||||
|
spec = importlib.util.spec_from_file_location('gias_csv', MODULE)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
# Byte for byte as GIAS writes it: 0xE0 à, 0x92 ’, 0xE9 é, 0xB0 °, 0xE7 ç.
|
||||||
|
EXTRACT = (
|
||||||
|
b'"URN","EstablishmentName","HeadLastName"\r\n'
|
||||||
|
b'"138950","St Thomas \xe0 Becket Catholic Secondary School","Smith"\r\n'
|
||||||
|
b'"100000","The Dean and Chapter of St Paul\x92s Cathedral","Pr\xe9vert"\r\n'
|
||||||
|
b'"140677","North Star 180\xb0","Fran\xe7ois"\r\n'
|
||||||
|
b'"100001","No head recorded",""\r\n'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_names_decode_as_windows_1252(gias_csv):
|
||||||
|
df = gias_csv.read_gias_csv(EXTRACT)
|
||||||
|
assert list(df['EstablishmentName']) == [
|
||||||
|
'St Thomas à Becket Catholic Secondary School',
|
||||||
|
'The Dean and Chapter of St Paul’s Cathedral',
|
||||||
|
'North Star 180°',
|
||||||
|
'No head recorded',
|
||||||
|
]
|
||||||
|
assert list(df['HeadLastName']) == ['Smith', 'Prévert', 'François', '']
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_codec_requests_guessed_is_not_used(gias_csv):
|
||||||
|
# What the tap stored on 3 Oct: the same bytes read as windows-1250.
|
||||||
|
assert 'ŕ' in EXTRACT.decode('cp1250')
|
||||||
|
names = ' '.join(gias_csv.read_gias_csv(EXTRACT)['EstablishmentName'])
|
||||||
|
assert 'ŕ' not in names
|
||||||
|
|
||||||
|
|
||||||
|
def test_values_stay_strings(gias_csv):
|
||||||
|
df = gias_csv.read_gias_csv(EXTRACT)
|
||||||
|
assert df.loc[0, 'URN'] == '138950'
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_byte_windows_1252_leaves_undefined_does_not_stop_the_load(gias_csv, caplog):
|
||||||
|
# 0x81 has no Windows-1252 character. One odd name must not block the daily
|
||||||
|
# refresh of every school, but it must be visible in the log.
|
||||||
|
extract = b'"URN","EstablishmentName"\r\n"100002","Odd \x81 Name"\r\n'
|
||||||
|
with caplog.at_level(logging.WARNING):
|
||||||
|
df = gias_csv.read_gias_csv(extract, logger=logging.getLogger('gias'))
|
||||||
|
assert df.loc[0, 'EstablishmentName'] == 'Odd � Name'
|
||||||
|
assert 'could not be decoded' in caplog.text
|
||||||
@@ -1,18 +1,91 @@
|
|||||||
-- Intermediate model: Latest Ofsted inspection per URN
|
-- Intermediate model: the current Ofsted status per URN
|
||||||
-- Picks the most recent inspection for each school
|
-- One row per school: its latest visit (report card, graded or ungraded
|
||||||
|
-- inspection) and the overall grade still in force, if any. A grade is dated
|
||||||
|
-- by the inspection that awarded or confirmed it, never by a later visit.
|
||||||
|
-- Rule and examples: docs/superpowers/specs/2026-10-05-ofsted-current-status-design.md
|
||||||
|
|
||||||
with ranked as (
|
with inspections as (
|
||||||
select
|
select
|
||||||
*,
|
*,
|
||||||
|
-- The newest of the three inspections, read from the dates. (Report
|
||||||
|
-- cards began in Nov 2025, after the last legacy inspections, so today
|
||||||
|
-- a report card is always the latest; nothing below relies on that.)
|
||||||
|
greatest(rc_inspection_date, graded_inspection_date, ungraded_inspection_date)
|
||||||
|
as latest_visit_date
|
||||||
|
from {{ ref('stg_ofsted_inspections') }}
|
||||||
|
),
|
||||||
|
|
||||||
|
ranked as (
|
||||||
|
select
|
||||||
|
*,
|
||||||
|
-- Monthly loads can leave several rows per school. The newest visit
|
||||||
|
-- wins; the tie-breaks keep the choice deterministic.
|
||||||
row_number() over (
|
row_number() over (
|
||||||
partition by urn
|
partition by urn
|
||||||
order by inspection_date desc
|
order by latest_visit_date desc,
|
||||||
|
rc_inspection_date desc nulls last,
|
||||||
|
graded_inspection_date desc nulls last,
|
||||||
|
ungraded_inspection_date desc nulls last
|
||||||
) as rn
|
) as rn
|
||||||
from {{ ref('stg_ofsted_inspections') }}
|
from inspections
|
||||||
|
),
|
||||||
|
|
||||||
|
latest as (
|
||||||
|
select
|
||||||
|
*,
|
||||||
|
-- Same-day ties resolve report card, then graded, then ungraded.
|
||||||
|
case
|
||||||
|
when rc_inspection_date = latest_visit_date then 'report_card'
|
||||||
|
when graded_inspection_date = latest_visit_date then 'graded'
|
||||||
|
else 'ungraded'
|
||||||
|
end as latest_visit_kind
|
||||||
|
from ranked
|
||||||
|
where rn = 1
|
||||||
|
),
|
||||||
|
|
||||||
|
graded as (
|
||||||
|
select
|
||||||
|
*,
|
||||||
|
-- The grade still in force. A report card replaced overall grades, so
|
||||||
|
-- none survives it. Otherwise: a graded inspection's own overall grade
|
||||||
|
-- (1-4; "Not judged" and the sentinel 9 are no grade); else an
|
||||||
|
-- ungraded visit's "School remains X"; else, after an ungraded visit
|
||||||
|
-- that names no grade, the graded inspection's grade.
|
||||||
|
case
|
||||||
|
when rc_inspection_date is not null
|
||||||
|
then null
|
||||||
|
when latest_visit_kind = 'graded' and overall_effectiveness between 1 and 4
|
||||||
|
then 'graded_latest'
|
||||||
|
when latest_visit_kind = 'ungraded' and ungraded_grade is not null
|
||||||
|
then 'confirmed'
|
||||||
|
when latest_visit_kind = 'ungraded' and overall_effectiveness between 1 and 4
|
||||||
|
then 'graded_earlier'
|
||||||
|
end as grade_case
|
||||||
|
from latest
|
||||||
)
|
)
|
||||||
|
|
||||||
select
|
select
|
||||||
urn,
|
urn,
|
||||||
|
latest_visit_date,
|
||||||
|
latest_visit_kind,
|
||||||
|
case when latest_visit_kind = 'ungraded' then ungraded_outcome end as latest_visit_outcome,
|
||||||
|
case grade_case
|
||||||
|
when 'confirmed' then ungraded_grade
|
||||||
|
when 'graded_latest' then overall_effectiveness
|
||||||
|
when 'graded_earlier' then overall_effectiveness
|
||||||
|
end as current_grade,
|
||||||
|
case grade_case
|
||||||
|
when 'confirmed' then ungraded_inspection_date
|
||||||
|
when 'graded_latest' then graded_inspection_date
|
||||||
|
when 'graded_earlier' then graded_inspection_date
|
||||||
|
end as current_grade_date,
|
||||||
|
case grade_case
|
||||||
|
when 'confirmed' then 'confirmed'
|
||||||
|
when 'graded_latest' then 'graded'
|
||||||
|
when 'graded_earlier' then 'graded'
|
||||||
|
end as current_grade_basis,
|
||||||
|
graded_inspection_date,
|
||||||
|
ungraded_inspection_date,
|
||||||
inspection_date,
|
inspection_date,
|
||||||
inspection_type,
|
inspection_type,
|
||||||
framework,
|
framework,
|
||||||
@@ -36,5 +109,4 @@ select
|
|||||||
rc_sixth_form,
|
rc_sixth_form,
|
||||||
rc_inspection_date,
|
rc_inspection_date,
|
||||||
report_url
|
report_url
|
||||||
from ranked
|
from graded
|
||||||
where rn = 1
|
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
unit_tests:
|
||||||
|
- name: graded_not_judged_has_no_grade
|
||||||
|
description: Rabbsfarm (102408). The 2025 inspection gave no overall grade, so the 2020 "remains Good" is not carried forward (audit C1).
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 102408, graded_inspection_date: '2025-06-17', ungraded_inspection_date: '2020-02-06', overall_effectiveness: null, ungraded_grade: 2, ungraded_outcome: 'School remains Good'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 102408, latest_visit_date: '2025-06-17', latest_visit_kind: graded, latest_visit_outcome: null, current_grade: null, current_grade_date: null, current_grade_basis: null}
|
||||||
|
|
||||||
|
- name: graded_with_overall_grade
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 1, graded_inspection_date: '2019-06-01', overall_effectiveness: 2}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 1, latest_visit_date: '2019-06-01', latest_visit_kind: graded, current_grade: 2, current_grade_date: '2019-06-01', current_grade_basis: graded}
|
||||||
|
|
||||||
|
- name: ungraded_remains_good_confirms_the_grade
|
||||||
|
description: Robins Lane (104762). Graded Good 2020, "School remains Good" July 2024 — Good, dated by the confirming visit.
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 104762, graded_inspection_date: '2020-01-07', ungraded_inspection_date: '2024-07-18', overall_effectiveness: 2, ungraded_grade: 2, ungraded_outcome: 'School remains Good'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 104762, latest_visit_date: '2024-07-18', latest_visit_kind: ungraded, latest_visit_outcome: 'School remains Good', current_grade: 2, current_grade_date: '2024-07-18', current_grade_basis: confirmed}
|
||||||
|
|
||||||
|
- name: post_2024_ungraded_keeps_graded_grade_with_its_own_date
|
||||||
|
description: Washwood Heath (139888). Graded Good 2020, "Standards maintained" May 2025 — Good, dated 2020; latest visit May 2025 (audit M1).
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 139888, graded_inspection_date: '2020-03-03', ungraded_inspection_date: '2025-05-21', overall_effectiveness: 2, ungraded_grade: null, ungraded_outcome: 'Standards maintained'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 139888, latest_visit_date: '2025-05-21', latest_visit_kind: ungraded, latest_visit_outcome: 'Standards maintained', current_grade: 2, current_grade_date: '2020-03-03', current_grade_basis: graded}
|
||||||
|
|
||||||
|
- name: ungraded_only_standards_maintained
|
||||||
|
description: Oakgrove (136454). Only an ungraded visit, outcome names no grade.
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 136454, ungraded_inspection_date: '2024-11-13', ungraded_grade: null, ungraded_outcome: 'Standards maintained'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 136454, latest_visit_date: '2024-11-13', latest_visit_kind: ungraded, latest_visit_outcome: 'Standards maintained', current_grade: null, current_grade_date: null, current_grade_basis: null}
|
||||||
|
|
||||||
|
- name: report_card_wins
|
||||||
|
description: The Willink School (110048). A report card is the latest visit and no legacy grade stays in force.
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 110048, ungraded_inspection_date: '2023-10-05', ungraded_grade: 2, ungraded_outcome: 'School remains Good', rc_inspection_date: '2026-05-06', rc_inclusion: 3}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 110048, latest_visit_date: '2026-05-06', latest_visit_kind: report_card, latest_visit_outcome: null, current_grade: null, current_grade_date: null, current_grade_basis: null}
|
||||||
|
|
||||||
|
- name: duplicate_rows_newer_report_card_wins
|
||||||
|
description: Monthly loads can leave an older row beside a newer one for the same graded date; the row with the report card must win (audit H3).
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 138186, graded_inspection_date: '2023-06-13', overall_effectiveness: 3}
|
||||||
|
- {urn: 138186, graded_inspection_date: '2023-06-13', overall_effectiveness: 3, rc_inspection_date: '2026-06-02', rc_inclusion: 3}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 138186, latest_visit_date: '2026-06-02', latest_visit_kind: report_card, current_grade: null}
|
||||||
|
|
||||||
|
- name: same_day_graded_wins
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 2, graded_inspection_date: '2024-03-01', ungraded_inspection_date: '2024-03-01', overall_effectiveness: 1, ungraded_grade: 2, ungraded_outcome: 'School remains Good'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 2, latest_visit_kind: graded, current_grade: 1, current_grade_basis: graded}
|
||||||
|
|
||||||
|
- name: overall_sentinel_is_not_a_grade
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 3, graded_inspection_date: '2018-05-01', overall_effectiveness: 9}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 3, latest_visit_kind: graded, current_grade: null}
|
||||||
|
|
||||||
|
- name: newer_legacy_visit_after_a_report_card
|
||||||
|
description: >
|
||||||
|
Not in Ofsted's data today (0 of 2,451 report-card schools in the 31 Aug
|
||||||
|
2026 MI), but the latest visit is read from the dates, not assumed. The
|
||||||
|
report card still leaves no legacy grade in force.
|
||||||
|
model: int_ofsted_latest
|
||||||
|
given:
|
||||||
|
- input: ref('stg_ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 4, ungraded_inspection_date: '2026-03-02', ungraded_grade: 2, ungraded_outcome: 'School remains Good', rc_inspection_date: '2025-12-01', rc_inclusion: 3}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 4, latest_visit_date: '2026-03-02', latest_visit_kind: ungraded, latest_visit_outcome: 'School remains Good', current_grade: null, current_grade_date: null, current_grade_basis: null}
|
||||||
@@ -125,6 +125,30 @@ models:
|
|||||||
- name: inspection_date
|
- name: inspection_date
|
||||||
tests: [not_null]
|
tests: [not_null]
|
||||||
|
|
||||||
|
- name: fact_ofsted_latest
|
||||||
|
description: >
|
||||||
|
Current Ofsted status, one row per URN: the latest visit and the overall
|
||||||
|
grade still in force. See int_ofsted_latest for the rule.
|
||||||
|
columns:
|
||||||
|
- name: urn
|
||||||
|
tests: [not_null, unique]
|
||||||
|
- name: latest_visit_date
|
||||||
|
tests: [not_null]
|
||||||
|
- name: latest_visit_kind
|
||||||
|
tests:
|
||||||
|
- not_null
|
||||||
|
- accepted_values:
|
||||||
|
values: ['report_card', 'graded', 'ungraded']
|
||||||
|
- name: current_grade
|
||||||
|
tests:
|
||||||
|
- accepted_values:
|
||||||
|
values: [1, 2, 3, 4]
|
||||||
|
quote: false
|
||||||
|
- name: current_grade_basis
|
||||||
|
tests:
|
||||||
|
- accepted_values:
|
||||||
|
values: ['graded', 'confirmed']
|
||||||
|
|
||||||
- name: fact_pupil_characteristics
|
- name: fact_pupil_characteristics
|
||||||
description: Pupil demographics — one row per URN per year
|
description: Pupil demographics — one row per URN per year
|
||||||
columns:
|
columns:
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
-- Mart: current Ofsted status — one row per URN
|
||||||
|
-- The backend reads this instead of choosing the latest row of
|
||||||
|
-- fact_ofsted_inspection itself. The rule lives in int_ofsted_latest.
|
||||||
|
|
||||||
|
select
|
||||||
|
urn,
|
||||||
|
latest_visit_date,
|
||||||
|
latest_visit_kind,
|
||||||
|
latest_visit_outcome,
|
||||||
|
current_grade,
|
||||||
|
current_grade_date,
|
||||||
|
current_grade_basis,
|
||||||
|
graded_inspection_date,
|
||||||
|
ungraded_inspection_date,
|
||||||
|
rc_inspection_date,
|
||||||
|
inspection_type,
|
||||||
|
framework,
|
||||||
|
overall_effectiveness,
|
||||||
|
quality_of_education,
|
||||||
|
behaviour_attitudes,
|
||||||
|
personal_development,
|
||||||
|
leadership_management,
|
||||||
|
early_years_provision,
|
||||||
|
sixth_form_provision,
|
||||||
|
ungraded_outcome,
|
||||||
|
ungraded_grade,
|
||||||
|
rc_safeguarding_met,
|
||||||
|
rc_inclusion,
|
||||||
|
rc_curriculum_teaching,
|
||||||
|
rc_achievement,
|
||||||
|
rc_attendance_behaviour,
|
||||||
|
rc_personal_development,
|
||||||
|
rc_leadership_governance,
|
||||||
|
rc_early_years,
|
||||||
|
rc_sixth_form,
|
||||||
|
report_url
|
||||||
|
from {{ ref('int_ofsted_latest') }}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
-- Staging model: Ofsted inspection records
|
-- Staging model: Ofsted inspection records
|
||||||
-- Handles both OEIF (pre-Nov 2025) and Report Card (post-Nov 2025) frameworks
|
-- Handles both OEIF (pre-Nov 2025) and Report Card (post-Nov 2025) frameworks.
|
||||||
|
--
|
||||||
|
-- Ofsted's MI carries up to three inspections per school: the latest graded
|
||||||
|
-- one, the latest ungraded one and the latest report card. Their dates stay
|
||||||
|
-- separate here so int_ofsted_latest can tell which came last and which one a
|
||||||
|
-- grade belongs to (docs/superpowers/specs/2026-10-05-ofsted-current-status-design.md).
|
||||||
|
|
||||||
with source as (
|
with source as (
|
||||||
select * from {{ source('raw', 'ofsted_inspections') }}
|
select * from {{ source('raw', 'ofsted_inspections') }}
|
||||||
@@ -8,17 +13,12 @@ with source as (
|
|||||||
renamed as (
|
renamed as (
|
||||||
select
|
select
|
||||||
cast(urn as integer) as urn,
|
cast(urn as integer) as urn,
|
||||||
-- Inspection event date: the graded inspection when present, otherwise the
|
to_date(nullif(trim(inspection_date), 'NULL'), 'DD/MM/YYYY') as graded_inspection_date,
|
||||||
-- ungraded (Section 8) inspection so schools with only an ungraded
|
to_date(nullif(trim(ungraded_inspection_date), 'NULL'), 'DD/MM/YYYY') as ungraded_inspection_date,
|
||||||
-- inspection are still retained.
|
|
||||||
coalesce(
|
|
||||||
to_date(nullif(trim(inspection_date), 'NULL'), 'DD/MM/YYYY'),
|
|
||||||
to_date(nullif(trim(ungraded_inspection_date), 'NULL'), 'DD/MM/YYYY')
|
|
||||||
) as inspection_date,
|
|
||||||
inspection_type,
|
inspection_type,
|
||||||
event_type_grouping as framework,
|
event_type_grouping as framework,
|
||||||
|
|
||||||
-- OEIF grades (1-4 scale)
|
-- OEIF grades (1-4 scale; 9 = not applicable)
|
||||||
{{ safe_numeric('overall_effectiveness') }}::integer as overall_effectiveness,
|
{{ safe_numeric('overall_effectiveness') }}::integer as overall_effectiveness,
|
||||||
{{ safe_numeric('quality_of_education') }}::integer as quality_of_education,
|
{{ safe_numeric('quality_of_education') }}::integer as quality_of_education,
|
||||||
{{ safe_numeric('behaviour_and_attitudes') }}::integer as behaviour_attitudes,
|
{{ safe_numeric('behaviour_and_attitudes') }}::integer as behaviour_attitudes,
|
||||||
@@ -27,9 +27,9 @@ renamed as (
|
|||||||
{{ safe_numeric('early_years_provision') }}::integer as early_years_provision,
|
{{ safe_numeric('early_years_provision') }}::integer as early_years_provision,
|
||||||
{{ safe_numeric('sixth_form_provision') }}::integer as sixth_form_provision,
|
{{ safe_numeric('sixth_form_provision') }}::integer as sixth_form_provision,
|
||||||
|
|
||||||
-- Ungraded (Section 8) inspection outcome — free text, plus a grade
|
-- Ungraded (Section 8) inspection outcome — free text, plus the grade
|
||||||
-- parsed from it (1/2/null) used as a last-resort fallback for schools
|
-- it confirms ("School remains Good" → 2); null for outcomes that
|
||||||
-- with no graded overall effectiveness.
|
-- name no grade.
|
||||||
nullif(trim(ungraded_outcome), 'NULL') as ungraded_outcome,
|
nullif(trim(ungraded_outcome), 'NULL') as ungraded_outcome,
|
||||||
{{ parse_ungraded_outcome('ungraded_outcome') }}::integer as ungraded_grade,
|
{{ parse_ungraded_outcome('ungraded_outcome') }}::integer as ungraded_grade,
|
||||||
|
|
||||||
@@ -50,21 +50,18 @@ renamed as (
|
|||||||
{{ parse_report_card_grade('rc_sixth_form') }}::integer as rc_sixth_form,
|
{{ parse_report_card_grade('rc_sixth_form') }}::integer as rc_sixth_form,
|
||||||
|
|
||||||
-- Start date of the latest FULL inspection (the report-card
|
-- Start date of the latest FULL inspection (the report-card
|
||||||
-- inspection in the renewed framework). Guarded in the final select:
|
-- inspection in the renewed framework). Only kept when the row
|
||||||
-- only kept when the row actually carries report-card grades, because
|
-- carries report-card grades, because in legacy-format files this
|
||||||
-- in legacy-format files this column is the legacy inspection date.
|
-- column is the legacy inspection date.
|
||||||
to_date(nullif(trim(rc_inspection_date), 'NULL'), 'DD/MM/YYYY') as rc_inspection_date_raw,
|
to_date(nullif(trim(rc_inspection_date), 'NULL'), 'DD/MM/YYYY') as rc_inspection_date_raw,
|
||||||
|
|
||||||
nullif(trim(report_url), 'NULL') as report_url
|
nullif(trim(report_url), 'NULL') as report_url
|
||||||
from source
|
from source
|
||||||
where urn is not null
|
where urn is not null
|
||||||
and (
|
),
|
||||||
nullif(trim(inspection_date), 'NULL') is not null
|
|
||||||
or nullif(trim(ungraded_inspection_date), 'NULL') is not null
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
select
|
dated as (
|
||||||
|
select
|
||||||
*,
|
*,
|
||||||
case
|
case
|
||||||
when rc_safeguarding_met is not null
|
when rc_safeguarding_met is not null
|
||||||
@@ -76,5 +73,13 @@ select
|
|||||||
or rc_leadership_governance is not null
|
or rc_leadership_governance is not null
|
||||||
then rc_inspection_date_raw
|
then rc_inspection_date_raw
|
||||||
end as rc_inspection_date
|
end as rc_inspection_date
|
||||||
from renamed
|
from renamed
|
||||||
where inspection_date is not null
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
*,
|
||||||
|
-- For readers that predate the separate dates (fact_ofsted_inspection and
|
||||||
|
-- the backend until it reads fact_ofsted_latest). Never null below.
|
||||||
|
coalesce(graded_inspection_date, ungraded_inspection_date, rc_inspection_date) as inspection_date
|
||||||
|
from dated
|
||||||
|
where coalesce(graded_inspection_date, ungraded_inspection_date, rc_inspection_date) is not null
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
unit_tests:
|
||||||
|
- name: stg_ofsted_keeps_the_three_dates_apart
|
||||||
|
description: The graded and ungraded dates must stay separate so the latest visit can be found.
|
||||||
|
model: stg_ofsted_inspections
|
||||||
|
given:
|
||||||
|
- input: source('raw', 'ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 102408, inspection_date: '17/06/2025', ungraded_inspection_date: '06/02/2020', overall_effectiveness: 'Not judged', ungraded_outcome: 'School remains Good', rc_inspection_date: '17/06/2025', rc_inclusion: 'NULL'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 102408, graded_inspection_date: '2025-06-17', ungraded_inspection_date: '2020-02-06', rc_inspection_date: null, inspection_date: '2025-06-17', ungraded_grade: 2}
|
||||||
|
|
||||||
|
- name: stg_ofsted_keeps_report_card_only_rows
|
||||||
|
description: A school whose only inspection is a report card used to be dropped (audit H3).
|
||||||
|
model: stg_ofsted_inspections
|
||||||
|
given:
|
||||||
|
- input: source('raw', 'ofsted_inspections')
|
||||||
|
rows:
|
||||||
|
- {urn: 149612, inspection_date: 'NULL', ungraded_inspection_date: 'NULL', rc_inspection_date: '10/02/2026', rc_inclusion: 'Expected standard', rc_safeguarding_met: 'Met'}
|
||||||
|
- {urn: 1, inspection_date: 'NULL', ungraded_inspection_date: 'NULL', rc_inspection_date: 'NULL'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 149612, graded_inspection_date: null, ungraded_inspection_date: null, rc_inspection_date: '2026-02-10', inspection_date: '2026-02-10', rc_inclusion: 3}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
-- A grade is dated by the inspection that awarded or confirmed it, never
|
||||||
|
-- after the latest visit, and has a date and a basis exactly when it exists.
|
||||||
|
-- A report card leaves no legacy grade in force.
|
||||||
|
|
||||||
|
select urn
|
||||||
|
from {{ ref('fact_ofsted_latest') }}
|
||||||
|
where current_grade_date > latest_visit_date
|
||||||
|
or (current_grade is null) <> (current_grade_date is null)
|
||||||
|
or (current_grade is null) <> (current_grade_basis is null)
|
||||||
|
or (rc_inspection_date is not null and current_grade is not null)
|
||||||
Reference in new issue
Block a user