Compare commits
62
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b5e681482 | ||
|
|
3bd1dbd276 | ||
|
|
870af949ee | ||
|
|
5f93a7ecd2 | ||
|
|
951c666f8a | ||
|
|
e09d7a202b | ||
|
|
c6ff77f05b | ||
|
|
c7ddf0505d | ||
|
|
e659867590 | ||
|
|
4ae3853277 | ||
|
|
242c603aec | ||
|
|
59dd20ab00 | ||
|
|
dbb60acff3 | ||
|
|
967b1f0eed | ||
|
|
4db1131d0f | ||
|
|
0e987ef06e | ||
|
|
ac5b7ccd7f | ||
|
|
c26b65246f | ||
|
|
3728a63275 | ||
|
|
90b7d09086 | ||
|
|
480ac4b9a9 | ||
|
|
93f17211b1 | ||
|
|
f86d6f45d1 | ||
|
|
5eed09dfa7 | ||
|
|
d37baa572b | ||
|
|
9ef48da4b1 | ||
|
|
a42c586cc8 | ||
|
|
a9e3a6a700 | ||
|
|
96732c56d1 | ||
|
|
befaf950a7 | ||
|
|
dfa4928641 | ||
|
|
e6babe21f5 | ||
|
|
358705bf39 | ||
|
|
3be902e98f | ||
|
|
12c52244ee | ||
|
|
b6e48c4930 | ||
|
|
9f4f2507cc | ||
|
|
e1373fb6df | ||
|
|
94bfac9caf | ||
|
|
65a2619e1d | ||
|
|
ccfa44389e | ||
|
|
423b27140c | ||
|
|
1c62e8247d | ||
|
|
da5d63593f | ||
|
|
ef4a2ccccb | ||
|
|
392ec29fdb | ||
|
|
03e44cf154 | ||
|
|
59ea8a4bdd | ||
|
|
c931d1078c | ||
|
|
807133c305 | ||
|
|
41d3f3b971 | ||
|
|
c013265cb4 | ||
|
|
ad9d3b67f7 | ||
|
|
ca47d08186 | ||
|
|
62a6bfaf0c | ||
|
|
e344298440 | ||
|
|
8020191832 | ||
|
|
5f9caad7f4 | ||
|
|
e65c93b68e | ||
|
|
e3f21a5bc7 | ||
|
|
dea435a906 | ||
|
|
dd5b48e612 |
No files matched your search
+93
-18
@@ -97,8 +97,9 @@ STATIC_SITEMAP_PATHS = ("/", "/rankings", "/compare", "/admissions")
|
|||||||
|
|
||||||
# A page has something a search result could state if any of these is present
|
# A page has something a search result could state if any of these is present
|
||||||
# in any year. Shared by _has_publishable_data and the per-school check in
|
# in any year. Shared by _has_publishable_data and the per-school check in
|
||||||
# _school_sitemap_rows so the two can never drift.
|
# _school_sitemap_rows so the two can never drift. An inspection with no
|
||||||
_PUBLISHABLE_FIELDS = ("rwm_expected_pct", "attainment_8_score", "ofsted_grade")
|
# overall grade (ofsted_date alone) still gives a page something to state.
|
||||||
|
_PUBLISHABLE_FIELDS = ("rwm_expected_pct", "attainment_8_score", "ofsted_grade", "ofsted_date")
|
||||||
|
|
||||||
|
|
||||||
def _has_publishable_data(row) -> bool:
|
def _has_publishable_data(row) -> bool:
|
||||||
@@ -621,6 +622,31 @@ def verify_admin_api_key(x_api_key: str = Header(None)) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _with_whole_school_pupils(rows: pd.DataFrame, source: pd.DataFrame) -> pd.DataFrame:
|
||||||
|
"""Set total_pupils to the size of the school.
|
||||||
|
|
||||||
|
fact_performance's total_pupils is the cohort a year's results were
|
||||||
|
measured on. For a secondary that is the GCSE year group alone (Burntwood:
|
||||||
|
245 against 1,462 on roll). Cards, map popups and place rows label it
|
||||||
|
"pupils", so they take the register's whole-school count instead, and
|
||||||
|
nothing when the register has none.
|
||||||
|
"""
|
||||||
|
whole = source["gias_total_pupils"] if "gias_total_pupils" in source.columns else None
|
||||||
|
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.
|
||||||
@@ -859,7 +885,7 @@ async def get_schools(
|
|||||||
if c in df_latest.columns
|
if c in df_latest.columns
|
||||||
]
|
]
|
||||||
# fact_performance guarantees one row per (urn, year); df_latest has one row per urn.
|
# fact_performance guarantees one row per (urn, year); df_latest has one row per urn.
|
||||||
schools_df = df_latest[available_cols]
|
schools_df = _with_whole_school_pupils(df_latest[available_cols], df_latest)
|
||||||
|
|
||||||
# Location-based search (uses pre-geocoded data from database)
|
# Location-based search (uses pre-geocoded data from database)
|
||||||
search_coords = None
|
search_coords = None
|
||||||
@@ -952,7 +978,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),
|
||||||
@@ -1016,11 +1042,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"),
|
||||||
@@ -1244,17 +1273,63 @@ async def get_filter_options(request: Request):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _la_averages_payload(df: pd.DataFrame) -> dict:
|
||||||
|
"""Per-LA Attainment 8 for the "vs LA avg" comparison: DfE's own LA
|
||||||
|
averages (fact_ks4_la_averages, all state-funded schools), never a mean of
|
||||||
|
the dataframe. That mean counted independent and special schools and put
|
||||||
|
most LAs about 7 points low (audit H2).
|
||||||
|
|
||||||
|
The year is the latest with any school Attainment 8, so the average and
|
||||||
|
the scores set against it are the same year. Figures are keyed by our LA
|
||||||
|
name through the LA code. An LA without a DfE figure for that year (City of
|
||||||
|
London) is absent; no figures for the year, or no mart, give an empty map,
|
||||||
|
so rows show no comparison, never another year's figure.
|
||||||
|
"""
|
||||||
|
empty = {"year": 0, "secondary": {"attainment_8_by_la": {}}}
|
||||||
|
if df.empty or "attainment_8_score" not in df.columns:
|
||||||
|
return empty
|
||||||
|
scored = df[df["attainment_8_score"].notna()]
|
||||||
|
if scored.empty:
|
||||||
|
return empty
|
||||||
|
year = int(scored["year"].max())
|
||||||
|
|
||||||
|
la = (df[["local_authority_code", "local_authority"]]
|
||||||
|
.dropna()
|
||||||
|
.drop_duplicates("local_authority_code"))
|
||||||
|
name_by_code = {int(code): name for code, name in
|
||||||
|
zip(la["local_authority_code"], la["local_authority"])}
|
||||||
|
|
||||||
|
from . import database
|
||||||
|
from .models import Ks4LaAverage
|
||||||
|
|
||||||
|
rows: list = []
|
||||||
|
db = None
|
||||||
|
try:
|
||||||
|
db = database.SessionLocal()
|
||||||
|
rows = db.query(Ks4LaAverage).filter(Ks4LaAverage.year == year).all()
|
||||||
|
except Exception:
|
||||||
|
import logging
|
||||||
|
logging.getLogger(__name__).warning(
|
||||||
|
"DfE LA averages unavailable for %s", year, exc_info=True)
|
||||||
|
if db is not None:
|
||||||
|
db.rollback()
|
||||||
|
finally:
|
||||||
|
if db is not None:
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
by_la = {
|
||||||
|
name_by_code[row.la_code]: row.attainment_8_score
|
||||||
|
for row in rows
|
||||||
|
if row.attainment_8_score is not None and row.la_code in name_by_code
|
||||||
|
}
|
||||||
|
return {"year": year, "secondary": {"attainment_8_by_la": by_la}}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/api/la-averages")
|
@app.get("/api/la-averages")
|
||||||
@limiter.limit(f"{settings.rate_limit_per_minute}/minute")
|
@limiter.limit(f"{settings.rate_limit_per_minute}/minute")
|
||||||
async def get_la_averages(request: Request):
|
async def get_la_averages(request: Request):
|
||||||
"""Get per-LA average Attainment 8 score for secondary schools in the latest year."""
|
"""DfE's per-LA Attainment 8 averages for the latest year with results."""
|
||||||
df = load_school_data()
|
return _la_averages_payload(load_school_data())
|
||||||
if df.empty:
|
|
||||||
return {"year": 0, "secondary": {"attainment_8_by_la": {}}}
|
|
||||||
latest_year = int(df["year"].max())
|
|
||||||
sec_df = df[(df["year"] == latest_year) & df["attainment_8_score"].notna()]
|
|
||||||
la_avg = sec_df.groupby("local_authority")["attainment_8_score"].mean().round(1).to_dict()
|
|
||||||
return {"year": latest_year, "secondary": {"attainment_8_by_la": la_avg}}
|
|
||||||
|
|
||||||
|
|
||||||
_KS2_NATIONAL_METRICS = [
|
_KS2_NATIONAL_METRICS = [
|
||||||
@@ -1509,13 +1584,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"])
|
||||||
@@ -1545,7 +1619,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(rows[cols]),
|
"schools": clean_for_json(
|
||||||
|
_with_type_group(_with_whole_school_pupils(rows[cols], rows))),
|
||||||
"averages": averages,
|
"averages": averages,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+37
-56
@@ -18,7 +18,7 @@ from .config import settings
|
|||||||
from .database import SessionLocal, engine
|
from .database import SessionLocal, engine
|
||||||
from .models import (
|
from .models import (
|
||||||
DimSchool, DimLocation, KS2Performance,
|
DimSchool, DimLocation, KS2Performance,
|
||||||
FactOfstedInspection, FactAdmissions, FactAdmissionDistance,
|
FactOfstedLatest, FactAdmissions, FactAdmissionDistance,
|
||||||
FactDeprivation, FactFinance, FactPupilCharacteristics,
|
FactDeprivation, FactFinance, FactPupilCharacteristics,
|
||||||
FactKs4Destinations, FactKs5Destinations,
|
FactKs4Destinations, FactKs5Destinations,
|
||||||
)
|
)
|
||||||
@@ -251,10 +251,11 @@ _MAIN_QUERY = text("""
|
|||||||
s.website,
|
s.website,
|
||||||
s.telephone,
|
s.telephone,
|
||||||
s.nursery_provision,
|
s.nursery_provision,
|
||||||
foi.ofsted_grade,
|
foi.current_grade AS ofsted_grade,
|
||||||
foi.ofsted_date,
|
foi.current_grade_date AS ofsted_grade_date,
|
||||||
foi.ofsted_framework,
|
foi.latest_visit_date AS ofsted_date,
|
||||||
foi.ofsted_rc_date,
|
foi.framework AS ofsted_framework,
|
||||||
|
foi.rc_inspection_date AS ofsted_rc_date,
|
||||||
l.local_authority_name AS local_authority,
|
l.local_authority_name AS local_authority,
|
||||||
l.local_authority_code,
|
l.local_authority_code,
|
||||||
l.address_line1 AS address1,
|
l.address_line1 AS address1,
|
||||||
@@ -335,21 +336,10 @@ _MAIN_QUERY = text("""
|
|||||||
FROM marts.dim_school s
|
FROM marts.dim_school s
|
||||||
JOIN marts.dim_location l ON s.urn = l.urn
|
JOIN marts.dim_location l ON s.urn = l.urn
|
||||||
LEFT JOIN marts.fact_performance p ON s.urn = p.urn
|
LEFT JOIN marts.fact_performance p ON s.urn = p.urn
|
||||||
LEFT JOIN (
|
-- One current Ofsted status per school (pipeline: int_ofsted_latest): the
|
||||||
SELECT DISTINCT ON (urn)
|
-- grade still in force, dated by the inspection that awarded or confirmed
|
||||||
urn,
|
-- it, and the latest visit of any kind.
|
||||||
-- Fall back to the ungraded-inspection grade when no graded grade exists.
|
LEFT JOIN marts.fact_ofsted_latest foi ON s.urn = foi.urn
|
||||||
COALESCE(overall_effectiveness, ungraded_grade) AS ofsted_grade,
|
|
||||||
inspection_date AS ofsted_date,
|
|
||||||
framework AS ofsted_framework,
|
|
||||||
-- Report-card signal for list/map badges: non-null only when the
|
|
||||||
-- latest inspection carries report-card grades. framework is the
|
|
||||||
-- raw event grouping ("Schools - S5"), never "ReportCard", so it
|
|
||||||
-- can't be used to detect report cards.
|
|
||||||
rc_inspection_date AS ofsted_rc_date
|
|
||||||
FROM marts.fact_ofsted_inspection
|
|
||||||
ORDER BY urn, inspection_date DESC NULLS LAST
|
|
||||||
) foi ON s.urn = foi.urn
|
|
||||||
ORDER BY s.school_name, p.year
|
ORDER BY s.school_name, p.year
|
||||||
""")
|
""")
|
||||||
|
|
||||||
@@ -731,39 +721,36 @@ def compute_benchmarks(df: pd.DataFrame, census_benchmarks: dict | None = None)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _iso(d):
|
||||||
|
return d.isoformat() if d else None
|
||||||
|
|
||||||
|
|
||||||
def _ofsted_block(o, urn: int) -> dict:
|
def _ofsted_block(o, urn: int) -> dict:
|
||||||
"""Serialize the latest Ofsted inspection row for API responses.
|
"""Serialize a fact_ofsted_latest row for API responses.
|
||||||
|
|
||||||
`grade_source` records where the effective overall grade came from:
|
`current_grade` is the overall grade still in force, dated by the
|
||||||
a graded (Section 5) inspection, or carried forward from an ungraded
|
inspection that awarded or confirmed it; `latest_visit` is the school's
|
||||||
(Section 8) outcome — materially different claims a UI must be able
|
most recent inspection of any kind. The rule lives in int_ofsted_latest
|
||||||
to distinguish. `report_card` holds coded+labelled renewed-framework
|
(docs/superpowers/specs/2026-10-05-ofsted-current-status-design.md).
|
||||||
(Nov 2025) area judgements; safeguarding is a separate boolean and
|
`overall_effectiveness` and `inspection_date` describe the graded
|
||||||
never appears among the graded areas.
|
inspection itself and label its area judgements. `report_card` holds the
|
||||||
|
renewed-framework (Nov 2025) area judgements; safeguarding is a separate
|
||||||
|
boolean and never appears among the graded areas.
|
||||||
"""
|
"""
|
||||||
if o.overall_effectiveness is not None:
|
|
||||||
grade_source = "graded"
|
|
||||||
overall = o.overall_effectiveness
|
|
||||||
elif o.ungraded_grade is not None:
|
|
||||||
# Fall back to the grade parsed from an ungraded (Section 8) outcome
|
|
||||||
# (e.g. "School remains Good") so the detail page matches the list badge.
|
|
||||||
grade_source = "ungraded_carried_forward"
|
|
||||||
overall = o.ungraded_grade
|
|
||||||
else:
|
|
||||||
grade_source = None
|
|
||||||
overall = None
|
|
||||||
|
|
||||||
block = {
|
block = {
|
||||||
"framework": o.framework,
|
"framework": o.framework,
|
||||||
"inspection_date": o.inspection_date.isoformat() if o.inspection_date else None,
|
"inspection_date": _iso(o.graded_inspection_date),
|
||||||
"rc_inspection_date": (
|
"rc_inspection_date": _iso(o.rc_inspection_date),
|
||||||
o.rc_inspection_date.isoformat()
|
|
||||||
if getattr(o, "rc_inspection_date", None)
|
|
||||||
else None
|
|
||||||
),
|
|
||||||
"inspection_type": o.inspection_type,
|
"inspection_type": o.inspection_type,
|
||||||
"overall_effectiveness": overall,
|
"overall_effectiveness": o.overall_effectiveness if o.overall_effectiveness in (1, 2, 3, 4) else None,
|
||||||
"grade_source": grade_source,
|
"current_grade": (
|
||||||
|
{"grade": o.current_grade, "date": _iso(o.current_grade_date), "basis": o.current_grade_basis}
|
||||||
|
if o.current_grade is not None else None
|
||||||
|
),
|
||||||
|
"latest_visit": (
|
||||||
|
{"date": _iso(o.latest_visit_date), "kind": o.latest_visit_kind, "outcome": o.latest_visit_outcome}
|
||||||
|
if o.latest_visit_date else None
|
||||||
|
),
|
||||||
"quality_of_education": o.quality_of_education,
|
"quality_of_education": o.quality_of_education,
|
||||||
"behaviour_attitudes": o.behaviour_attitudes,
|
"behaviour_attitudes": o.behaviour_attitudes,
|
||||||
"personal_development": o.personal_development,
|
"personal_development": o.personal_development,
|
||||||
@@ -1097,20 +1084,14 @@ def get_supplementary_data_batch(db: Session, urns: list[int]) -> dict:
|
|||||||
logging.getLogger(__name__).error("batch supplementary query failed: %s", e)
|
logging.getLogger(__name__).error("batch supplementary query failed: %s", e)
|
||||||
db.rollback()
|
db.rollback()
|
||||||
|
|
||||||
# Ofsted — latest inspection per URN. Ordered so the first row seen per
|
# Ofsted — the mart already holds one current status per URN.
|
||||||
# URN is the most recent.
|
|
||||||
def _ofsted():
|
def _ofsted():
|
||||||
rows = (
|
rows = (
|
||||||
db.query(FactOfstedInspection)
|
db.query(FactOfstedLatest)
|
||||||
.filter(FactOfstedInspection.urn.in_(urns))
|
.filter(FactOfstedLatest.urn.in_(urns))
|
||||||
.order_by(FactOfstedInspection.urn, FactOfstedInspection.inspection_date.desc())
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
seen = set()
|
|
||||||
for o in rows:
|
for o in rows:
|
||||||
if o.urn in seen:
|
|
||||||
continue
|
|
||||||
seen.add(o.urn)
|
|
||||||
result[o.urn]["ofsted"] = _ofsted_block(o, o.urn)
|
result[o.urn]["ofsted"] = _ofsted_block(o, o.urn)
|
||||||
_safe(_ofsted)
|
_safe(_ofsted)
|
||||||
|
|
||||||
|
|||||||
@@ -162,6 +162,49 @@ class FactOfstedInspection(Base):
|
|||||||
report_url = Column(Text)
|
report_url = Column(Text)
|
||||||
|
|
||||||
|
|
||||||
|
class FactOfstedLatest(Base):
|
||||||
|
"""Current Ofsted status — one row per URN (pipeline: int_ofsted_latest).
|
||||||
|
|
||||||
|
`current_grade` is the overall grade still in force, dated by the
|
||||||
|
inspection that awarded or confirmed it; `latest_visit_*` is the school's
|
||||||
|
most recent inspection of any kind.
|
||||||
|
"""
|
||||||
|
__tablename__ = "fact_ofsted_latest"
|
||||||
|
__table_args__ = MARTS
|
||||||
|
|
||||||
|
urn = Column(Integer, primary_key=True)
|
||||||
|
latest_visit_date = Column(Date)
|
||||||
|
latest_visit_kind = Column(String(20))
|
||||||
|
latest_visit_outcome = Column(String(100))
|
||||||
|
current_grade = Column(Integer)
|
||||||
|
current_grade_date = Column(Date)
|
||||||
|
current_grade_basis = Column(String(20))
|
||||||
|
graded_inspection_date = Column(Date)
|
||||||
|
ungraded_inspection_date = Column(Date)
|
||||||
|
rc_inspection_date = Column(Date)
|
||||||
|
inspection_type = Column(String(100))
|
||||||
|
framework = Column(String(20))
|
||||||
|
overall_effectiveness = Column(Integer)
|
||||||
|
quality_of_education = Column(Integer)
|
||||||
|
behaviour_attitudes = Column(Integer)
|
||||||
|
personal_development = Column(Integer)
|
||||||
|
leadership_management = Column(Integer)
|
||||||
|
early_years_provision = Column(Integer)
|
||||||
|
sixth_form_provision = Column(Integer)
|
||||||
|
ungraded_outcome = Column(String(100))
|
||||||
|
ungraded_grade = Column(Integer)
|
||||||
|
rc_safeguarding_met = Column(Boolean)
|
||||||
|
rc_inclusion = Column(Integer)
|
||||||
|
rc_curriculum_teaching = Column(Integer)
|
||||||
|
rc_achievement = Column(Integer)
|
||||||
|
rc_attendance_behaviour = Column(Integer)
|
||||||
|
rc_personal_development = Column(Integer)
|
||||||
|
rc_leadership_governance = Column(Integer)
|
||||||
|
rc_early_years = Column(Integer)
|
||||||
|
rc_sixth_form = Column(Integer)
|
||||||
|
report_url = Column(Text)
|
||||||
|
|
||||||
|
|
||||||
class FactAdmissions(Base):
|
class FactAdmissions(Base):
|
||||||
"""School admissions — one row per URN per year."""
|
"""School admissions — one row per URN per year."""
|
||||||
__tablename__ = "fact_admissions"
|
__tablename__ = "fact_admissions"
|
||||||
@@ -301,6 +344,18 @@ class Ks4NationalAverage(Base):
|
|||||||
gcse_grade_91_pct = Column(Float)
|
gcse_grade_91_pct = Column(Float)
|
||||||
|
|
||||||
|
|
||||||
|
class Ks4LaAverage(Base):
|
||||||
|
"""Official DfE KS4 local-authority averages (all state-funded schools) —
|
||||||
|
one row per academic year and LA. la_code is the GIAS LA code."""
|
||||||
|
__tablename__ = "fact_ks4_la_averages"
|
||||||
|
__table_args__ = MARTS
|
||||||
|
|
||||||
|
year = Column(Integer, primary_key=True)
|
||||||
|
la_code = Column(Integer, primary_key=True)
|
||||||
|
la_name = Column(String)
|
||||||
|
attainment_8_score = Column(Float)
|
||||||
|
|
||||||
|
|
||||||
class Ks2NationalAverage(Base):
|
class Ks2NationalAverage(Base):
|
||||||
"""Official DfE KS2 national headline averages — one row per academic year."""
|
"""Official DfE KS2 national headline averages — one row per academic year."""
|
||||||
__tablename__ = "fact_ks2_national_averages"
|
__tablename__ = "fact_ks2_national_averages"
|
||||||
|
|||||||
@@ -569,10 +569,12 @@ 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",
|
||||||
"ofsted_grade",
|
"ofsted_grade",
|
||||||
|
"ofsted_grade_date",
|
||||||
"ofsted_date",
|
"ofsted_date",
|
||||||
"ofsted_framework",
|
"ofsted_framework",
|
||||||
"ofsted_rc_date",
|
"ofsted_rc_date",
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ from fastapi.testclient import TestClient
|
|||||||
LATEST = 202425
|
LATEST = 202425
|
||||||
|
|
||||||
CANNED_SUPPLEMENTARY = {
|
CANNED_SUPPLEMENTARY = {
|
||||||
"ofsted": {"overall_effectiveness": 2, "grade_source": "graded",
|
"ofsted": {"overall_effectiveness": 2,
|
||||||
|
"current_grade": {"grade": 2, "date": "2023-01-01", "basis": "graded"},
|
||||||
"report_card": {}, "ofsted_page_url": "https://reports.ofsted.gov.uk/provider/21/100140"},
|
"report_card": {}, "ofsted_page_url": "https://reports.ofsted.gov.uk/provider/21/100140"},
|
||||||
"census": {"year": 202526, "fsm_pct": 29.8},
|
"census": {"year": 202526, "fsm_pct": 29.8},
|
||||||
"admissions": {"year": 202627, "second_preference_offers": 4},
|
"admissions": {"year": 202627, "second_preference_offers": 4},
|
||||||
@@ -86,7 +87,7 @@ def test_each_school_gains_supplementary_blocks(client):
|
|||||||
body = client.get("/api/compare?urns=100140,138690").json()
|
body = client.get("/api/compare?urns=100140,138690").json()
|
||||||
for urn in ("100140", "138690"):
|
for urn in ("100140", "138690"):
|
||||||
school = body["comparison"][urn]
|
school = body["comparison"][urn]
|
||||||
assert school["ofsted"]["grade_source"] == "graded"
|
assert school["ofsted"]["current_grade"]["basis"] == "graded"
|
||||||
assert school["census"]["fsm_pct"] == 29.8
|
assert school["census"]["fsm_pct"] == 29.8
|
||||||
assert school["admissions"]["second_preference_offers"] == 4
|
assert school["admissions"]["second_preference_offers"] == 4
|
||||||
assert school["admissions_history"][0]["year"] == 202627
|
assert school["admissions_history"][0]["year"] == 202627
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
"""/api/la-averages serves DfE's own LA averages (fact_ks4_la_averages).
|
||||||
|
|
||||||
|
It used to average the dataframe: every school with an Attainment 8,
|
||||||
|
independent and special schools included. Kensington and Chelsea came out at
|
||||||
|
35.2 against DfE's 54.5, and most LAs about 7 points low (audit H2).
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
LATEST = 202425
|
||||||
|
|
||||||
|
|
||||||
|
def _df():
|
||||||
|
return pd.DataFrame([
|
||||||
|
# A state school and an independent: their mean, 37.65, is not DfE's figure.
|
||||||
|
dict(year=LATEST, local_authority="Kensington and Chelsea", local_authority_code=207, attainment_8_score=54.9),
|
||||||
|
dict(year=LATEST, local_authority="Kensington and Chelsea", local_authority_code=207, attainment_8_score=20.4),
|
||||||
|
dict(year=LATEST, local_authority="Bristol, City of", local_authority_code=801, attainment_8_score=45.0),
|
||||||
|
dict(year=LATEST, local_authority="West Sussex", local_authority_code=938, attainment_8_score=48.0),
|
||||||
|
# DfE publishes no LA figure for City of London.
|
||||||
|
dict(year=LATEST, local_authority="City of London", local_authority_code=201, attainment_8_score=30.0),
|
||||||
|
# A newer year with primary results only.
|
||||||
|
dict(year=202526, local_authority="Kensington and Chelsea", local_authority_code=207, attainment_8_score=np.nan),
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class _Row:
|
||||||
|
def __init__(self, year, la_code, la_name, attainment_8_score):
|
||||||
|
self.year = year
|
||||||
|
self.la_code = la_code
|
||||||
|
self.la_name = la_name
|
||||||
|
self.attainment_8_score = attainment_8_score
|
||||||
|
|
||||||
|
|
||||||
|
class _StubSession:
|
||||||
|
rows = [
|
||||||
|
_Row(LATEST, 207, "Kensington and Chelsea", 54.5),
|
||||||
|
_Row(LATEST, 801, "Bristol City", 46.3), # DfE's spelling, not ours
|
||||||
|
_Row(LATEST, 938, "West Sussex", None), # suppressed
|
||||||
|
_Row(LATEST, 330, "Birmingham", 44.0), # no school of ours there
|
||||||
|
_Row(202324, 207, "Kensington and Chelsea", 54.5),
|
||||||
|
]
|
||||||
|
|
||||||
|
def query(self, model):
|
||||||
|
assert model.__name__ == "Ks4LaAverage"
|
||||||
|
return self
|
||||||
|
|
||||||
|
def filter(self, condition):
|
||||||
|
# The payload filters on year == <year>; apply it as Postgres would.
|
||||||
|
self._year = condition.right.value
|
||||||
|
return self
|
||||||
|
|
||||||
|
def all(self):
|
||||||
|
return [r for r in self.rows if r.year == self._year]
|
||||||
|
|
||||||
|
def rollback(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class _OldYearOnly(_StubSession):
|
||||||
|
rows = [_Row(202324, 207, "Kensington and Chelsea", 54.5)]
|
||||||
|
|
||||||
|
|
||||||
|
class _NoMart(_StubSession):
|
||||||
|
def all(self):
|
||||||
|
raise RuntimeError('relation "marts.fact_ks4_la_averages" does not exist')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def payload(monkeypatch):
|
||||||
|
from backend import app as app_module
|
||||||
|
from backend import database as database_module
|
||||||
|
|
||||||
|
def _run(session_cls):
|
||||||
|
monkeypatch.setattr(database_module, "SessionLocal", session_cls)
|
||||||
|
return app_module._la_averages_payload(_df())
|
||||||
|
|
||||||
|
return _run
|
||||||
|
|
||||||
|
|
||||||
|
def test_serves_dfe_figures_keyed_by_our_la_names(payload):
|
||||||
|
out = payload(_StubSession)
|
||||||
|
assert out["year"] == LATEST
|
||||||
|
assert out["secondary"]["attainment_8_by_la"] == {
|
||||||
|
"Kensington and Chelsea": 54.5,
|
||||||
|
"Bristol, City of": 46.3,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_an_la_without_a_dfe_figure_is_absent(payload):
|
||||||
|
by_la = payload(_StubSession)["secondary"]["attainment_8_by_la"]
|
||||||
|
assert "City of London" not in by_la
|
||||||
|
assert "West Sussex" not in by_la
|
||||||
|
assert None not in by_la.values()
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_dfe_figures_for_the_year_give_an_empty_map(payload):
|
||||||
|
assert payload(_OldYearOnly) == {"year": LATEST, "secondary": {"attainment_8_by_la": {}}}
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_missing_mart_gives_an_empty_map(payload):
|
||||||
|
assert payload(_NoMart)["secondary"]["attainment_8_by_la"] == {}
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_endpoint_serves_dfe_figures(monkeypatch):
|
||||||
|
from backend import app as app_module
|
||||||
|
from backend import database as database_module
|
||||||
|
|
||||||
|
monkeypatch.setattr(app_module, "load_school_data", _df)
|
||||||
|
monkeypatch.setattr(database_module, "SessionLocal", _StubSession)
|
||||||
|
resp = TestClient(app_module.app).get("/api/la-averages")
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
assert resp.json()["secondary"]["attainment_8_by_la"]["Kensington and Chelsea"] == 54.5
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
"""The search badge reads ofsted_grade, ofsted_grade_date and ofsted_date from
|
||||||
|
list rows (nextjs-app/lib/utils.ts buildOfstedListBadge). A field the list
|
||||||
|
never sends would leave the badge without its year, or worse, fall back to
|
||||||
|
"Not yet inspected". The school page reads current_grade and latest_visit from
|
||||||
|
the ofsted block (lib/ofstedStatus.ts)."""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
from backend.schemas import SCHOOL_COLUMNS
|
||||||
|
|
||||||
|
|
||||||
|
def test_list_columns_include_the_status_fields():
|
||||||
|
for field in ("ofsted_grade", "ofsted_grade_date", "ofsted_date", "ofsted_rc_date"):
|
||||||
|
assert field in SCHOOL_COLUMNS
|
||||||
|
|
||||||
|
|
||||||
|
def _df() -> pd.DataFrame:
|
||||||
|
# Rabbsfarm (102408): latest inspection 17 June 2025 gave no overall grade.
|
||||||
|
return pd.DataFrame([{
|
||||||
|
"urn": 102408, "school_name": "Rabbsfarm Primary School", "phase": "Primary",
|
||||||
|
"school_type": "Community school", "local_authority": "Hillingdon",
|
||||||
|
"address": "Gordon Road, Yiewsley, UB7 8AH", "postcode": "UB7 8AH",
|
||||||
|
"latitude": 51.51, "longitude": -0.47, "year": 202425, "rwm_expected_pct": 58.0,
|
||||||
|
"total_pupils": 60, "gias_total_pupils": 616,
|
||||||
|
"ofsted_grade": np.nan, "ofsted_grade_date": None, "ofsted_date": "2025-06-17",
|
||||||
|
"ofsted_framework": "Schools - S5", "ofsted_rc_date": None,
|
||||||
|
}])
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def client(monkeypatch):
|
||||||
|
from backend import app as app_module
|
||||||
|
|
||||||
|
monkeypatch.setattr(app_module, "load_school_data", _df)
|
||||||
|
monkeypatch.setattr(app_module, "load_latest_school_data", _df)
|
||||||
|
monkeypatch.setattr(app_module, "_place_registry", None)
|
||||||
|
return TestClient(app_module.app, raise_server_exceptions=False)
|
||||||
|
|
||||||
|
|
||||||
|
def test_search_rows_carry_the_status_fields(client):
|
||||||
|
resp = client.get("/api/schools")
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
row = resp.json()["schools"][0]
|
||||||
|
assert row["ofsted_grade"] is None
|
||||||
|
assert row["ofsted_date"] == "2025-06-17"
|
||||||
|
assert "ofsted_grade_date" in row
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_school_with_only_an_inspection_is_publishable():
|
||||||
|
from backend.app import _has_publishable_data
|
||||||
|
|
||||||
|
assert _has_publishable_data({"rwm_expected_pct": None, "attainment_8_score": None,
|
||||||
|
"ofsted_grade": None, "ofsted_date": "2025-06-17"})
|
||||||
@@ -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"
|
||||||
@@ -85,12 +85,15 @@ def _ofsted_row(urn, date, oe):
|
|||||||
"framework", "inspection_type", "quality_of_education", "behaviour_attitudes",
|
"framework", "inspection_type", "quality_of_education", "behaviour_attitudes",
|
||||||
"personal_development", "leadership_management", "early_years_provision",
|
"personal_development", "leadership_management", "early_years_provision",
|
||||||
"sixth_form_provision", "ungraded_outcome", "ungraded_grade",
|
"sixth_form_provision", "ungraded_outcome", "ungraded_grade",
|
||||||
|
"ungraded_inspection_date", "rc_inspection_date", "latest_visit_outcome",
|
||||||
"rc_safeguarding_met", "rc_inclusion", "rc_curriculum_teaching", "rc_achievement",
|
"rc_safeguarding_met", "rc_inclusion", "rc_curriculum_teaching", "rc_achievement",
|
||||||
"rc_attendance_behaviour", "rc_personal_development", "rc_leadership_governance",
|
"rc_attendance_behaviour", "rc_personal_development", "rc_leadership_governance",
|
||||||
"rc_early_years", "rc_sixth_form", "report_url",
|
"rc_early_years", "rc_sixth_form", "report_url",
|
||||||
)}
|
)}
|
||||||
base.update(urn=urn, inspection_date=types.SimpleNamespace(isoformat=lambda: date),
|
when = types.SimpleNamespace(isoformat=lambda: date)
|
||||||
overall_effectiveness=oe, grade_source=None)
|
base.update(urn=urn, graded_inspection_date=when, latest_visit_date=when,
|
||||||
|
latest_visit_kind="graded", overall_effectiveness=oe,
|
||||||
|
current_grade=oe, current_grade_date=when, current_grade_basis="graded")
|
||||||
return types.SimpleNamespace(**base)
|
return types.SimpleNamespace(**base)
|
||||||
|
|
||||||
|
|
||||||
@@ -114,10 +117,9 @@ def _dist_row(urn, year, distance_m, route_count=1):
|
|||||||
|
|
||||||
def test_one_query_per_table_and_latest_row_per_urn():
|
def test_one_query_per_table_and_latest_row_per_urn():
|
||||||
rows = {
|
rows = {
|
||||||
# URN 1 has two Ofsted rows; the batch must keep the most recent (2023).
|
# The mart holds one current Ofsted status per URN.
|
||||||
"FactOfstedInspection": [
|
"FactOfstedLatest": [
|
||||||
_ofsted_row(1, "2023-01-01", 2),
|
_ofsted_row(1, "2023-01-01", 2),
|
||||||
_ofsted_row(1, "2019-01-01", 3),
|
|
||||||
_ofsted_row(2, "2021-06-01", 1),
|
_ofsted_row(2, "2021-06-01", 1),
|
||||||
],
|
],
|
||||||
"FactAdmissions": [_adm_row(1, 202526), _adm_row(1, 202627), _adm_row(2, 202627)],
|
"FactAdmissions": [_adm_row(1, 202526), _adm_row(1, 202627), _adm_row(2, 202627)],
|
||||||
@@ -142,14 +144,14 @@ def test_one_query_per_table_and_latest_row_per_urn():
|
|||||||
assert sorted(session.queries) == [
|
assert sorted(session.queries) == [
|
||||||
"FactAdmissionDistance", "FactAdmissions", "FactDeprivation",
|
"FactAdmissionDistance", "FactAdmissions", "FactDeprivation",
|
||||||
"FactFinance", "FactKs4Destinations", "FactKs5Destinations",
|
"FactFinance", "FactKs4Destinations", "FactKs5Destinations",
|
||||||
"FactOfstedInspection", "FactPupilCharacteristics",
|
"FactOfstedLatest", "FactPupilCharacteristics",
|
||||||
]
|
]
|
||||||
|
|
||||||
# A school with no destination rows gets null, not an empty shell — the
|
# A school with no destination rows gets null, not an empty shell — the
|
||||||
# frontend renders the section from the block's presence.
|
# frontend renders the section from the block's presence.
|
||||||
assert out[1]["destinations"] is None
|
assert out[1]["destinations"] is None
|
||||||
|
|
||||||
# Latest Ofsted kept per URN
|
# Each URN's current Ofsted status
|
||||||
assert out[1]["ofsted"]["overall_effectiveness"] == 2
|
assert out[1]["ofsted"]["overall_effectiveness"] == 2
|
||||||
assert out[2]["ofsted"]["overall_effectiveness"] == 1
|
assert out[2]["ofsted"]["overall_effectiveness"] == 1
|
||||||
|
|
||||||
@@ -175,7 +177,7 @@ def test_one_query_per_table_and_latest_row_per_urn():
|
|||||||
|
|
||||||
|
|
||||||
def test_single_wrapper_matches_batch(monkeypatch):
|
def test_single_wrapper_matches_batch(monkeypatch):
|
||||||
session = _FakeSession({"FactOfstedInspection": [_ofsted_row(5, "2022-01-01", 2)]})
|
session = _FakeSession({"FactOfstedLatest": [_ofsted_row(5, "2022-01-01", 2)]})
|
||||||
single = data_loader.get_supplementary_data(session, 5)
|
single = data_loader.get_supplementary_data(session, 5)
|
||||||
assert single["ofsted"]["overall_effectiveness"] == 2
|
assert single["ofsted"]["overall_effectiveness"] == 2
|
||||||
assert single["admissions_history"] == []
|
assert single["admissions_history"] == []
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ from backend.data_loader import _admissions_row_dict, _ofsted_block
|
|||||||
|
|
||||||
def _row(**kw):
|
def _row(**kw):
|
||||||
base = dict(
|
base = dict(
|
||||||
framework="RC", inspection_date=None, inspection_type=None,
|
framework="RC", inspection_type=None,
|
||||||
|
graded_inspection_date=None, ungraded_inspection_date=None, rc_inspection_date=None,
|
||||||
|
latest_visit_date=None, latest_visit_kind=None, latest_visit_outcome=None,
|
||||||
|
current_grade=None, current_grade_date=None, current_grade_basis=None,
|
||||||
overall_effectiveness=None, quality_of_education=None,
|
overall_effectiveness=None, quality_of_education=None,
|
||||||
behaviour_attitudes=None, personal_development=None,
|
behaviour_attitudes=None, personal_development=None,
|
||||||
leadership_management=None, early_years_provision=None,
|
leadership_management=None, early_years_provision=None,
|
||||||
@@ -33,20 +36,41 @@ def test_report_card_block_and_provider_url():
|
|||||||
assert block["ofsted_page_url"] == "https://reports.ofsted.gov.uk/provider/21/100140"
|
assert block["ofsted_page_url"] == "https://reports.ofsted.gov.uk/provider/21/100140"
|
||||||
|
|
||||||
|
|
||||||
def test_grade_source_graded_vs_carried_forward():
|
def test_no_grade_is_carried_past_a_newer_inspection():
|
||||||
assert _ofsted_block(_row(overall_effectiveness=1), urn=1)["grade_source"] == "graded"
|
# Rabbsfarm (102408): the 2025 inspection gave no overall grade.
|
||||||
carried = _ofsted_block(_row(ungraded_grade=2), urn=1)
|
block = _ofsted_block(_row(
|
||||||
assert carried["grade_source"] == "ungraded_carried_forward"
|
graded_inspection_date=date(2025, 6, 17), ungraded_inspection_date=date(2020, 2, 6),
|
||||||
assert carried["overall_effectiveness"] == 2
|
latest_visit_date=date(2025, 6, 17), latest_visit_kind="graded",
|
||||||
assert _ofsted_block(_row(), urn=1)["grade_source"] is None
|
ungraded_grade=2, ungraded_outcome="School remains Good", quality_of_education=3,
|
||||||
|
), urn=102408)
|
||||||
|
assert block["current_grade"] is None
|
||||||
|
assert block["overall_effectiveness"] is None
|
||||||
|
assert block["latest_visit"] == {"date": "2025-06-17", "kind": "graded", "outcome": None}
|
||||||
|
assert block["inspection_date"] == "2025-06-17"
|
||||||
|
assert "grade_source" not in block
|
||||||
|
|
||||||
|
|
||||||
|
def test_confirmed_grade_is_dated_by_the_confirming_visit():
|
||||||
|
block = _ofsted_block(_row(
|
||||||
|
graded_inspection_date=date(2020, 1, 7), ungraded_inspection_date=date(2024, 7, 18),
|
||||||
|
latest_visit_date=date(2024, 7, 18), latest_visit_kind="ungraded",
|
||||||
|
latest_visit_outcome="School remains Good", overall_effectiveness=2,
|
||||||
|
current_grade=2, current_grade_date=date(2024, 7, 18), current_grade_basis="confirmed",
|
||||||
|
), urn=104762)
|
||||||
|
assert block["current_grade"] == {"grade": 2, "date": "2024-07-18", "basis": "confirmed"}
|
||||||
|
assert block["overall_effectiveness"] == 2
|
||||||
|
assert block["inspection_date"] == "2020-01-07"
|
||||||
|
|
||||||
|
|
||||||
|
def test_overall_sentinel_is_not_served_as_a_grade():
|
||||||
|
assert _ofsted_block(_row(overall_effectiveness=9), urn=1)["overall_effectiveness"] is None
|
||||||
|
|
||||||
|
|
||||||
def test_ofsted_block_carries_rc_inspection_date():
|
def test_ofsted_block_carries_rc_inspection_date():
|
||||||
o = _row(
|
o = _row(
|
||||||
ungraded_grade=2,
|
|
||||||
rc_achievement=1,
|
rc_achievement=1,
|
||||||
rc_inspection_date=date(2026, 2, 3),
|
rc_inspection_date=date(2026, 2, 3),
|
||||||
inspection_date=date(2021, 10, 7),
|
graded_inspection_date=date(2021, 10, 7),
|
||||||
)
|
)
|
||||||
block = _ofsted_block(o, urn=138690)
|
block = _ofsted_block(o, urn=138690)
|
||||||
assert block["rc_inspection_date"] == "2026-02-03"
|
assert block["rc_inspection_date"] == "2026-02-03"
|
||||||
@@ -55,7 +79,7 @@ def test_ofsted_block_carries_rc_inspection_date():
|
|||||||
|
|
||||||
|
|
||||||
def test_ofsted_block_rc_inspection_date_none_when_absent():
|
def test_ofsted_block_rc_inspection_date_none_when_absent():
|
||||||
o = _row(overall_effectiveness=1, inspection_date=date(2021, 10, 13))
|
o = _row(overall_effectiveness=1, graded_inspection_date=date(2021, 10, 13))
|
||||||
block = _ofsted_block(o, urn=136276)
|
block = _ofsted_block(o, urn=136276)
|
||||||
assert block["rc_inspection_date"] is None
|
assert block["rc_inspection_date"] is None
|
||||||
|
|
||||||
@@ -63,6 +87,7 @@ def test_ofsted_block_rc_inspection_date_none_when_absent():
|
|||||||
def test_ofsted_block_keeps_existing_keys():
|
def test_ofsted_block_keeps_existing_keys():
|
||||||
block = _ofsted_block(_row(overall_effectiveness=2, quality_of_education=2), urn=1)
|
block = _ofsted_block(_row(overall_effectiveness=2, quality_of_education=2), urn=1)
|
||||||
for key in ("framework", "inspection_date", "overall_effectiveness",
|
for key in ("framework", "inspection_date", "overall_effectiveness",
|
||||||
|
"current_grade", "latest_visit",
|
||||||
"quality_of_education", "rc_inclusion", "report_url"):
|
"quality_of_education", "rc_inclusion", "report_url"):
|
||||||
assert key in block
|
assert key in block
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
"""Cards, map popups and place rows label total_pupils "pupils".
|
||||||
|
|
||||||
|
fact_performance's total_pupils is the cohort a year's results were measured
|
||||||
|
on. For a secondary that is the GCSE year group alone: Burntwood showed 245 in
|
||||||
|
search against 1,462 on roll. The list and place payloads therefore carry the
|
||||||
|
register's whole-school count, and nothing when the register has none.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
|
||||||
|
def _schools_df() -> pd.DataFrame:
|
||||||
|
base = {
|
||||||
|
"local_authority": "Essex", "school_type": "Academy converter",
|
||||||
|
"year": 202425, "ofsted_grade": 2.0, "ofsted_date": None,
|
||||||
|
"town": "Brentwood", "postcode": "CM13 1AA", "status": "Open",
|
||||||
|
"address": "1 Test Street", "latitude": 51.6, "longitude": 0.3,
|
||||||
|
"gender": "Mixed", "rwm_expected_pct": np.nan, "attainment_8_score": 50.0,
|
||||||
|
}
|
||||||
|
rows = [
|
||||||
|
# Secondary: results cohort 245, register 1,462.
|
||||||
|
{**base, "urn": 100001, "school_name": "Alpha High", "phase": "Secondary",
|
||||||
|
"total_pupils": 245, "gias_total_pupils": 1462},
|
||||||
|
# Register count missing: no count, never the cohort.
|
||||||
|
{**base, "urn": 100002, "school_name": "Beta High", "phase": "Secondary",
|
||||||
|
"total_pupils": 180, "gias_total_pupils": np.nan},
|
||||||
|
]
|
||||||
|
# Enough schools in one town for it to have a place page.
|
||||||
|
rows += [
|
||||||
|
{**base, "urn": 100010 + i, "school_name": f"Gamma High {i}", "phase": "Secondary",
|
||||||
|
"total_pupils": 200, "gias_total_pupils": 1000 + i}
|
||||||
|
for i in range(5)
|
||||||
|
]
|
||||||
|
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, "_place_registry", None)
|
||||||
|
return TestClient(app_module.app, raise_server_exceptions=False)
|
||||||
|
|
||||||
|
|
||||||
|
def _pupils(schools: list[dict]) -> dict[int, object]:
|
||||||
|
return {s["urn"]: s.get("total_pupils") for s in schools}
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_list_carries_the_whole_school_count(client):
|
||||||
|
resp = client.get("/api/schools?page_size=50")
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
pupils = _pupils(resp.json()["schools"])
|
||||||
|
assert pupils[100001] == 1462
|
||||||
|
assert pupils[100002] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_place_page_carries_the_whole_school_count(client):
|
||||||
|
resp = client.get("/api/places/town/brentwood")
|
||||||
|
assert resp.status_code == 200, resp.text
|
||||||
|
pupils = _pupils(resp.json()["schools"])
|
||||||
|
assert pupils[100001] == 1462
|
||||||
|
assert pupils[100002] is None
|
||||||
@@ -61,6 +61,12 @@ history from the full DataFrame and supplementary data from marts. Comparisons
|
|||||||
batch supplementary queries across selected URNs. Async routes still contain
|
batch supplementary queries across selected URNs. Async routes still contain
|
||||||
synchronous dependency calls; a fully asynchronous database layer is not present.
|
synchronous dependency calls; a fully asynchronous database layer is not present.
|
||||||
|
|
||||||
|
DfE's official benchmarks live in marts: `fact_ks2_national_averages` and
|
||||||
|
`fact_ks4_national_averages` for England, and `fact_ks4_la_averages` (all
|
||||||
|
state-funded schools, per LA) for the search rows' "vs LA avg".
|
||||||
|
`data_loader.compute_benchmarks` computes further state-school benchmarks from
|
||||||
|
our own dataset; they are not DfE figures and are labelled as computed.
|
||||||
|
|
||||||
## Frontend boundaries
|
## Frontend boundaries
|
||||||
|
|
||||||
`app/(frontend)` owns the public root layout and pages. `app/(payload)` owns the
|
`app/(frontend)` owns the public root layout and pages. `app/(payload)` owns the
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
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.
|
||||||
@@ -0,0 +1,300 @@
|
|||||||
|
# 2023/24 Results and DfE LA Averages — Design
|
||||||
|
|
||||||
|
**Date:** 2026-10-06
|
||||||
|
**Status:** approved design, not yet implemented
|
||||||
|
**Scope:** `tap_uk_ees` (KS4 results, KS4 information, new LA stream),
|
||||||
|
`safe_numeric`, new `fact_ks4_la_averages` mart, annual EES DAG selector,
|
||||||
|
`/api/la-averages`, secondary search rows and map cards
|
||||||
|
**Fixes:** audit findings C2 and H2, from the 3 Oct 2026 accuracy audit
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
|
||||||
|
Show every 2023/24 result and school-information figure DfE published, and
|
||||||
|
compare each state-funded secondary school with DfE's own local-authority
|
||||||
|
average.
|
||||||
|
|
||||||
|
## The problem
|
||||||
|
|
||||||
|
### C2: 2023/24 is empty
|
||||||
|
|
||||||
|
Bishop Stopford School (137086) shows Attainment 8 60.7 for 2022/23, nothing
|
||||||
|
for 2023/24 and 58.7 for 2024/25. DfE's 2023/24 figures are Attainment 8 64.1,
|
||||||
|
Progress 8 +1.02 and English and maths grade 4+ 91.7%. 2023/24 is the last year
|
||||||
|
DfE published Progress 8 (2024/25 has no KS2 baseline), so the site shows no
|
||||||
|
recent Progress 8 for any school. Site-wide, 4,170 listed schools have a DfE
|
||||||
|
2023/24 Attainment 8 and 3,384 a Progress 8.
|
||||||
|
|
||||||
|
There are three separate causes.
|
||||||
|
|
||||||
|
1. **KS4 results.** The 2024/25 release's
|
||||||
|
`202425_performance_tables_schools_final.csv` is a time series: it holds
|
||||||
|
2022/23, 2023/24 and 2024/25 under the current column names, with the right
|
||||||
|
values (Bishop Stopford 2023/24: 64.1, 1.02, 91.7). The 2023/24 release's own
|
||||||
|
`202324_performance_tables_schools_final.csv`, re-issued on 10 March 2026,
|
||||||
|
uses the older names (`t_pupils`, `avg_att8`, `avg_p8score`,
|
||||||
|
`pt_l2basics_94` …). `EESDatasetStream` reads releases in the API's order,
|
||||||
|
newest first, so the old file is read last. Its rows carry none of the
|
||||||
|
declared fields, and target-postgres upserts on the stream's primary key
|
||||||
|
(`append_only = not key_properties` in meltanolabs-target-postgres 0.8.0),
|
||||||
|
so they overwrite the good 2023/24 rows with nulls.
|
||||||
|
|
||||||
|
The two files share the keys of every "Total" row, but 34,254 of the 57,090
|
||||||
|
2023/24 sub-group rows use different labels ("Low prior" against "Low prior
|
||||||
|
attainment"). Those old-label rows sit in `raw.ees_ks4_performance` with
|
||||||
|
null measures. Nothing reads them.
|
||||||
|
|
||||||
|
2. **KS4 school information.** 2023/24 information exists only in the 2023/24
|
||||||
|
release, in `202324_information_about_schools_final.csv`, with the older
|
||||||
|
names. `EESKS4InfoStream` declares the newer ones, so prior attainment,
|
||||||
|
SEN percentages, disadvantage gaps and Progress 8 banding are null for
|
||||||
|
2023/24.
|
||||||
|
|
||||||
|
3. **KS2 school information.** The 2023/24 file
|
||||||
|
`ks2_school_information_data.csv` uses the declared names, and pupil counts
|
||||||
|
load (school 147411: 818 pupils, 112 eligible). Its percentages are written
|
||||||
|
with a sign (`ptfsm6cla1a = "34%"`). `safe_numeric` accepts only
|
||||||
|
`^-?[0-9]+(\.[0-9]+)?$`, so disadvantaged, EAL, SEN and mobility percentages
|
||||||
|
are null for every school in 2023/24.
|
||||||
|
|
||||||
|
DfE published no school-level KS2 information file for 2022/23 (the 2023/24
|
||||||
|
release's attainment file carries 2022/23 attainment rows only). Those nulls are
|
||||||
|
a gap in the source, not a defect.
|
||||||
|
|
||||||
|
### H2: "vs LA avg" uses the wrong average
|
||||||
|
|
||||||
|
`/api/la-averages` (`backend/app.py`) takes an unweighted mean of every school
|
||||||
|
in the LA with an Attainment 8 score, independent and special schools included.
|
||||||
|
Independent schools score low because DfE measures exclude IGCSEs, and special
|
||||||
|
schools score low for other reasons, so the average is too low almost
|
||||||
|
everywhere. Kensington and Chelsea's "LA avg" is 35.2: the mean of 6 state
|
||||||
|
schools (54.9) and 8 independent schools (20.4). DfE's figure is 54.5. Of the
|
||||||
|
151 LAs the audit compared, ours was lower in 147, by 7.1 points on average and
|
||||||
|
by up to 19.3, so most secondary schools look better than their area.
|
||||||
|
|
||||||
|
DfE's LA averages are already in the file the pipeline downloads for the
|
||||||
|
England averages: the "summary, all state-funded" data set
|
||||||
|
(`data-catalogue/data-set/1b649e16-01e8-435b-a814-56be2faf9054/csv`). Its
|
||||||
|
`Local authority` / `All state-funded` / Total rows match DfE's published
|
||||||
|
performance-table LA averages (RECTYPE 4) for all 152 LAs in 2024/25, with no
|
||||||
|
difference. `EESKs4NationalStream` keeps the England row and discards them.
|
||||||
|
"All state-funded" is the same population as the England benchmark the site
|
||||||
|
already shows.
|
||||||
|
|
||||||
|
Computing the average ourselves from state-funded schools, weighted by pupils,
|
||||||
|
was tested and rejected: it differs from DfE's figure by 1.1 points on average
|
||||||
|
and is never exact.
|
||||||
|
|
||||||
|
## Non-goals
|
||||||
|
|
||||||
|
- 2022/23 KS2 school information (DfE published none).
|
||||||
|
- An "excludes IGCSEs" note wherever an independent school's Attainment 8
|
||||||
|
appears. This change only stops comparing independent schools with the LA.
|
||||||
|
- Showing 2023/24 Progress 8 in the GCSE section's headline. The history section
|
||||||
|
shows it once the data loads; the 2024/25 banner stays true.
|
||||||
|
- Updating the fixed EES data-set id when DfE publishes 2025/26. It already
|
||||||
|
feeds the England averages; the LA stream shares it.
|
||||||
|
- LA comparisons for other measures or on other pages.
|
||||||
|
- Deleting the leftover old-label raw rows automatically.
|
||||||
|
|
||||||
|
## The rules
|
||||||
|
|
||||||
|
### The newest release owns every year it contains (KS4 results only)
|
||||||
|
|
||||||
|
`EESDatasetStream` gets an opt-in class attribute,
|
||||||
|
`_newest_release_owns_period: bool = False`. `EESKS4PerformanceStream` sets it
|
||||||
|
to `True`. When it is on:
|
||||||
|
|
||||||
|
- releases are processed newest first by `time_period` (from the release slug),
|
||||||
|
not in the API's order;
|
||||||
|
- the stream records each `time_period` it has emitted;
|
||||||
|
- in each older release, rows whose `time_period` a newer release already
|
||||||
|
emitted are dropped, and the stream logs how many it skipped and for which
|
||||||
|
years;
|
||||||
|
- years only an older release contains are emitted as before.
|
||||||
|
|
||||||
|
The filter is a pure function, testable without a download. Other streams keep
|
||||||
|
the current behaviour. A general rule would be wrong: the 2024/25 KS2 file holds
|
||||||
|
98,448 of the 955,956 rows the 2023/24 release has for 2023/24.
|
||||||
|
|
||||||
|
### KS4 information: old names
|
||||||
|
|
||||||
|
`EESKS4InfoStream._column_renames` maps the 2023/24 names onto the declared
|
||||||
|
fields:
|
||||||
|
|
||||||
|
| 2023/24 column | Declared field |
|
||||||
|
|---|---|
|
||||||
|
| `t_allks_pupils` | `allks_pupil_count` |
|
||||||
|
| `t_allks_boys` | `allks_boys_count` |
|
||||||
|
| `t_allks_girls` | `allks_girls_count` |
|
||||||
|
| `t_pupils` | `endks4_pupil_count` |
|
||||||
|
| `avg_ks2_scaledscore` | `ks2_scaledscore_average` |
|
||||||
|
| `pt_sen_with_ehcp` | `sen_with_ehcp_pupil_percent` |
|
||||||
|
| `pt_sen` | `sen_pupil_percent` |
|
||||||
|
| `pt_sen_no_ehcp` | `sen_no_ehcp_pupil_percent` |
|
||||||
|
| `diffn_att8` | `attainment8_diffn` |
|
||||||
|
| `diffn_p8mea` | `progress8_diffn` |
|
||||||
|
| `p8_banding` | `progress8_banding` |
|
||||||
|
|
||||||
|
Newer files contain none of the old names, so they are unaffected.
|
||||||
|
|
||||||
|
### `safe_numeric` accepts a trailing `%`
|
||||||
|
|
||||||
|
The pattern becomes `^-?[0-9]+(\.[0-9]+)?%?$` and the cast reads
|
||||||
|
`rtrim(col, '%')`. A value such as `34%` can only mean 34. Suppression codes
|
||||||
|
(`c`, `z`, `x` …) still become null.
|
||||||
|
|
||||||
|
### LA averages
|
||||||
|
|
||||||
|
A new stream, `ees_ks4_la`, reads the same CSV as `ees_ks4_national` and keeps
|
||||||
|
rows where `geographic_level = 'Local authority'`,
|
||||||
|
`establishment_type_group = 'All state-funded'`, `breakdown_topic = 'Total'` and
|
||||||
|
`breakdown = 'Total'` (case-insensitive, as the national stream compares). It
|
||||||
|
emits `time_period`, `old_la_code`, `new_la_code`, `la_name` and the 8 headline
|
||||||
|
measures the national stream emits (`_KS4_NATIONAL_COL_MAP`). Primary key:
|
||||||
|
(`time_period`, `old_la_code`). The two streams share one download-and-filter
|
||||||
|
helper.
|
||||||
|
|
||||||
|
`old_la_code` is the GIAS LA code (`local_authority_code`), so schools join on
|
||||||
|
the code, not the name. Names match today for every LA DfE publishes; DfE
|
||||||
|
publishes no figure for City of London.
|
||||||
|
|
||||||
|
### Which schools get a gap
|
||||||
|
|
||||||
|
The search row and the map card show "vs LA avg" only when the school has an
|
||||||
|
Attainment 8 score, is neither special (`isSpecialSchool`) nor independent
|
||||||
|
(`isIndependentSchool`: "independent" in the GIAS type, which covers "Other
|
||||||
|
independent school" and "Other independent special school"), and its LA has a
|
||||||
|
DfE figure for the year the endpoint serves.
|
||||||
|
|
||||||
|
## Delivery
|
||||||
|
|
||||||
|
Two PRs, as for C1.
|
||||||
|
|
||||||
|
### PR 1: pipeline
|
||||||
|
|
||||||
|
- `pipeline/plugins/extractors/tap-uk-ees/tap_uk_ees/tap.py`: release
|
||||||
|
precedence, KS4 information renames, `ees_ks4_la` stream registered in
|
||||||
|
`discover_streams`, shared national/LA helper.
|
||||||
|
- `pipeline/transform/macros/safe_numeric.sql`: trailing `%`.
|
||||||
|
- `pipeline/transform/models/staging/`: source `raw.ees_ks4_la` and
|
||||||
|
`stg_ees_ks4_la` (view): `cast(old_la_code as integer) as la_code`,
|
||||||
|
`cast(time_period as integer) as year`, `la_name`, measures via
|
||||||
|
`safe_numeric`, named as in `stg_ees_ks4_national`.
|
||||||
|
- `pipeline/transform/models/marts/fact_ks4_la_averages.sql` (table): one row
|
||||||
|
per (`year`, `la_code`) with `la_name` and the columns of
|
||||||
|
`fact_ks4_national_averages`. Schema tests: unique (`year`, `la_code`);
|
||||||
|
`year`, `la_code` and `la_name` not null.
|
||||||
|
- Data tests in `pipeline/transform/tests/`:
|
||||||
|
- `assert_ks4_years_have_results`: every year in `stg_ees_ks4` has a non-null
|
||||||
|
Attainment 8 for at least 50% of its rows. DfE's files reach 82% each year;
|
||||||
|
2023/24 loads at 0% today. Pre-2019 years come from the legacy model and are
|
||||||
|
not tested.
|
||||||
|
- `assert_ks2_info_percentages_loaded`: for every year in `stg_ees_ks2` where
|
||||||
|
at least 1,000 rows have `total_pupils`, at least 90% of those rows have
|
||||||
|
`disadvantaged_pct`. DfE's files reach 96–97%. 2022/23 has no pupil counts
|
||||||
|
and is skipped.
|
||||||
|
- `assert_ks4_la_averages_cover_las`: the latest year in
|
||||||
|
`fact_ks4_la_averages` has at least 145 LAs (DfE: 152).
|
||||||
|
- `pipeline/dags/school_data_pipeline.py`: the annual EES build selects
|
||||||
|
`stg_ees_ks4_la+`.
|
||||||
|
- `docs/ARCHITECTURE.md`: LA averages come from DfE's data set.
|
||||||
|
|
||||||
|
### PR 2: backend and UI (after the EES DAG has run on PR 1)
|
||||||
|
|
||||||
|
- `backend/models.py`: `Ks4LaAverage` for `marts.fact_ks4_la_averages`.
|
||||||
|
- `backend/app.py` `/api/la-averages`: the year is the latest with any school
|
||||||
|
Attainment 8 (as now). It reads that year's rows from the mart and keys each
|
||||||
|
`attainment_8_score` by our LA name, through the `local_authority_code` →
|
||||||
|
`local_authority` pairs in the school data. The response shape is unchanged.
|
||||||
|
No rows for that year, a missing table or a query error give an empty map,
|
||||||
|
logged, never another year's figures and never a computed mean.
|
||||||
|
- `nextjs-app/lib/utils.ts`: `isIndependentSchool(school)`.
|
||||||
|
- `nextjs-app/components/SecondarySchoolRow.tsx` and
|
||||||
|
`nextjs-app/components/LeafletMapInner.tsx`: the rule in "Which schools get a
|
||||||
|
gap".
|
||||||
|
- `e2e/tests/journeys.spec.ts`: the two journeys under Testing.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
**Extractor (pytest, `pipeline/tests/`, new):**
|
||||||
|
|
||||||
|
- precedence: with the flag on, a year in a newer release is emitted once, from
|
||||||
|
the newer release; a year only an older release has is kept; with the flag
|
||||||
|
off, every row passes;
|
||||||
|
- releases arriving oldest first are still processed newest first;
|
||||||
|
- KS4 information: an old-format row yields `endks4_pupil_count`,
|
||||||
|
`ks2_scaledscore_average`, `progress8_banding` and the rest of the table;
|
||||||
|
- LA filter: a small CSV with national, regional, LA and sub-group rows yields
|
||||||
|
one row per LA and year, with the declared fields.
|
||||||
|
|
||||||
|
**dbt (local `pgserver`, as for C1):**
|
||||||
|
|
||||||
|
- unit test on `stg_ees_ks2`: `34%` → 34, `34` → 34, `c` → null;
|
||||||
|
- unit test on `stg_ees_ks4_la` or the mart: codes and years cast, measures
|
||||||
|
carried;
|
||||||
|
- the three data tests and the schema tests above;
|
||||||
|
- `pipeline/tests/test_dag_selectors.py` passes with the new selector.
|
||||||
|
|
||||||
|
**Backend (pytest):**
|
||||||
|
|
||||||
|
- the response gives the mart's figure where the fixture's plain mean differs;
|
||||||
|
- matching works by code when the mart's `la_name` differs from ours;
|
||||||
|
- a mart without the served year, and a missing table, give an empty map.
|
||||||
|
|
||||||
|
**Front end (Jest):**
|
||||||
|
|
||||||
|
- `isIndependentSchool` for "Other independent school", "Other independent
|
||||||
|
special school", "Academy converter" and null;
|
||||||
|
- `SecondarySchoolRow` and the map card show no gap for an independent school
|
||||||
|
and show one for a state school with an LA figure.
|
||||||
|
|
||||||
|
**E2E (`journeys.spec.ts`, PR 2):**
|
||||||
|
|
||||||
|
- C2: Bishop Stopford (137086) history shows 2023/24 Attainment 8 64.1 and
|
||||||
|
Progress 8 +1.02. These are final figures, so the journey stays stable.
|
||||||
|
- H2: a search returning an independent and a state secondary: the independent
|
||||||
|
row has no "vs LA avg", the state row has one. The exact gap is not asserted:
|
||||||
|
DfE's 2025/26 provisional KS4 data is due and would change it.
|
||||||
|
|
||||||
|
## Rollout and verification
|
||||||
|
|
||||||
|
1. PR 1 merges to staging. Tudor runs `school_data_annual_ees` on staging.
|
||||||
|
2. Through the staging API: Bishop Stopford 2023/24 Attainment 8 64.1 and
|
||||||
|
Progress 8 1.02; school 147411 2023/24 disadvantaged 34; the LA mart has 152
|
||||||
|
LAs for 2024/25. If a data test fails, the build stops before search sync;
|
||||||
|
investigate before going further.
|
||||||
|
3. PR 2 merges, so the post-merge E2E gate runs against loaded data.
|
||||||
|
4. Production, Tudor's decision, in order: promote PR 1, run the EES DAG on
|
||||||
|
production, promote PR 2. If PR 2 arrives first, the endpoint returns an
|
||||||
|
empty map and rows show no gap, never a wrong one.
|
||||||
|
5. Optional cleanup, in the PR 1 description for Tudor:
|
||||||
|
`delete from raw.ees_ks4_performance where time_period = '202324' and pupil_count is null`.
|
||||||
|
New-format rows always have `pupil_count` (suppressed values are `c` or `z`,
|
||||||
|
not null), so this removes exactly the old-label leftovers.
|
||||||
|
6. Validation on production against DfE's files: every listed school's 2023/24
|
||||||
|
Attainment 8, Progress 8 and English and maths figures match; the 2023/24 KS4
|
||||||
|
and KS2 information fields match; `/api/la-averages` equals DfE for all 152
|
||||||
|
LAs; independent rows show no gap. Then mark C2 and H2 resolved in the audit
|
||||||
|
report.
|
||||||
|
|
||||||
|
## Expected visible change
|
||||||
|
|
||||||
|
- Secondary history charts and tables run unbroken from 2022/23 to 2024/25, and
|
||||||
|
2023/24 Progress 8 appears for about 3,400 schools.
|
||||||
|
- 2023/24 school information (KS2 and KS4) fills in.
|
||||||
|
- "vs LA avg" drops for most state secondaries. In Kensington and Chelsea, a
|
||||||
|
school with Attainment 8 60.0 moves from +24.8 to +5.5.
|
||||||
|
- Independent schools and City of London schools show no LA gap.
|
||||||
|
|
||||||
|
## Risks
|
||||||
|
|
||||||
|
- **Data-test thresholds stop a good build.** They were set from DfE's own
|
||||||
|
files (82% and 96–97% against 50% and 90%). A failure means the data changed
|
||||||
|
shape, which is what they are for.
|
||||||
|
- **`safe_numeric` is shared by 14 models.** Values written as `n%` were null
|
||||||
|
and become numbers. No DfE column uses `%` for anything but a percentage.
|
||||||
|
The staging EES run is the check.
|
||||||
|
- **Precedence drops data an older release holds more completely.** It is
|
||||||
|
opt-in for KS4 results, where both files hold the same 57,090 2023/24 keys.
|
||||||
|
- **The fixed EES data-set id goes stale** when 2025/26 is published. The
|
||||||
|
endpoint's year check then gives no gap rather than a mismatched one.
|
||||||
+253
-12
@@ -53,7 +53,7 @@ async function settledScrollLeft(scroller: Locator): Promise<number> {
|
|||||||
* whatever primaries the environment holds.
|
* whatever primaries the environment holds.
|
||||||
*/
|
*/
|
||||||
async function twoPrimaryUrns(page: Page): Promise<[string, string]> {
|
async function twoPrimaryUrns(page: Page): Promise<[string, string]> {
|
||||||
const res = await page.request.get('/api/schools?search=primary&per_page=50');
|
const res = await page.request.get('/api/schools?search=primary&page_size=50');
|
||||||
expect(res.ok()).toBeTruthy();
|
expect(res.ok()).toBeTruthy();
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
const urns: string[] = (body.schools ?? [])
|
const urns: string[] = (body.schools ?? [])
|
||||||
@@ -66,7 +66,7 @@ async function twoPrimaryUrns(page: Page): Promise<[string, string]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function twoSecondaryUrns(page: Page): Promise<[string, string]> {
|
async function twoSecondaryUrns(page: Page): Promise<[string, string]> {
|
||||||
const res = await page.request.get('/api/schools?search=school&per_page=100');
|
const res = await page.request.get('/api/schools?search=school&page_size=100');
|
||||||
expect(res.ok()).toBeTruthy();
|
expect(res.ok()).toBeTruthy();
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
const urns: string[] = (body.schools ?? [])
|
const urns: string[] = (body.schools ?? [])
|
||||||
@@ -355,6 +355,133 @@ test('school type groups and the faith filter narrow to what they name', async (
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Search rows printed tags the register does not hold. Every non-selective
|
||||||
|
* secondary was "Selective" ("non-selective" contains "selective"), and a
|
||||||
|
* school with no religious character got "Faith priority" or a bare "None"
|
||||||
|
* chip, because only "Does not apply" was excluded. Data-invariant: each test
|
||||||
|
* picks its school from the API and reads only that school's row.
|
||||||
|
*/
|
||||||
|
async function rowTags(page: Page, school: { urn: number; school_name: string }) {
|
||||||
|
await searchByName(page, school.school_name);
|
||||||
|
const link = page.locator(`a[href^="/school/${school.urn}-"]`).first();
|
||||||
|
await expect(link).toBeVisible({ timeout: 15_000 });
|
||||||
|
return link.locator('xpath=ancestor::div[contains(@class, "__rowContent")][1]')
|
||||||
|
.locator('[class*="__line2"]');
|
||||||
|
}
|
||||||
|
|
||||||
|
test('a non-selective secondary is not tagged Selective in search', async ({ page }) => {
|
||||||
|
const res = await page.request.get(
|
||||||
|
'/api/schools?search=school&phase=secondary&admissions_policy=non-selective&page_size=1');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const [school] = (await res.json()).schools ?? [];
|
||||||
|
test.skip(!school, 'no non-selective secondary in this environment');
|
||||||
|
expect(school.admissions_policy, 'the admissions filter was ignored').toBe('Non-selective');
|
||||||
|
|
||||||
|
const tags = await rowTags(page, school);
|
||||||
|
await expect(tags).toBeVisible();
|
||||||
|
await expect(tags.getByText('Selective', { exact: true })).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a school with no religious character carries no faith tag in search', async ({ page }) => {
|
||||||
|
const res = await page.request.get('/api/schools?search=school&faith=none&page_size=100');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
// Not a selective school: the Selective tag would win and hide the bug.
|
||||||
|
const school = ((await res.json()).schools ?? []).find(
|
||||||
|
(s: { religious_denomination?: string; admissions_policy?: string }) =>
|
||||||
|
s.religious_denomination === 'None' && !/selective/i.test(s.admissions_policy ?? ''));
|
||||||
|
test.skip(!school, 'no school recorded with religious character "None" here');
|
||||||
|
|
||||||
|
const tags = await rowTags(page, school);
|
||||||
|
await expect(tags).toBeVisible();
|
||||||
|
await expect(tags.getByText('Faith priority', { exact: true })).toHaveCount(0);
|
||||||
|
await expect(tags.getByText('None', { exact: true })).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('search and the school page agree on how many pupils a secondary has', async ({ page }) => {
|
||||||
|
// Search showed the GCSE year group as "pupils": Burntwood had 245 in
|
||||||
|
// search and 1,462 on its page. Both now carry the register's count.
|
||||||
|
const res = await page.request.get('/api/schools?search=school&phase=secondary&page_size=20');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const school = ((await res.json()).schools ?? []).find(
|
||||||
|
(s: { total_pupils?: number | null }) => s.total_pupils != null);
|
||||||
|
test.skip(!school, 'no secondary with a pupil count in this environment');
|
||||||
|
const detail = await (await page.request.get(`/api/schools/${school.urn}`)).json();
|
||||||
|
expect(school.total_pupils).toBe(detail.school_info.total_pupils);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a secondary search row compares its Attainment 8 with the LA average', async ({ page }) => {
|
||||||
|
// The comparison vanished unnoticed: the averages were fetched with
|
||||||
|
// force-cache, so one stored failure hid it in that browser for good.
|
||||||
|
// Playwright disables the HTTP cache when it intercepts requests, so this
|
||||||
|
// guards the comparison itself; the unit test pins the cache mode.
|
||||||
|
const la = await (await page.request.get('/api/la-averages')).json();
|
||||||
|
const averages: Record<string, number> = la.secondary?.attainment_8_by_la ?? {};
|
||||||
|
// DfE publishes about 152 LA averages. An empty map (a missing mart, or a
|
||||||
|
// year the LA data set has not reached) hides every comparison: fail, not skip.
|
||||||
|
expect(Object.keys(averages).length).toBeGreaterThan(100);
|
||||||
|
const res = await page.request.get('/api/schools?search=school&phase=secondary&page_size=50');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const school = ((await res.json()).schools ?? []).find(
|
||||||
|
(s: { attainment_8_score?: number | null; local_authority?: string; school_type?: string }) =>
|
||||||
|
s.attainment_8_score != null && s.local_authority != null && averages[s.local_authority] != null
|
||||||
|
&& !/special|pupil referral|alternative provision|independent/i.test(s.school_type ?? ''));
|
||||||
|
test.skip(!school, 'no mainstream secondary with an LA average here');
|
||||||
|
|
||||||
|
await searchByName(page, school.school_name);
|
||||||
|
const link = page.locator(`a[href^="/school/${school.urn}-"]`).first();
|
||||||
|
await expect(link).toBeVisible({ timeout: 15_000 });
|
||||||
|
const stats = link.locator('xpath=ancestor::div[contains(@class, "__rowContent")][1]')
|
||||||
|
.locator('[class*="__line3"]');
|
||||||
|
await expect(stats.getByText(/vs LA avg/)).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an independent secondary shows its Attainment 8 without an LA comparison', async ({ page }) => {
|
||||||
|
// DfE's LA averages cover state-funded schools, and an independent school's
|
||||||
|
// Attainment 8 leaves out IGCSEs, so a gap would mislead (audit H2). A state
|
||||||
|
// school on the same page must show its gap first, so the absence is real.
|
||||||
|
const la = await (await page.request.get('/api/la-averages')).json();
|
||||||
|
const averages: Record<string, number> = la.secondary?.attainment_8_by_la ?? {};
|
||||||
|
expect(Object.keys(averages).length).toBeGreaterThan(100);
|
||||||
|
|
||||||
|
type Row = { urn: number; school_type?: string; local_authority?: string; attainment_8_score?: number | null };
|
||||||
|
const compared = (s: Row) => s.attainment_8_score != null && s.local_authority != null
|
||||||
|
&& averages[s.local_authority] != null
|
||||||
|
&& !/special|pupil referral|alternative provision/i.test(s.school_type ?? '');
|
||||||
|
let found: { la: string; state: Row; independent: Row } | null = null;
|
||||||
|
for (const name of ['Kensington and Chelsea', 'Westminster', 'Camden', 'Hammersmith and Fulham', 'Barnet']) {
|
||||||
|
// The search page asks for the same first 50 schools.
|
||||||
|
const res = await page.request.get(`/api/schools?search=${encodeURIComponent(name)}&phase=secondary&page_size=50`);
|
||||||
|
const schools: Row[] = ((await res.json()).schools ?? []).filter(compared);
|
||||||
|
const independent = schools.find(s => /independent/i.test(s.school_type ?? ''));
|
||||||
|
const state = schools.find(s => !/independent/i.test(s.school_type ?? ''));
|
||||||
|
if (independent && state) { found = { la: name, state, independent }; break; }
|
||||||
|
}
|
||||||
|
test.skip(!found, 'no LA here lists a state and an independent secondary on one page');
|
||||||
|
|
||||||
|
await page.goto(`/?search=${encodeURIComponent(found!.la)}&phase=secondary`);
|
||||||
|
const stats = (urn: number) => page.locator(`a[href^="/school/${urn}-"]`).first()
|
||||||
|
.locator('xpath=ancestor::div[contains(@class, "__rowContent")][1]')
|
||||||
|
.locator('[class*="__line3"]');
|
||||||
|
await expect(stats(found!.state.urn).getByText(/vs LA avg/)).toBeVisible({ timeout: 15_000 });
|
||||||
|
const independent = stats(found!.independent.urn);
|
||||||
|
await expect(independent.getByText(found!.independent.attainment_8_score!.toFixed(1))).toBeVisible();
|
||||||
|
await expect(independent.getByText(/vs LA avg/)).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a secondary shows its 2023/24 GCSE results, the last year DfE published Progress 8', async ({ page }) => {
|
||||||
|
// DfE re-issued its 2023/24 file under older column names, and every
|
||||||
|
// school's 2023/24 row loaded empty (audit C2). These are DfE's final
|
||||||
|
// figures for Bishop Stopford School, so they do not change.
|
||||||
|
await page.goto('/school/137086');
|
||||||
|
const history = page.locator('#history');
|
||||||
|
await history.getByText('View raw year-by-year data').click();
|
||||||
|
const row = history.getByRole('row', { name: /2023\/24/ });
|
||||||
|
await expect(row).toContainText('64.1');
|
||||||
|
await expect(row).toContainText('+1.0');
|
||||||
|
await expect(row).toContainText('91.7%');
|
||||||
|
});
|
||||||
|
|
||||||
test('a phase outside primary/secondary filters to that phase, not to everything', async ({ page }) => {
|
test('a phase outside primary/secondary filters to that phase, not to everything', async ({ page }) => {
|
||||||
// The search page offers every GIAS phase, but the API only knew the grouped
|
// The search page offers every GIAS phase, but the API only knew the grouped
|
||||||
// ones and silently dropped the rest — so "Nursery" returned primaries.
|
// ones and silently dropped the rest — so "Nursery" returned primaries.
|
||||||
@@ -396,6 +523,37 @@ test('a report-card school shows a Report Card badge in search results, not its
|
|||||||
await expect(page.getByText(/Report Card ·/).first()).toBeVisible();
|
await expect(page.getByText(/Report Card ·/).first()).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a school whose latest inspection gave no grade is not shown with an older grade', async ({ page }) => {
|
||||||
|
// Rabbsfarm (102408): Ofsted's 17 June 2025 inspection gave no overall
|
||||||
|
// grade and rated three areas Requires Improvement. The site used to carry
|
||||||
|
// a 2020 "remains Good" forward and print "Good · 2025" (audit C1).
|
||||||
|
const URN = 102408;
|
||||||
|
const res = await page.request.get(`/api/schools/${URN}`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const ofsted = (await res.json()).ofsted;
|
||||||
|
expect(ofsted.current_grade).toBeNull();
|
||||||
|
expect(ofsted.latest_visit.date).toBe('2025-06-17');
|
||||||
|
|
||||||
|
await searchByName(page, 'Rabbsfarm Primary');
|
||||||
|
const row = page.locator(`a[href*="${URN}"]`).first();
|
||||||
|
await expect(row).toBeVisible({ timeout: 15_000 });
|
||||||
|
await expect(page.getByText('Inspected · 2025').first()).toBeVisible();
|
||||||
|
await expect(page.getByText(/Good · 2025/)).toHaveCount(0);
|
||||||
|
|
||||||
|
await page.goto(`/school/${URN}`);
|
||||||
|
const section = page.locator('#ofsted');
|
||||||
|
await expect(section.getByText('No overall grade')).toBeVisible();
|
||||||
|
await expect(section.getByText('Requires Improvement').first()).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a grade confirmed at an ungraded visit says so and is dated by it', async ({ page }) => {
|
||||||
|
const URN = 104762; // Robins Lane: graded Good Jan 2020, "School remains Good" 18 July 2024
|
||||||
|
await page.goto(`/school/${URN}`);
|
||||||
|
const section = page.locator('#ofsted');
|
||||||
|
await expect(section).toBeVisible({ timeout: 15_000 });
|
||||||
|
await expect(section.getByText('Confirmed at an ungraded inspection, 18 July 2024')).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
test('school detail page renders name and performance data', async ({ page }) => {
|
test('school detail page renders name and performance data', async ({ page }) => {
|
||||||
await searchByName(page, 'primary');
|
await searchByName(page, 'primary');
|
||||||
const firstSchool = schoolLinks(page).first();
|
const firstSchool = schoolLinks(page).first();
|
||||||
@@ -432,9 +590,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 }) => {
|
||||||
@@ -544,7 +703,7 @@ test('school with no performance data still gets a working detail page', async (
|
|||||||
const candidates: number[] = [];
|
const candidates: number[] = [];
|
||||||
for (const q of ['post 16', 'specialist college', 'sixth form']) {
|
for (const q of ['post 16', 'specialist college', 'sixth form']) {
|
||||||
const resp = await page.request.get(
|
const resp = await page.request.get(
|
||||||
`/api/schools?search=${encodeURIComponent(q)}&per_page=20`
|
`/api/schools?search=${encodeURIComponent(q)}&page_size=20`
|
||||||
);
|
);
|
||||||
if (!resp.ok()) continue;
|
if (!resp.ok()) continue;
|
||||||
const body = await resp.json();
|
const body = await resp.json();
|
||||||
@@ -1123,7 +1282,7 @@ test('compare metric-help popover stays within the mobile viewport', async ({ pa
|
|||||||
test('admissions year/trend toggle still switches views after the server/client split', async ({ page }) => {
|
test('admissions year/trend toggle still switches views after the server/client split', async ({ page }) => {
|
||||||
// Find a school with at least two years carrying an offer rate — the toggle
|
// Find a school with at least two years carrying an offer rate — the toggle
|
||||||
// only appears then. Data-invariant: uses whatever the environment holds.
|
// only appears then. Data-invariant: uses whatever the environment holds.
|
||||||
const res = await page.request.get('/api/schools?search=primary&per_page=50');
|
const res = await page.request.get('/api/schools?search=primary&page_size=50');
|
||||||
expect(res.ok()).toBeTruthy();
|
expect(res.ok()).toBeTruthy();
|
||||||
const candidates: number[] = ((await res.json()).schools ?? []).map((s: { urn: number }) => s.urn);
|
const candidates: number[] = ((await res.json()).schools ?? []).map((s: { urn: number }) => s.urn);
|
||||||
|
|
||||||
@@ -2083,7 +2242,7 @@ test('English schools with Welsh postcodes are kept', async ({ page }) => {
|
|||||||
test('a Welsh school URL 404s while an English one still resolves', async ({ page }) => {
|
test('a Welsh school URL 404s while an English one still resolves', async ({ page }) => {
|
||||||
// Paired on purpose: the Welsh assertion alone would also pass if the whole
|
// Paired on purpose: the Welsh assertion alone would also pass if the whole
|
||||||
// site were down, which is the failure this test most needs to distinguish.
|
// site were down, which is the failure this test most needs to distinguish.
|
||||||
const english = await page.request.get('/api/schools?search=primary&per_page=1');
|
const english = await page.request.get('/api/schools?search=primary&page_size=1');
|
||||||
expect(english.ok()).toBeTruthy();
|
expect(english.ok()).toBeTruthy();
|
||||||
const [first] = (await english.json()).schools ?? [];
|
const [first] = (await english.json()).schools ?? [];
|
||||||
expect(first, 'no English school available to compare against').toBeTruthy();
|
expect(first, 'no English school available to compare against').toBeTruthy();
|
||||||
@@ -2193,7 +2352,7 @@ test('a filtered homepage still canonicalises to the bare root', async ({ page }
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('a school page canonicalises to its own slug on the www host', async ({ page }) => {
|
test('a school page canonicalises to its own slug on the www host', async ({ page }) => {
|
||||||
const res = await page.request.get('/api/schools?search=primary&per_page=1');
|
const res = await page.request.get('/api/schools?search=primary&page_size=1');
|
||||||
expect(res.ok()).toBeTruthy();
|
expect(res.ok()).toBeTruthy();
|
||||||
const [first] = (await res.json()).schools ?? [];
|
const [first] = (await res.json()).schools ?? [];
|
||||||
expect(first, 'no school available').toBeTruthy();
|
expect(first, 'no school available').toBeTruthy();
|
||||||
@@ -2268,7 +2427,7 @@ function blocksEverything(robots: string, agent: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test('a school page on staging is noindexed too, not just the homepage', async ({ page }) => {
|
test('a school page on staging is noindexed too, not just the homepage', async ({ page }) => {
|
||||||
const list = await page.request.get('/api/schools?search=primary&per_page=1');
|
const list = await page.request.get('/api/schools?search=primary&page_size=1');
|
||||||
const [first] = (await list.json()).schools ?? [];
|
const [first] = (await list.json()).schools ?? [];
|
||||||
expect(first, 'no school available').toBeTruthy();
|
expect(first, 'no school available').toBeTruthy();
|
||||||
|
|
||||||
@@ -2879,7 +3038,7 @@ test('with autosuggest off, the search box is a plain input', async ({ page }) =
|
|||||||
async function secondaryWithDestinations(page: Page): Promise<{
|
async function secondaryWithDestinations(page: Page): Promise<{
|
||||||
urn: string; destinations: any;
|
urn: string; destinations: any;
|
||||||
}> {
|
}> {
|
||||||
const res = await page.request.get('/api/schools?search=school&per_page=100');
|
const res = await page.request.get('/api/schools?search=school&page_size=100');
|
||||||
expect(res.ok()).toBeTruthy();
|
expect(res.ok()).toBeTruthy();
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
const urns: string[] = (body.schools ?? [])
|
const urns: string[] = (body.schools ?? [])
|
||||||
@@ -2975,7 +3134,7 @@ test('switching to disadvantaged pupils never reveals a withheld figure', async
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('a school with no sixth form has no post-16 destinations section', async ({ page }) => {
|
test('a school with no sixth form has no post-16 destinations section', async ({ page }) => {
|
||||||
const res = await page.request.get('/api/schools?search=school&per_page=100');
|
const res = await page.request.get('/api/schools?search=school&page_size=100');
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
const noSixthForm = (body.schools ?? [])
|
const noSixthForm = (body.schools ?? [])
|
||||||
.filter((s: { phase?: string; has_sixth_form?: boolean }) =>
|
.filter((s: { phase?: string; has_sixth_form?: boolean }) =>
|
||||||
@@ -3286,3 +3445,85 @@ for (const width of [360, 390, 430]) {
|
|||||||
expect(failing).toEqual([]);
|
expect(failing).toEqual([]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The header's facts row read GIAS text as booleans: "Not applicable" put a
|
||||||
|
* "Nursery" chip on secondaries aged 11–18, and "Girls" became "Girls's
|
||||||
|
* school". Data-invariant: the chip follows whatever the API says.
|
||||||
|
*/
|
||||||
|
test('a girls\' secondary header names it properly and shows Nursery only when it has one', async ({ page }) => {
|
||||||
|
const res = await page.request.get('/api/schools?search=school&phase=secondary&gender=girls&page_size=1');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const [school] = (await res.json()).schools ?? [];
|
||||||
|
test.skip(!school, 'no girls\' secondary in this environment');
|
||||||
|
expect(school.gender, 'the gender filter was ignored').toBe('Girls');
|
||||||
|
const detail = await (await page.request.get(`/api/schools/${school.urn}`)).json();
|
||||||
|
// Without the field, the Nursery assertion below would pass vacuously.
|
||||||
|
expect(detail.school_info).toHaveProperty('nursery_provision');
|
||||||
|
|
||||||
|
await page.goto(`/school/${school.urn}`);
|
||||||
|
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(/'s school/)).toHaveCount(0);
|
||||||
|
await expect(header.getByText('Nursery class', { exact: true }))
|
||||||
|
.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);
|
||||||
|
});
|
||||||
@@ -33,18 +33,26 @@ function ofsted(partial: Partial<OfstedInspection>): OfstedInspection {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const schools = [school(1, 'Graded School'), school(2, 'Carried School'), school(3, 'Card School')];
|
const schools = [school(1, 'Graded School'), school(2, 'Confirmed School'), school(3, 'Card School')];
|
||||||
|
|
||||||
const data: Record<string, ComparisonData> = {
|
const data: Record<string, ComparisonData> = {
|
||||||
'1': {
|
'1': {
|
||||||
school_info: schools[0],
|
school_info: schools[0],
|
||||||
yearly_data: [],
|
yearly_data: [],
|
||||||
ofsted: ofsted({ overall_effectiveness: 1, grade_source: 'graded' }),
|
ofsted: ofsted({
|
||||||
|
overall_effectiveness: 1,
|
||||||
|
current_grade: { grade: 1, date: '2021-10-07', basis: 'graded' },
|
||||||
|
latest_visit: { date: '2021-10-07', kind: 'graded', outcome: null },
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
'2': {
|
'2': {
|
||||||
school_info: schools[1],
|
school_info: schools[1],
|
||||||
yearly_data: [],
|
yearly_data: [],
|
||||||
ofsted: ofsted({ overall_effectiveness: 2, grade_source: 'ungraded_carried_forward' }),
|
ofsted: ofsted({
|
||||||
|
overall_effectiveness: 2,
|
||||||
|
current_grade: { grade: 2, date: '2023-03-14', basis: 'confirmed' },
|
||||||
|
latest_visit: { date: '2023-03-14', kind: 'ungraded', outcome: 'School remains Good' },
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
'3': {
|
'3': {
|
||||||
school_info: schools[2],
|
school_info: schools[2],
|
||||||
@@ -65,9 +73,9 @@ describe('CompareOfsted', () => {
|
|||||||
render(<CompareOfsted schools={schools} data={data} />);
|
render(<CompareOfsted schools={schools} data={data} />);
|
||||||
|
|
||||||
expect(screen.getByText('Outstanding')).toBeInTheDocument();
|
expect(screen.getByText('Outstanding')).toBeInTheDocument();
|
||||||
// Carried-forward grade is shown but marked as such
|
// A grade confirmed at an ungraded visit says so, with that visit's date
|
||||||
expect(screen.getByText('Good')).toBeInTheDocument();
|
expect(screen.getByText('Good')).toBeInTheDocument();
|
||||||
expect(screen.getByText(/carried forward/i)).toBeInTheDocument();
|
expect(screen.getByText('Confirmed at an ungraded inspection, 14 March 2023')).toBeInTheDocument();
|
||||||
// Report card: label present, no overall-grade badge for that school
|
// Report card: label present, no overall-grade badge for that school
|
||||||
expect(screen.getByText('Report card')).toBeInTheDocument();
|
expect(screen.getByText('Report card')).toBeInTheDocument();
|
||||||
expect(screen.getByText(/no overall grade/i)).toBeInTheDocument();
|
expect(screen.getByText(/no overall grade/i)).toBeInTheDocument();
|
||||||
@@ -104,7 +112,7 @@ describe('CompareOfsted', () => {
|
|||||||
yearly_data: [],
|
yearly_data: [],
|
||||||
ofsted: ofsted({
|
ofsted: ofsted({
|
||||||
overall_effectiveness: 2,
|
overall_effectiveness: 2,
|
||||||
grade_source: 'graded',
|
current_grade: { grade: 2, date: '2021-10-07', basis: 'graded' },
|
||||||
quality_of_education: 1,
|
quality_of_education: 1,
|
||||||
early_years_provision: 9,
|
early_years_provision: 9,
|
||||||
sixth_form_provision: 2,
|
sixth_form_provision: 2,
|
||||||
@@ -167,4 +175,26 @@ describe('CompareOfsted', () => {
|
|||||||
expect(screen.getAllByText('Graded').length).toBe(4);
|
expect(screen.getAllByText('Graded').length).toBe(4);
|
||||||
expect(screen.getAllByText('Card').length).toBe(4);
|
expect(screen.getAllByText('Card').length).toBe(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('dates "Inspected" by the latest visit, not the graded inspection (Washwood Heath)', () => {
|
||||||
|
const s1 = school(7, 'Washwood Heath Academy');
|
||||||
|
render(<CompareOfsted schools={[s1]} data={{ '7': { school_info: s1, yearly_data: [], ofsted: ofsted({
|
||||||
|
inspection_date: '2020-03-03', overall_effectiveness: 2, quality_of_education: 2,
|
||||||
|
current_grade: { grade: 2, date: '2020-03-03', basis: 'graded' },
|
||||||
|
latest_visit: { date: '2025-05-21', kind: 'ungraded', outcome: 'Standards maintained' },
|
||||||
|
}) } }} />);
|
||||||
|
expect(screen.getByText(/21 May 2025/)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('4+ years ago')).not.toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Graded inspection, 3 March 2020')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows no overall grade after a no-grade inspection (Rabbsfarm)', () => {
|
||||||
|
const s1 = school(8, 'Rabbsfarm Primary School');
|
||||||
|
render(<CompareOfsted schools={[s1]} data={{ '8': { school_info: s1, yearly_data: [], ofsted: ofsted({
|
||||||
|
inspection_date: '2025-06-17', quality_of_education: 3,
|
||||||
|
current_grade: null, latest_visit: { date: '2025-06-17', kind: 'graded', outcome: null },
|
||||||
|
}) } }} />);
|
||||||
|
expect(screen.getAllByText('No overall grade').length).toBeGreaterThan(0);
|
||||||
|
expect(screen.queryByText('Good')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { act, fireEvent, render, screen } from '@testing-library/react';
|
import { act, fireEvent, render, screen } from '@testing-library/react';
|
||||||
import { HomeView } from '@/components/HomeView';
|
import { HomeView } from '@/components/HomeView';
|
||||||
import { fetchSchools } from '@/lib/api';
|
import { fetchLAaverages, fetchSchools } from '@/lib/api';
|
||||||
import { primaryFixture } from '../support/schoolFixtures';
|
import { primaryFixture } from '../support/schoolFixtures';
|
||||||
import type { SchoolsResponse, School } from '@/lib/types';
|
import type { SchoolsResponse, School } from '@/lib/types';
|
||||||
|
|
||||||
@@ -84,3 +84,23 @@ test('failed map requests can be retried by reopening the map', async () => {
|
|||||||
expect(fetchSchools).toHaveBeenCalledTimes(2);
|
expect(fetchSchools).toHaveBeenCalledTimes(2);
|
||||||
expect(screen.getByTestId('map')).toHaveTextContent('Retry result');
|
expect(screen.getByTestId('map')).toHaveTextContent('Retry result');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('LA averages are not fetched with force-cache, so one failure is not replayed for good', async () => {
|
||||||
|
// force-cache serves any stored response, however old, without asking the
|
||||||
|
// server. A request that failed once (a staging deploy restart, the July
|
||||||
|
// proxy outage) was stored and replayed on every later visit, and the
|
||||||
|
// "vs LA avg" delta vanished from every secondary row in that browser.
|
||||||
|
// The default mode honours the API's Cache-Control and never reuses an
|
||||||
|
// error.
|
||||||
|
params = new URLSearchParams('search=high');
|
||||||
|
const secondary: SchoolsResponse = {
|
||||||
|
...response('Alpha High'),
|
||||||
|
schools: [{ ...primaryFixture.schoolInfo, school_name: 'Alpha High', phase: 'Secondary', attainment_8_score: 50 }],
|
||||||
|
};
|
||||||
|
render(<HomeView initialSchools={secondary} filters={filters} />);
|
||||||
|
await act(async () => {});
|
||||||
|
expect(fetchLAaverages).toHaveBeenCalled();
|
||||||
|
for (const [options] of jest.mocked(fetchLAaverages).mock.calls) {
|
||||||
|
expect(options?.cache).not.toBe('force-cache');
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -105,3 +105,20 @@ it('puts the card back when the pins are rebuilt for a reason other than the sch
|
|||||||
expect(container.querySelector('.sc-popup')).toHaveTextContent('Southmead Primary School');
|
expect(container.querySelector('.sc-popup')).toHaveTextContent('Southmead Primary School');
|
||||||
expect(container.querySelectorAll('.sc-pin--selected')).toHaveLength(1);
|
expect(container.querySelectorAll('.sc-pin--selected')).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('compares a state secondary with its LA average on the card, but not an independent one', () => {
|
||||||
|
const state: School = { ...base, urn: 3, school_name: 'Holland Park School', school_type: 'Academy converter',
|
||||||
|
phase: 'Secondary', local_authority: 'Kensington and Chelsea', attainment_8_score: 60,
|
||||||
|
latitude: 51.5, longitude: -0.2, distance: 0.3 };
|
||||||
|
const independent: School = { ...state, urn: 4, school_name: 'Abbey Gate College',
|
||||||
|
school_type: 'Other independent school', attainment_8_score: 20.4 };
|
||||||
|
const laAverages = { 'Kensington and Chelsea': 54.5 };
|
||||||
|
|
||||||
|
const { container, rerender } = renderMap({ schools: [state, independent], laAverages, selectedUrn: 3 });
|
||||||
|
expect(container.querySelector('.sc-popup')).toHaveTextContent('60.0 Att 8 +5.5 vs LA');
|
||||||
|
|
||||||
|
rerender({ schools: [state, independent], laAverages, selectedUrn: 4 });
|
||||||
|
const card = container.querySelector('.sc-popup')!;
|
||||||
|
expect(card).toHaveTextContent('20.4 Att 8');
|
||||||
|
expect(card).not.toHaveTextContent(/vs LA/);
|
||||||
|
});
|
||||||
@@ -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' })]);
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import { OfstedSection } from '@/components/school/OfstedSection';
|
||||||
|
import { ofstedLegacyAreas } from '@/lib/utils';
|
||||||
|
import type { OfstedInspection } from '@/lib/types';
|
||||||
|
|
||||||
|
const empty = {
|
||||||
|
framework: null, inspection_date: null, inspection_type: null, overall_effectiveness: null,
|
||||||
|
quality_of_education: null, behaviour_attitudes: null, personal_development: null,
|
||||||
|
leadership_management: null, early_years_provision: null, sixth_form_provision: null,
|
||||||
|
previous_overall: null, rc_safeguarding_met: null, rc_inclusion: null, rc_curriculum_teaching: null,
|
||||||
|
rc_achievement: null, rc_attendance_behaviour: null, rc_personal_development: null,
|
||||||
|
rc_leadership_governance: null, rc_early_years: null, rc_sixth_form: null, report_url: null,
|
||||||
|
report_card: {},
|
||||||
|
} as OfstedInspection;
|
||||||
|
|
||||||
|
// `page` mimics how each school page used to mount the section; the secondary
|
||||||
|
// page's branch hard-coded four areas and dropped the sixth form (audit M2).
|
||||||
|
function renderSection(o: Partial<OfstedInspection>, page: Record<string, unknown> = {}) {
|
||||||
|
const ofsted = { ...empty, ...o } as OfstedInspection;
|
||||||
|
render(
|
||||||
|
<OfstedSection
|
||||||
|
{...page}
|
||||||
|
ofsted={ofsted}
|
||||||
|
urn={1}
|
||||||
|
isReportCard={false}
|
||||||
|
ofstedInspectedDate={ofsted.latest_visit?.date ?? null}
|
||||||
|
oeifAllSameGrade={false}
|
||||||
|
oeifAreas={ofstedLegacyAreas(ofsted)}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
it('shows no overall grade, not an older one, after a no-grade inspection (Rabbsfarm)', () => {
|
||||||
|
renderSection({
|
||||||
|
inspection_date: '2025-06-17', quality_of_education: 3, behaviour_attitudes: 3,
|
||||||
|
personal_development: 2, leadership_management: 3, early_years_provision: 2,
|
||||||
|
current_grade: null, latest_visit: { date: '2025-06-17', kind: 'graded', outcome: null },
|
||||||
|
});
|
||||||
|
expect(screen.getByText(/Inspected 17 June 2025/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('No overall grade')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Good', { selector: 'span' })).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Not rated')).not.toBeInTheDocument();
|
||||||
|
expect(screen.getAllByText('Requires Improvement')).toHaveLength(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the sixth-form judgement when there is no overall grade (audit M2)', () => {
|
||||||
|
renderSection({
|
||||||
|
inspection_date: '2025-04-01', quality_of_education: 1, behaviour_attitudes: 1,
|
||||||
|
personal_development: 1, leadership_management: 1, sixth_form_provision: 2,
|
||||||
|
current_grade: null, latest_visit: { date: '2025-04-01', kind: 'graded', outcome: null },
|
||||||
|
}, { variant: 'secondary' });
|
||||||
|
expect(screen.getByText(/sixth form/i)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Good')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('dates a grade by its source and prints a later visit separately (Washwood Heath)', () => {
|
||||||
|
renderSection({
|
||||||
|
inspection_date: '2020-03-03', overall_effectiveness: 2, quality_of_education: 2,
|
||||||
|
current_grade: { grade: 2, date: '2020-03-03', basis: 'graded' },
|
||||||
|
latest_visit: { date: '2025-05-21', kind: 'ungraded', outcome: 'Standards maintained' },
|
||||||
|
});
|
||||||
|
expect(screen.getByText(/Inspected 21 May 2025/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Graded inspection, 3 March 2020')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/Latest visit: Ungraded inspection, 21 May 2025: Standards maintained/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('says a grade was confirmed at an ungraded visit (Robins Lane)', () => {
|
||||||
|
renderSection({
|
||||||
|
inspection_date: '2020-01-07', overall_effectiveness: 2,
|
||||||
|
current_grade: { grade: 2, date: '2024-07-18', basis: 'confirmed' },
|
||||||
|
latest_visit: { date: '2024-07-18', kind: 'ungraded', outcome: 'School remains Good' },
|
||||||
|
});
|
||||||
|
expect(screen.getByText('Confirmed at an ungraded inspection, 18 July 2024')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/Latest visit/)).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prints an ungraded outcome when there is no grade (Oakgrove)', () => {
|
||||||
|
renderSection({
|
||||||
|
current_grade: null,
|
||||||
|
latest_visit: { date: '2024-11-13', kind: 'ungraded', outcome: 'Standards maintained' },
|
||||||
|
});
|
||||||
|
expect(screen.getByText('No overall grade')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/Ungraded inspection, 13 November 2024: Standards maintained/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
@@ -361,12 +361,12 @@ describe('PlaceView school attributes', () => {
|
|||||||
{ urn: 1, school_name: 'Alpha Primary', phase: 'Primary',
|
{ urn: 1, school_name: 'Alpha Primary', phase: 'Primary',
|
||||||
rwm_expected_pct: 82, attainment_8_score: null,
|
rwm_expected_pct: 82, attainment_8_score: null,
|
||||||
age_range: '4-11', religious_denomination: 'Church of England',
|
age_range: '4-11', religious_denomination: 'Church of England',
|
||||||
nursery_provision: true,
|
nursery_provision: 'Has Nursery Classes',
|
||||||
parliamentary_constituency: 'Chelmsford' } as never,
|
parliamentary_constituency: 'Chelmsford' } as never,
|
||||||
{ urn: 2, school_name: 'Beta High', phase: 'Secondary',
|
{ urn: 2, school_name: 'Beta High', phase: 'Secondary',
|
||||||
rwm_expected_pct: null, attainment_8_score: 47,
|
rwm_expected_pct: null, attainment_8_score: 47,
|
||||||
age_range: '11-16', religious_denomination: 'Does not apply',
|
age_range: '11-16', religious_denomination: 'Does not apply',
|
||||||
nursery_provision: false,
|
nursery_provision: 'No Nursery Classes',
|
||||||
parliamentary_constituency: 'Witham' } as never,
|
parliamentary_constituency: 'Witham' } as never,
|
||||||
],
|
],
|
||||||
averages: { rwm_expected_pct: 63, attainment_8_score: 45 },
|
averages: { rwm_expected_pct: 63, attainment_8_score: 45 },
|
||||||
@@ -459,6 +459,18 @@ describe('PlaceView school attributes', () => {
|
|||||||
expect(cells.slice(2)).toEqual(['—', '—', '—', '—']);
|
expect(cells.slice(2)).toEqual(['—', '—', '—', '—']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('reads "Not applicable" as no nursery, not as a yes', () => {
|
||||||
|
// GIAS sends text. Tested for truthiness, every value was a "Yes".
|
||||||
|
const notApplicable: PlaceDetail = {
|
||||||
|
...withAttributes,
|
||||||
|
schools: [{ urn: 5, school_name: 'Epsilon Primary', phase: 'Primary',
|
||||||
|
rwm_expected_pct: 70, nursery_provision: 'Not applicable' } as never],
|
||||||
|
};
|
||||||
|
const { container } = render(<PlaceView detail={notApplicable} phase="primary"
|
||||||
|
englandAverage={61} neighbours={[]} />);
|
||||||
|
expect(container.querySelector('tbody')!.textContent).not.toContain('Yes');
|
||||||
|
});
|
||||||
|
|
||||||
it('gives an all-through school its nursery under primary only', () => {
|
it('gives an all-through school its nursery under primary only', () => {
|
||||||
// All-through schools render in both groups. Nursery belongs to the
|
// All-through schools render in both groups. Nursery belongs to the
|
||||||
// primary reading of the same school, not the secondary one.
|
// primary reading of the same school, not the secondary one.
|
||||||
@@ -467,7 +479,7 @@ describe('PlaceView school attributes', () => {
|
|||||||
schools: [{ urn: 4, school_name: 'Delta Academy', phase: 'All-through',
|
schools: [{ urn: 4, school_name: 'Delta Academy', phase: 'All-through',
|
||||||
rwm_expected_pct: 66, attainment_8_score: 51,
|
rwm_expected_pct: 66, attainment_8_score: 51,
|
||||||
age_range: '4-18', religious_denomination: 'None',
|
age_range: '4-18', religious_denomination: 'None',
|
||||||
nursery_provision: true,
|
nursery_provision: 'Has Nursery Classes',
|
||||||
parliamentary_constituency: 'Chelmsford' } as never],
|
parliamentary_constituency: 'Chelmsford' } as never],
|
||||||
};
|
};
|
||||||
const { container } = render(<PlaceView detail={allThrough}
|
const { container } = render(<PlaceView detail={allThrough}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/**
|
||||||
|
* SchoolRow (primary search results): line 2 prints the religious character
|
||||||
|
* only when the school has one. The register's "None" was printed as a chip.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import '@testing-library/jest-dom';
|
||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
import { SchoolRow } from '@/components/SchoolRow';
|
||||||
|
import type { School } from '@/lib/types';
|
||||||
|
|
||||||
|
const base = {
|
||||||
|
urn: 100001,
|
||||||
|
school_name: 'Alpha Primary School',
|
||||||
|
local_authority: 'Testshire',
|
||||||
|
school_type: 'Free schools',
|
||||||
|
phase: 'Primary',
|
||||||
|
gender: 'Mixed',
|
||||||
|
age_range: '4-11',
|
||||||
|
rwm_expected_pct: 70,
|
||||||
|
} as unknown as School;
|
||||||
|
|
||||||
|
describe('SchoolRow religious character', () => {
|
||||||
|
it.each(['None', 'Does not apply', ''])(
|
||||||
|
'prints nothing when the register says %p',
|
||||||
|
(religious_denomination) => {
|
||||||
|
render(<SchoolRow school={{ ...base, religious_denomination }} />);
|
||||||
|
expect(screen.queryByText('None')).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Does not apply')).not.toBeInTheDocument();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it('prints a religious character the school has', () => {
|
||||||
|
render(<SchoolRow school={{ ...base, religious_denomination: 'Church of England' }} />);
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -65,3 +65,89 @@ describe('SecondarySchoolRow proposed-to-close tag', () => {
|
|||||||
expect(screen.queryByText(/Proposed to close/)).not.toBeInTheDocument();
|
expect(screen.queryByText(/Proposed to close/)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('SecondarySchoolRow admissions tag', () => {
|
||||||
|
it('tags a selective school', () => {
|
||||||
|
render(<SecondarySchoolRow school={{ ...base, admissions_policy: 'Selective' }} />);
|
||||||
|
expect(screen.getByText('Selective')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not tag a non-selective school as selective', () => {
|
||||||
|
// "Non-selective" contains "selective": a substring test tagged every
|
||||||
|
// comprehensive (Burntwood, Graveney) as Selective.
|
||||||
|
render(<SecondarySchoolRow school={{ ...base, admissions_policy: 'Non-selective' }} />);
|
||||||
|
expect(screen.queryByText('Selective')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(['None', 'Does not apply'])(
|
||||||
|
'gives no faith tag when the religious character is %p',
|
||||||
|
(religious_denomination) => {
|
||||||
|
render(
|
||||||
|
<SecondarySchoolRow
|
||||||
|
school={{ ...base, admissions_policy: 'Not applicable', religious_denomination }}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(screen.queryByText(religious_denomination)).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('Faith priority')).not.toBeInTheDocument();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it('tags the religious character the register records, not "Faith priority"', () => {
|
||||||
|
render(
|
||||||
|
<SecondarySchoolRow
|
||||||
|
school={{ ...base, admissions_policy: 'Not applicable', religious_denomination: 'Church of England' }}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('SecondarySchoolRow LA comparison', () => {
|
||||||
|
it('compares a state school with its LA average', () => {
|
||||||
|
render(
|
||||||
|
<SecondarySchoolRow
|
||||||
|
school={{ ...base, school_type: 'Academy converter', attainment_8_score: 60 }}
|
||||||
|
laAvgAttainment8={54.5}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(screen.getByText(/\+5\.5 vs LA avg/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the comparison for a school whose type is unknown', () => {
|
||||||
|
render(
|
||||||
|
<SecondarySchoolRow
|
||||||
|
school={{ ...base, school_type: null, attainment_8_score: 60 } as unknown as School}
|
||||||
|
laAvgAttainment8={54.5}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(screen.getByText(/\+5\.5 vs LA avg/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows an independent school's Attainment 8 without an LA comparison", () => {
|
||||||
|
// DfE's LA average covers state-funded schools; an independent's
|
||||||
|
// Attainment 8 leaves out IGCSEs (audit H2).
|
||||||
|
render(
|
||||||
|
<SecondarySchoolRow
|
||||||
|
school={{ ...base, school_type: 'Other independent school', attainment_8_score: 20.4 }}
|
||||||
|
laAvgAttainment8={54.5}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
expect(screen.getByText('20.4')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/vs LA avg/)).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
/**
|
||||||
|
* 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",
|
||||||
|
* "No Nursery Classes" or "Not applicable". Tested for truthiness, every one
|
||||||
|
* of those read as a nursery, so secondaries aged 11–18 showed "Nursery".
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { screen, within } from '@testing-library/react';
|
||||||
|
import type { School } from '@/lib/types';
|
||||||
|
import { primaryFixture, secondaryFixture } from '../support/schoolFixtures';
|
||||||
|
import { renderSchoolDetail, 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/SatsChart', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: () => <div data-testid="sats-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 withSchool<T extends { schoolInfo: School }>(fixture: T, info: Partial<School>): T {
|
||||||
|
return { ...fixture, schoolInfo: { ...fixture.schoolInfo, ...info } };
|
||||||
|
}
|
||||||
|
|
||||||
|
const flagList = () => screen.queryByRole('list', { name: 'Admission and provision' });
|
||||||
|
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' }));
|
||||||
|
expect(flagLabels()).toEqual(['Nursery class']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(['No Nursery Classes', 'Not applicable', null])(
|
||||||
|
'shows no nursery flag when GIAS says %p',
|
||||||
|
(value) => {
|
||||||
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, { nursery_provision: value }));
|
||||||
|
expect(screen.queryByText(/^Nursery/)).not.toBeInTheDocument();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it.each([['Girls', "Girls' school"], ['Boys', "Boys' school"]])(
|
||||||
|
'labels a %s school with a plural possessive',
|
||||||
|
(gender, label) => {
|
||||||
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, { gender }));
|
||||||
|
expect(screen.getByText(label)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/'s school/)).not.toBeInTheDocument();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it('says nothing for a mixed school', () => {
|
||||||
|
renderSecondarySchoolDetail(withSchool(secondaryFixture, { gender: 'Mixed' }));
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
* "Pupils" on a school page is the size of the school.
|
||||||
|
*
|
||||||
|
* A year's results row carries the cohort its figures were measured on. For a
|
||||||
|
* secondary that is the GCSE year group alone (Burntwood: 245, against 1,462
|
||||||
|
* on roll), so it must never stand in for the whole-school count.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { screen } from '@testing-library/react';
|
||||||
|
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/SatsChart', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: () => <div data-testid="sats-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 withoutCensus(schoolTotal: number | null) {
|
||||||
|
const yearlyData = secondaryFixture.yearlyData.map((r) => ({ ...r, total_pupils: 245 }));
|
||||||
|
return {
|
||||||
|
...secondaryFixture,
|
||||||
|
census: null,
|
||||||
|
yearlyData,
|
||||||
|
schoolInfo: { ...secondaryFixture.schoolInfo, total_pupils: schoolTotal },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('pupil count without a census record', () => {
|
||||||
|
it('uses the register count in the header, not the results cohort', () => {
|
||||||
|
renderSecondarySchoolDetail(withoutCensus(1462));
|
||||||
|
expect(screen.getByText('1,462 pupils')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('245 pupils')).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows no count rather than the results cohort when the register has none', () => {
|
||||||
|
renderSecondarySchoolDetail(withoutCensus(null));
|
||||||
|
expect(screen.queryByText(/^[\d,]+ 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -114,16 +114,13 @@ describe('ofstedDisplay', () => {
|
|||||||
expect(d.kind).toBe('report_card');
|
expect(d.kind).toBe('report_card');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('distinguishes graded from carried-forward grades', () => {
|
it('distinguishes a graded grade from a confirmed one', () => {
|
||||||
const graded = ofstedDisplay(
|
expect(ofstedDisplay(ofsted({ current_grade: { grade: 1, date: '2019-10-09', basis: 'graded' },
|
||||||
ofsted({ overall_effectiveness: 1, grade_source: 'graded' }),
|
latest_visit: { date: '2025-02-05', kind: 'ungraded', outcome: 'Some aspects not as strong' } })))
|
||||||
);
|
.toMatchObject({ kind: 'graded', gradeLabel: 'Outstanding', gradeDate: '2019-10-09' });
|
||||||
expect(graded).toMatchObject({ kind: 'graded', gradeLabel: 'Outstanding', carriedForward: false });
|
expect(ofstedDisplay(ofsted({ current_grade: { grade: 2, date: '2024-07-18', basis: 'confirmed' },
|
||||||
|
latest_visit: { date: '2024-07-18', kind: 'ungraded', outcome: 'School remains Good' } })))
|
||||||
const carried = ofstedDisplay(
|
.toMatchObject({ kind: 'confirmed', gradeLabel: 'Good' });
|
||||||
ofsted({ overall_effectiveness: 2, grade_source: 'ungraded_carried_forward' }),
|
|
||||||
);
|
|
||||||
expect(carried).toMatchObject({ kind: 'carried_forward', gradeLabel: 'Good', carriedForward: true });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles missing data', () => {
|
it('handles missing data', () => {
|
||||||
@@ -131,11 +128,11 @@ describe('ofstedDisplay', () => {
|
|||||||
expect(ofstedDisplay(ofsted({})).kind).toBe('none');
|
expect(ofstedDisplay(ofsted({})).kind).toBe('none');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('identifies transitional inspections without overall grades', () => {
|
it('has no overall grade when the latest inspection gave none', () => {
|
||||||
const transitional = ofstedDisplay(
|
// Rabbsfarm: the graded inspection's own overall is null, so no grade is
|
||||||
ofsted({ overall_effectiveness: null, inspection_date: '2024-11-05' }),
|
// in force even though an older ungraded visit said "remains Good".
|
||||||
);
|
expect(ofstedDisplay(ofsted({ current_grade: null, overall_effectiveness: null,
|
||||||
expect(transitional.kind).toBe('transitional');
|
latest_visit: { date: '2025-06-17', kind: 'graded', outcome: null } })).kind).toBe('no_overall_grade');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses the four legacy grade words', () => {
|
it('uses the four legacy grade words', () => {
|
||||||
|
|||||||
@@ -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,47 @@
|
|||||||
|
import { gradeSourceLine, latestVisitLine, showLatestVisitLine } from '@/lib/ofstedStatus';
|
||||||
|
import type { OfstedInspection } from '@/lib/types';
|
||||||
|
|
||||||
|
const base = { report_card: {} } as unknown as OfstedInspection;
|
||||||
|
|
||||||
|
describe('gradeSourceLine', () => {
|
||||||
|
it('names the graded inspection and its date', () => {
|
||||||
|
expect(gradeSourceLine({ grade: 2, date: '2016-07-06', basis: 'graded' }))
|
||||||
|
.toBe('Graded inspection, 6 July 2016');
|
||||||
|
});
|
||||||
|
it('names the ungraded visit that confirmed it', () => {
|
||||||
|
expect(gradeSourceLine({ grade: 2, date: '2023-03-14', basis: 'confirmed' }))
|
||||||
|
.toBe('Confirmed at an ungraded inspection, 14 March 2023');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('latestVisitLine', () => {
|
||||||
|
it('prints the ungraded outcome', () => {
|
||||||
|
expect(latestVisitLine({ date: '2024-11-13', kind: 'ungraded', outcome: 'Standards maintained' }))
|
||||||
|
.toBe('Ungraded inspection, 13 November 2024: Standards maintained');
|
||||||
|
});
|
||||||
|
it('prints a graded visit without an outcome', () => {
|
||||||
|
expect(latestVisitLine({ date: '2025-06-17', kind: 'graded', outcome: null }))
|
||||||
|
.toBe('Graded inspection, 17 June 2025');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('showLatestVisitLine', () => {
|
||||||
|
it('shows a later visit than the one the grade came from', () => {
|
||||||
|
expect(showLatestVisitLine({ ...base,
|
||||||
|
current_grade: { grade: 2, date: '2020-03-03', basis: 'graded' },
|
||||||
|
latest_visit: { date: '2025-05-21', kind: 'ungraded', outcome: 'Standards maintained' } })).toBe(true);
|
||||||
|
});
|
||||||
|
it('hides it when the visit is the grade’s own source', () => {
|
||||||
|
expect(showLatestVisitLine({ ...base,
|
||||||
|
current_grade: { grade: 2, date: '2024-07-18', basis: 'confirmed' },
|
||||||
|
latest_visit: { date: '2024-07-18', kind: 'ungraded', outcome: 'School remains Good' } })).toBe(false);
|
||||||
|
});
|
||||||
|
it('shows an ungraded outcome when there is no grade', () => {
|
||||||
|
expect(showLatestVisitLine({ ...base, current_grade: null,
|
||||||
|
latest_visit: { date: '2024-11-13', kind: 'ungraded', outcome: 'Standards maintained' } })).toBe(true);
|
||||||
|
});
|
||||||
|
it('hides it for a graded visit with no grade (the title already dates it)', () => {
|
||||||
|
expect(showLatestVisitLine({ ...base, current_grade: null,
|
||||||
|
latest_visit: { date: '2025-06-17', kind: 'graded', outcome: null } })).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -15,6 +15,8 @@ import {
|
|||||||
computeYBounds,
|
computeYBounds,
|
||||||
formatAgeRange,
|
formatAgeRange,
|
||||||
formatAgeSpan,
|
formatAgeSpan,
|
||||||
|
hasNurseryClasses,
|
||||||
|
singleSexLabel,
|
||||||
} from '@/lib/utils';
|
} from '@/lib/utils';
|
||||||
|
|
||||||
describe('formatPercentage', () => {
|
describe('formatPercentage', () => {
|
||||||
@@ -145,23 +147,37 @@ describe('ofstedLegacyAreas', () => {
|
|||||||
|
|
||||||
describe('buildOfstedListBadge', () => {
|
describe('buildOfstedListBadge', () => {
|
||||||
it('returns grade word + year for OEIF Outstanding', () => {
|
it('returns grade word + year for OEIF Outstanding', () => {
|
||||||
const badge = buildOfstedListBadge({ ofsted_grade: 1, ofsted_date: '2023-11-15', ofsted_framework: 'OEIF' });
|
const badge = buildOfstedListBadge({ ofsted_grade: 1, ofsted_grade_date: '2023-11-15', ofsted_date: '2023-11-15', ofsted_framework: 'OEIF' });
|
||||||
expect(badge.label).toBe('Outstanding · 2023');
|
expect(badge.label).toBe('Outstanding · 2023');
|
||||||
expect(badge.cssClass).toBe('ofsted1');
|
expect(badge.cssClass).toBe('ofsted1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns grade word for each OEIF grade', () => {
|
it('returns grade word for each OEIF grade', () => {
|
||||||
expect(buildOfstedListBadge({ ofsted_grade: 2, ofsted_date: '2022-05-01' }).label).toBe('Good · 2022');
|
expect(buildOfstedListBadge({ ofsted_grade: 2, ofsted_grade_date: '2022-05-01' }).label).toBe('Good · 2022');
|
||||||
expect(buildOfstedListBadge({ ofsted_grade: 3, ofsted_date: '2021-01-01' }).label).toBe('Req. Improvement · 2021');
|
expect(buildOfstedListBadge({ ofsted_grade: 3, ofsted_grade_date: '2021-01-01' }).label).toBe('Req. Improvement · 2021');
|
||||||
expect(buildOfstedListBadge({ ofsted_grade: 4, ofsted_date: '2020-03-01' }).label).toBe('Inadequate · 2020');
|
expect(buildOfstedListBadge({ ofsted_grade: 4, ofsted_grade_date: '2020-03-01' }).label).toBe('Inadequate · 2020');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns grade word without year when date is missing', () => {
|
it('prints a grade without a year when its date is missing', () => {
|
||||||
const badge = buildOfstedListBadge({ ofsted_grade: 2, ofsted_date: null });
|
const badge = buildOfstedListBadge({ ofsted_grade: 2, ofsted_grade_date: null, ofsted_date: '2025-01-01' });
|
||||||
expect(badge.label).toBe('Good');
|
expect(badge.label).toBe('Good');
|
||||||
expect(badge.cssClass).toBe('ofsted2');
|
expect(badge.cssClass).toBe('ofsted2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('dates a grade by the inspection that awarded it, not the latest visit', () => {
|
||||||
|
// Washwood Heath: Good from a March 2020 graded inspection; latest visit
|
||||||
|
// an ungraded one in May 2025 (audit M1).
|
||||||
|
const badge = buildOfstedListBadge({ ofsted_grade: 2, ofsted_grade_date: '2020-03-03', ofsted_date: '2025-05-21' });
|
||||||
|
expect(badge.label).toBe('Good · 2020');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows Inspected for a latest inspection that gave no grade (Rabbsfarm)', () => {
|
||||||
|
// Audit C1: this used to read "Good · 2025", from a 2020 ungraded visit.
|
||||||
|
const badge = buildOfstedListBadge({ ofsted_grade: null, ofsted_grade_date: null, ofsted_date: '2025-06-17' });
|
||||||
|
expect(badge.label).toBe('Inspected · 2025');
|
||||||
|
expect(badge.cssClass).toBe('ofstedInspected');
|
||||||
|
});
|
||||||
|
|
||||||
it('returns a Report Card badge when ofsted_rc_date is present', () => {
|
it('returns a Report Card badge when ofsted_rc_date is present', () => {
|
||||||
const badge = buildOfstedListBadge({ ofsted_grade: null, ofsted_rc_date: '2026-02-03' });
|
const badge = buildOfstedListBadge({ ofsted_grade: null, ofsted_rc_date: '2026-02-03' });
|
||||||
expect(badge.label).toBe('Report Card · 2026');
|
expect(badge.label).toBe('Report Card · 2026');
|
||||||
@@ -346,3 +362,49 @@ describe('formatAgeRange', () => {
|
|||||||
expect(formatAgeRange('4-11')).toBe('Ages 4–11');
|
expect(formatAgeRange('4-11')).toBe('Ages 4–11');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('hasNurseryClasses', () => {
|
||||||
|
it('is true only for the GIAS value that means it', () => {
|
||||||
|
// GIAS sends text, and two of its three values mean no nursery.
|
||||||
|
expect(hasNurseryClasses('Has Nursery Classes')).toBe(true);
|
||||||
|
expect(hasNurseryClasses('No Nursery Classes')).toBe(false);
|
||||||
|
expect(hasNurseryClasses('Not applicable')).toBe(false);
|
||||||
|
expect(hasNurseryClasses(null)).toBe(false);
|
||||||
|
expect(hasNurseryClasses(undefined)).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('singleSexLabel', () => {
|
||||||
|
it('uses the plural possessive GIAS values need', () => {
|
||||||
|
expect(singleSexLabel('Girls')).toBe("Girls' school");
|
||||||
|
expect(singleSexLabel('Boys')).toBe("Boys' school");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores case, as hasNurseryClasses does', () => {
|
||||||
|
expect(singleSexLabel(' girls ')).toBe("Girls' school");
|
||||||
|
expect(singleSexLabel('BOYS')).toBe("Boys' school");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns null for a mixed or unknown school', () => {
|
||||||
|
expect(singleSexLabel('Mixed')).toBeNull();
|
||||||
|
expect(singleSexLabel(null)).toBeNull();
|
||||||
|
expect(singleSexLabel(undefined)).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isIndependentSchool', () => {
|
||||||
|
const { isIndependentSchool } = require('@/lib/utils');
|
||||||
|
|
||||||
|
it('matches both GIAS independent types', () => {
|
||||||
|
expect(isIndependentSchool({ school_type: 'Other independent school' })).toBe(true);
|
||||||
|
expect(isIndependentSchool({ school_type: 'Other independent special school' })).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not match state-funded types or a missing type', () => {
|
||||||
|
for (const t of ['Academy converter', 'Community school', 'Free schools', 'Non-maintained special school']) {
|
||||||
|
expect(isIndependentSchool({ school_type: t })).toBe(false);
|
||||||
|
}
|
||||||
|
expect(isIndependentSchool({ school_type: null })).toBe(false);
|
||||||
|
expect(isIndependentSchool({})).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -39,7 +39,6 @@ export function renderSchoolDetail(fixture: any) {
|
|||||||
withProviders(
|
withProviders(
|
||||||
<SchoolDetailShell
|
<SchoolDetailShell
|
||||||
schoolInfo={fixture.schoolInfo}
|
schoolInfo={fixture.schoolInfo}
|
||||||
yearlyData={fixture.yearlyData}
|
|
||||||
census={fixture.census}
|
census={fixture.census}
|
||||||
navItems={navItems}
|
navItems={navItems}
|
||||||
>
|
>
|
||||||
@@ -67,7 +66,6 @@ export function renderSecondarySchoolDetail(fixture: any) {
|
|||||||
withProviders(
|
withProviders(
|
||||||
<SchoolDetailShell
|
<SchoolDetailShell
|
||||||
schoolInfo={fixture.schoolInfo}
|
schoolInfo={fixture.schoolInfo}
|
||||||
yearlyData={fixture.yearlyData}
|
|
||||||
census={fixture.census}
|
census={fixture.census}
|
||||||
navItems={navItems}
|
navItems={navItems}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -191,7 +191,8 @@ export const primaryFixture = {
|
|||||||
personal_development: 2,
|
personal_development: 2,
|
||||||
leadership_management: 2,
|
leadership_management: 2,
|
||||||
previous_overall: 3,
|
previous_overall: 3,
|
||||||
grade_source: 'graded',
|
current_grade: { grade: 2, date: '2023-05-17', basis: 'graded' },
|
||||||
|
latest_visit: { date: '2023-05-17', kind: 'graded', outcome: null },
|
||||||
}),
|
}),
|
||||||
census,
|
census,
|
||||||
admissions: makeAdmissions({ year: 2024 }),
|
admissions: makeAdmissions({ year: 2024 }),
|
||||||
@@ -295,7 +296,8 @@ export const allThroughFixture = {
|
|||||||
behaviour_attitudes: 1,
|
behaviour_attitudes: 1,
|
||||||
personal_development: 1,
|
personal_development: 1,
|
||||||
leadership_management: 1,
|
leadership_management: 1,
|
||||||
grade_source: 'graded',
|
current_grade: { grade: 1, date: '2022-10-04', basis: 'graded' },
|
||||||
|
latest_visit: { date: '2022-10-04', kind: 'graded', outcome: null },
|
||||||
}),
|
}),
|
||||||
census,
|
census,
|
||||||
admissions: makeAdmissions({ year: 2024, school_phase: 'Secondary' }),
|
admissions: makeAdmissions({ year: 2024, school_phase: 'Secondary' }),
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ export default async function SchoolPage({ params }: SchoolPageProps) {
|
|||||||
{isSecondary ? (
|
{isSecondary ? (
|
||||||
<SchoolDetailShell
|
<SchoolDetailShell
|
||||||
schoolInfo={school_info}
|
schoolInfo={school_info}
|
||||||
yearlyData={yearly_data}
|
|
||||||
census={census ?? null}
|
census={census ?? null}
|
||||||
navItems={secondaryNavItems}
|
navItems={secondaryNavItems}
|
||||||
>
|
>
|
||||||
@@ -273,7 +272,6 @@ export default async function SchoolPage({ params }: SchoolPageProps) {
|
|||||||
) : (
|
) : (
|
||||||
<SchoolDetailShell
|
<SchoolDetailShell
|
||||||
schoolInfo={school_info}
|
schoolInfo={school_info}
|
||||||
yearlyData={yearly_data}
|
|
||||||
census={census ?? null}
|
census={census ?? null}
|
||||||
navItems={primaryNavItems}
|
navItems={primaryNavItems}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -358,10 +358,14 @@ export function HomeView({ initialSchools, filters, totalSchools, howItWorks, ed
|
|||||||
return () => controller.abort();
|
return () => controller.abort();
|
||||||
}, [resultsView, searchParams, initialSchools.schools]);
|
}, [resultsView, searchParams, initialSchools.schools]);
|
||||||
|
|
||||||
// Fetch LA averages when secondary or mixed schools are visible
|
// Fetch LA averages when secondary or mixed schools are visible. Default
|
||||||
|
// cache mode, never force-cache: force-cache replays any stored response
|
||||||
|
// without asking the server, so one failed request (a deploy restart) hid
|
||||||
|
// every "vs LA avg" delta in that browser for good. The API's Cache-Control
|
||||||
|
// already lets the browser reuse a good answer for five minutes.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isSecondaryView && !isMixedView) return;
|
if (!isSecondaryView && !isMixedView) return;
|
||||||
fetchLAaverages({ cache: 'force-cache' })
|
fetchLAaverages()
|
||||||
.then(data => setLaAverages(data.secondary.attainment_8_by_la))
|
.then(data => setLaAverages(data.secondary.attainment_8_by_la))
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, [isSecondaryView, isMixedView]);
|
}, [isSecondaryView, isMixedView]);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { useEffect, useRef, useState } from 'react';
|
|||||||
import L from 'leaflet';
|
import L from 'leaflet';
|
||||||
import 'leaflet/dist/leaflet.css';
|
import 'leaflet/dist/leaflet.css';
|
||||||
import type { School } from '@/lib/types';
|
import type { School } from '@/lib/types';
|
||||||
import { schoolUrl, isSpecialSchool, buildOfstedListBadge, listRwmValue } from '@/lib/utils';
|
import { schoolUrl, isSpecialSchool, isIndependentSchool, buildOfstedListBadge, listRwmValue } from '@/lib/utils';
|
||||||
|
|
||||||
interface LeafletMapInnerProps {
|
interface LeafletMapInnerProps {
|
||||||
schools: School[];
|
schools: School[];
|
||||||
@@ -70,7 +70,7 @@ function metricHtml(school: School, { nationalAvgRwm, laAverages }: CardContext)
|
|||||||
const score = school.attainment_8_score;
|
const score = school.attainment_8_score;
|
||||||
const laAvg = school.local_authority ? (laAverages?.[school.local_authority] ?? null) : null;
|
const laAvg = school.local_authority ? (laAverages?.[school.local_authority] ?? null) : null;
|
||||||
let delta = '';
|
let delta = '';
|
||||||
if (!special && laAvg != null) {
|
if (!special && !isIndependentSchool(school) && laAvg != null) {
|
||||||
const diff = Math.round((score - laAvg) * 10) / 10;
|
const diff = Math.round((score - laAvg) * 10) / 10;
|
||||||
// Att8 runs 0–90 in 0.1 steps; ±0.5 is meaningful, where RWM needs ±2.
|
// Att8 runs 0–90 in 0.1 steps; ±0.5 is meaningful, where RWM needs ±2.
|
||||||
const cls = diff >= 0.5 ? 'sc-up' : diff <= -0.5 ? 'sc-down' : '';
|
const cls = diff >= 0.5 ? 'sc-up' : diff <= -0.5 ? 'sc-down' : '';
|
||||||
|
|||||||
@@ -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, 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,10 +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 =
|
const flags = schoolFlags(school);
|
||||||
school.religious_denomination &&
|
|
||||||
school.religious_denomination !== 'Does not apply';
|
|
||||||
|
|
||||||
// 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
|
||||||
@@ -79,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, isProposedToClose, isSpecialSchool } from '@/lib/utils';
|
import { buildOfstedListBadge, getPhaseStyle, schoolUrl, formatAgeRange, isProposedToClose, isSpecialSchool, isIndependentSchool } 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 {
|
|
||||||
const policy = school.admissions_policy?.toLowerCase() ?? '';
|
|
||||||
if (policy.includes('selective')) return 'Selective';
|
|
||||||
const denom = school.religious_denomination ?? '';
|
|
||||||
if (denom && denom !== 'Does not apply') 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;
|
||||||
@@ -57,16 +45,17 @@ export function SecondarySchoolRow({
|
|||||||
const att8 = school.attainment_8_score;
|
const att8 = school.attainment_8_score;
|
||||||
// The school's own Attainment 8 is a same-school figure — shown whenever it
|
// The school's own Attainment 8 is a same-school figure — shown whenever it
|
||||||
// exists (special schools included; their type tag on line 2 gives context).
|
// exists (special schools included; their type tag on line 2 gives context).
|
||||||
// Only the vs-LA-average delta, a benchmark comparison, is dropped for
|
// Only the vs-LA-average delta, a benchmark comparison, is dropped: for
|
||||||
// special schools / PRUs / AP, whose pupils aren't measured against it fairly.
|
// special schools / PRUs / AP, whose pupils aren't measured against it
|
||||||
|
// fairly, and for independent schools, because DfE's LA average covers
|
||||||
|
// state-funded schools and an independent's Attainment 8 leaves out IGCSEs.
|
||||||
const laDelta =
|
const laDelta =
|
||||||
att8 != null && !isSpecialSchool(school) && laAvgAttainment8 != null
|
att8 != null && !isSpecialSchool(school) && !isIndependentSchool(school) && laAvgAttainment8 != null
|
||||||
? 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 +79,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>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -78,21 +78,18 @@ export function CompareAtAGlance({
|
|||||||
return (
|
return (
|
||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
{display.kind === 'report_card' && <ReportCardChips summary={display.summary} />}
|
{display.kind === 'report_card' && <ReportCardChips summary={display.summary} />}
|
||||||
{(display.kind === 'graded' || display.kind === 'carried_forward') && (
|
{(display.kind === 'graded' || display.kind === 'confirmed') && (
|
||||||
<>
|
<>
|
||||||
<span className={`${s.badge} ${display.grade <= 2 ? s.badgeGood : display.grade === 3 ? s.badgeWarn : s.badgeBad}`}>
|
<span className={`${s.badge} ${display.grade <= 2 ? s.badgeGood : display.grade === 3 ? s.badgeWarn : s.badgeBad}`}>
|
||||||
{display.gradeLabel}
|
{display.gradeLabel}
|
||||||
</span>
|
</span>
|
||||||
{display.carriedForward && <span className={s.small}>Grade carried forward</span>}
|
{display.kind === 'confirmed' && <span className={s.small}>Confirmed at an ungraded inspection</span>}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{display.kind === 'transitional' && (
|
{display.kind === 'no_overall_grade' && (
|
||||||
<>
|
<span className={s.badge} style={{ backgroundColor: 'var(--bg-secondary)', color: 'var(--text-secondary)' }}>
|
||||||
<span className={s.badge} style={{ backgroundColor: 'var(--bg-secondary)', color: 'var(--text-secondary)' }}>
|
No overall grade
|
||||||
No overall grade
|
</span>
|
||||||
</span>
|
|
||||||
<span className={s.small}>Sub-judgements only</span>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
{display.kind === 'none' && <span className={s.small}>No inspection in our dataset</span>}
|
{display.kind === 'none' && <span className={s.small}>No inspection in our dataset</span>}
|
||||||
</Cell>
|
</Cell>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Ofsted section — one visual grammar for inspection detail across all
|
* Ofsted section — one visual grammar for inspection detail across all
|
||||||
* three regimes (legacy graded, interim carried-forward, renewed-framework
|
* three regimes (legacy graded, no overall grade, renewed-framework report
|
||||||
* report card). Copy comes verbatim from the reviewed mockups.
|
* card). The grade shown is the one still in force, with the inspection that
|
||||||
|
* awarded or confirmed it; "Inspected" is the latest visit.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
@@ -12,7 +13,8 @@ import {
|
|||||||
rcAreaLabel,
|
rcAreaLabel,
|
||||||
type OfstedDisplay,
|
type OfstedDisplay,
|
||||||
} from '@/lib/compareLogic';
|
} from '@/lib/compareLogic';
|
||||||
import type { ComparisonData, OfstedInspection, School } from '@/lib/types';
|
import { gradeSourceLine } from '@/lib/ofstedStatus';
|
||||||
|
import type { ComparisonData, OfstedCurrentGrade, OfstedInspection, School } from '@/lib/types';
|
||||||
import { Cell, Chip, Measure, Section, SectionGrid, sectionStyles as s } from './sectionShared';
|
import { Cell, Chip, Measure, Section, SectionGrid, sectionStyles as s } from './sectionShared';
|
||||||
|
|
||||||
const GRADE_TONE: Record<number, 'good' | 'warn' | 'bad'> = {
|
const GRADE_TONE: Record<number, 'good' | 'warn' | 'bad'> = {
|
||||||
@@ -39,7 +41,7 @@ function yearsSince(iso: string | null): number | null {
|
|||||||
return (Date.now() - d.getTime()) / (365.25 * 24 * 3600 * 1000);
|
return (Date.now() - d.getTime()) / (365.25 * 24 * 3600 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ResultCell({ display }: { display: OfstedDisplay }) {
|
function ResultCell({ display, current }: { display: OfstedDisplay; current: OfstedCurrentGrade | null }) {
|
||||||
if (display.kind === 'none') {
|
if (display.kind === 'none') {
|
||||||
return <span className={s.small}>No inspection outcome in our dataset</span>;
|
return <span className={s.small}>No inspection outcome in our dataset</span>;
|
||||||
}
|
}
|
||||||
@@ -51,15 +53,13 @@ function ResultCell({ display }: { display: OfstedDisplay }) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (display.kind === 'transitional') {
|
if (display.kind === 'no_overall_grade') {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<span className={s.badge} style={{ backgroundColor: 'var(--bg-secondary)', color: 'var(--text-secondary)' }}>
|
<span className={s.badge} style={{ backgroundColor: 'var(--bg-secondary)', color: 'var(--text-secondary)' }}>
|
||||||
No overall grade
|
No overall grade
|
||||||
</span>
|
</span>
|
||||||
<span className={s.small}>
|
<span className={s.small}>Ofsted stopped giving overall grades in September 2024</span>
|
||||||
Inspected under transitional framework (sub-judgements only)
|
|
||||||
</span>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -68,11 +68,7 @@ function ResultCell({ display }: { display: OfstedDisplay }) {
|
|||||||
<span className={`${s.badge} ${display.grade <= 2 ? s.badgeGood : display.grade === 3 ? s.badgeWarn : s.badgeBad}`}>
|
<span className={`${s.badge} ${display.grade <= 2 ? s.badgeGood : display.grade === 3 ? s.badgeWarn : s.badgeBad}`}>
|
||||||
{display.gradeLabel}
|
{display.gradeLabel}
|
||||||
</span>
|
</span>
|
||||||
<span className={s.small}>
|
{current && <span className={s.small}>{gradeSourceLine(current)}</span>}
|
||||||
{display.carriedForward
|
|
||||||
? 'Grade carried forward from an earlier inspection (ungraded visit since)'
|
|
||||||
: 'Overall grade (older-style inspection)'}
|
|
||||||
</span>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -179,7 +175,7 @@ export function CompareOfsted({
|
|||||||
<Measure label="Result">
|
<Measure label="Result">
|
||||||
{schools.map((school, i) => (
|
{schools.map((school, i) => (
|
||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
<ResultCell display={displays[i]} />
|
<ResultCell display={displays[i]} current={data[String(school.urn)]?.ofsted?.current_grade ?? null} />
|
||||||
</Cell>
|
</Cell>
|
||||||
))}
|
))}
|
||||||
</Measure>
|
</Measure>
|
||||||
@@ -187,19 +183,15 @@ export function CompareOfsted({
|
|||||||
<Measure label="Inspected">
|
<Measure label="Inspected">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const ofsted = data[String(school.urn)]?.ofsted;
|
const ofsted = data[String(school.urn)]?.ofsted;
|
||||||
// A report card is dated by its OWN inspection date. The legacy
|
// The school's latest visit of any kind (a report card's own date
|
||||||
// inspection_date belongs to an older inspection and must never
|
// when there is one), never an older inspection a grade comes from.
|
||||||
// be shown against a report card (report cards exist only from
|
const dateIso = ofsted?.latest_visit?.date ?? ofsted?.rc_inspection_date ?? null;
|
||||||
// Nov 2025).
|
|
||||||
const dateIso =
|
|
||||||
displays[i].kind === 'report_card'
|
|
||||||
? ofsted?.rc_inspection_date ?? null
|
|
||||||
: ofsted?.inspection_date ?? null;
|
|
||||||
const age = yearsSince(dateIso);
|
const age = yearsSince(dateIso);
|
||||||
return (
|
return (
|
||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
{formatInspectionDate(dateIso)}{' '}
|
{formatInspectionDate(dateIso)}{' '}
|
||||||
{age != null && age > 4 && <Chip tone="neutral">4+ years ago</Chip>}
|
{age != null && age > 4 && <Chip tone="neutral">4+ years ago</Chip>}
|
||||||
|
{ofsted?.latest_visit?.outcome && <span className={s.small}>{ofsted.latest_visit.outcome}</span>}
|
||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import Link from 'next/link';
|
|||||||
import type { PlaceDetail, PlaceSummary } from '@/lib/places';
|
import type { PlaceDetail, PlaceSummary } from '@/lib/places';
|
||||||
import { placeUrl, authoritySlug } from '@/lib/places';
|
import { placeUrl, authoritySlug } from '@/lib/places';
|
||||||
import type { School } from '@/lib/types';
|
import type { School } from '@/lib/types';
|
||||||
import { schoolUrl, formatAgeSpan } from '@/lib/utils';
|
import { schoolUrl, formatAgeSpan, hasNurseryClasses } from '@/lib/utils';
|
||||||
import { absoluteUrl } from '@/lib/site';
|
import { absoluteUrl } from '@/lib/site';
|
||||||
import { TrackPlaceView } from './TrackPlaceView';
|
import { TrackPlaceView } from './TrackPlaceView';
|
||||||
import styles from './PlaceView.module.css';
|
import styles from './PlaceView.module.css';
|
||||||
@@ -131,9 +131,10 @@ function SchoolTable({ schools, phase }: { schools: School[]; phase: PhaseKey })
|
|||||||
{showNursery && (
|
{showNursery && (
|
||||||
<td className={styles.attr}>
|
<td className={styles.attr}>
|
||||||
{/* Undefined is a mart the pipeline has not rebuilt, and
|
{/* Undefined is a mart the pipeline has not rebuilt, and
|
||||||
false is a school without one. Neither is a "Yes", and
|
"No Nursery Classes" or "Not applicable" is a school
|
||||||
neither is worth two different words. */}
|
without one. None is a "Yes", and none is worth a
|
||||||
{s.nursery_provision ? 'Yes' : NO_VALUE}
|
different word. */}
|
||||||
|
{hasNurseryClasses(s.nursery_provision) ? 'Yes' : NO_VALUE}
|
||||||
</td>
|
</td>
|
||||||
)}
|
)}
|
||||||
<td className={styles.attrWide}>
|
<td className={styles.attrWide}>
|
||||||
|
|||||||
@@ -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) => (
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
/**
|
/**
|
||||||
* OfstedSection — shared between the primary and secondary detail pages.
|
* OfstedSection — shared between the primary and secondary detail pages.
|
||||||
*
|
*
|
||||||
* The two versions were ~80% identical, but that figure masked a real fork in
|
* The headline is the school's current Ofsted status (backend:
|
||||||
* the no-overall-grade case: the primary page shows a "Not rated" badge, while
|
* fact_ofsted_latest): the report card; or the overall grade still in force,
|
||||||
* the secondary page shows a four-area OEIF panel. The disclaimer copy also
|
* with the inspection that awarded or confirmed it; or "No overall grade".
|
||||||
* differs slightly. Both are preserved exactly via the `variant` prop rather
|
* A later visit that is not the grade's source gets its own line. Both pages
|
||||||
* than reconciled, because this refactor must not change either page. Merging
|
* render the same branches, so neither drops an area judgement (audit M2).
|
||||||
* them is a follow-up decision for a human, not a side effect of a move.
|
* Rule: docs/superpowers/specs/2026-10-05-ofsted-current-status-design.md
|
||||||
*
|
*
|
||||||
* Server component.
|
* Server component.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { ofstedDisplay } from '@/lib/compareLogic';
|
||||||
|
import { formatOfstedDate, gradeSourceLine, latestVisitLine, showLatestVisitLine } from '@/lib/ofstedStatus';
|
||||||
import type { OfstedInspection } from '@/lib/types';
|
import type { OfstedInspection } from '@/lib/types';
|
||||||
import { Section, sectionStyles as styles } from './sectionShared';
|
import { Section, sectionStyles as styles } from './sectionShared';
|
||||||
|
|
||||||
@@ -40,14 +42,13 @@ export interface OfstedSectionProps {
|
|||||||
ofstedInspectedDate: string | null;
|
ofstedInspectedDate: string | null;
|
||||||
oeifAllSameGrade: boolean;
|
oeifAllSameGrade: boolean;
|
||||||
oeifAreas: { label: string; value: number }[];
|
oeifAreas: { label: string; value: number }[];
|
||||||
variant?: 'primary' | 'secondary';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function OfstedSection({
|
export function OfstedSection({
|
||||||
ofsted, urn, isReportCard, ofstedInspectedDate,
|
ofsted, urn, isReportCard, ofstedInspectedDate,
|
||||||
oeifAllSameGrade, oeifAreas, variant = 'primary',
|
oeifAllSameGrade, oeifAreas,
|
||||||
}: OfstedSectionProps) {
|
}: OfstedSectionProps) {
|
||||||
const isSecondary = variant === 'secondary';
|
const display = ofstedDisplay(ofsted);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section id="ofsted">
|
<Section id="ofsted">
|
||||||
@@ -55,7 +56,7 @@ export function OfstedSection({
|
|||||||
{isReportCard ? 'Ofsted Report Card' : 'Ofsted Rating'}
|
{isReportCard ? 'Ofsted Report Card' : 'Ofsted Rating'}
|
||||||
{ofstedInspectedDate && (
|
{ofstedInspectedDate && (
|
||||||
<span className={styles.ofstedDate}>
|
<span className={styles.ofstedDate}>
|
||||||
{isSecondary && ' '}Inspected {new Date(ofstedInspectedDate).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' })}
|
Inspected {new Date(ofstedInspectedDate).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' })}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<a
|
<a
|
||||||
@@ -98,65 +99,55 @@ export function OfstedSection({
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
) : (!isSecondary || ofsted.overall_effectiveness) ? (
|
) : (
|
||||||
/* ── Old OEIF layout ── */
|
|
||||||
<>
|
<>
|
||||||
<div className={styles.ofstedHeader}>
|
<div className={styles.ofstedHeader}>
|
||||||
<span className={`${styles.ofstedGrade} ${styles[`ofstedGrade${ofsted.overall_effectiveness}`]}`}>
|
{display.kind === 'graded' || display.kind === 'confirmed' ? (
|
||||||
{ofsted.overall_effectiveness ? OFSTED_LABELS[ofsted.overall_effectiveness] : 'Not rated'}
|
<>
|
||||||
</span>
|
<span className={`${styles.ofstedGrade} ${styles[`ofstedGrade${display.grade}`]}`}>
|
||||||
{ofsted.previous_overall != null &&
|
{display.gradeLabel}
|
||||||
ofsted.previous_overall !== ofsted.overall_effectiveness && (
|
</span>
|
||||||
<span className={styles.ofstedPrevious}>
|
{ofsted.previous_overall != null && ofsted.previous_overall !== display.grade && (
|
||||||
Previously: {OFSTED_LABELS[ofsted.previous_overall]}
|
<span className={styles.ofstedPrevious}>
|
||||||
</span>
|
Previously: {OFSTED_LABELS[ofsted.previous_overall]}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className={styles.ofstedGrade}>No overall grade</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className={styles.ofstedDisclaimer}>
|
<p className={styles.ofstedDisclaimer}>
|
||||||
{ofsted.grade_source === 'ungraded_carried_forward'
|
{ofsted.current_grade
|
||||||
? 'This overall grade is carried forward from an earlier inspection. Ofsted has since visited without issuing a new overall grade. From September 2024, Ofsted no longer makes an overall effectiveness judgement.'
|
? gradeSourceLine(ofsted.current_grade)
|
||||||
: isSecondary
|
: 'Ofsted stopped giving overall grades in September 2024.'}
|
||||||
? 'From September 2024, Ofsted no longer makes an overall effectiveness judgement in inspections.'
|
|
||||||
: 'From September 2024, Ofsted no longer makes an overall effectiveness judgement in inspections of state-funded schools.'}
|
|
||||||
</p>
|
</p>
|
||||||
{oeifAllSameGrade ? (
|
{showLatestVisitLine(ofsted) && ofsted.latest_visit && (
|
||||||
<p className={styles.ofstedAllSame}>
|
<p className={styles.ofstedDisclaimer}>Latest visit: {latestVisitLine(ofsted.latest_visit)}</p>
|
||||||
Rated <strong>{OFSTED_LABELS[ofsted.overall_effectiveness!]}</strong> across all inspected areas: Quality of Teaching, Behaviour, Pupils' Development and Leadership.
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<div className={`${styles.metricsGrid} ${styles.gradeGrid}`}>
|
|
||||||
{oeifAreas.map(({ label, value }) => (
|
|
||||||
<div key={label} className={styles.metricCard}>
|
|
||||||
<div className={styles.metricLabel}>{label}</div>
|
|
||||||
<div className={`${styles.metricValue} ${styles[`ofstedGrade${value}`]}`}>
|
|
||||||
{OFSTED_LABELS[value]}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</>
|
{oeifAllSameGrade && (display.kind === 'graded' || display.kind === 'confirmed') ? (
|
||||||
) : (
|
<p className={styles.ofstedAllSame}>
|
||||||
/* ── Secondary only: inspected since Sept 2024, no overall grade ── */
|
Rated <strong>{display.gradeLabel}</strong> across all inspected areas: Quality of Teaching, Behaviour, Pupils' Development and Leadership.
|
||||||
<>
|
</p>
|
||||||
<p className={styles.sectionSubtitle}>
|
) : oeifAreas.length > 0 ? (
|
||||||
From September 2024, Ofsted no longer gives a single overall grade.
|
<>
|
||||||
</p>
|
{ofsted.inspection_date && ofsted.inspection_date !== ofsted.latest_visit?.date && (
|
||||||
<div className={`${styles.metricsGrid} ${styles.gradeGrid}`}>
|
<p className={styles.ofstedDisclaimer}>
|
||||||
{[
|
Area judgements from the graded inspection, {formatOfstedDate(ofsted.inspection_date)}.
|
||||||
{ label: 'Quality of Education', value: ofsted.quality_of_education },
|
</p>
|
||||||
{ label: 'Behaviour & Attitudes', value: ofsted.behaviour_attitudes },
|
)}
|
||||||
{ label: 'Personal Development', value: ofsted.personal_development },
|
<div className={`${styles.metricsGrid} ${styles.gradeGrid}`}>
|
||||||
{ label: 'Leadership & Management', value: ofsted.leadership_management },
|
{oeifAreas.map(({ label, value }) => (
|
||||||
].filter(({ value }) => value != null).map(({ label, value }) => (
|
<div key={label} className={styles.metricCard}>
|
||||||
<div key={label} className={styles.metricCard}>
|
<div className={styles.metricLabel}>{label}</div>
|
||||||
<div className={styles.metricLabel}>{label}</div>
|
<div className={`${styles.metricValue} ${styles[`ofstedGrade${value}`]}`}>
|
||||||
<div className={`${styles.metricValue} ${styles[`ofstedGrade${value}`]}`}>
|
{OFSTED_LABELS[value]}
|
||||||
{OFSTED_LABELS[value!]}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
))}
|
</>
|
||||||
</div>
|
) : null}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Section>
|
</Section>
|
||||||
|
|||||||
@@ -55,15 +55,17 @@ export function PrimarySchoolSections({
|
|||||||
const secondaryAvg = nationalAvg?.secondary ?? {};
|
const secondaryAvg = nationalAvg?.secondary ?? {};
|
||||||
|
|
||||||
const isReportCard = !!(ofsted?.report_card && Object.keys(ofsted.report_card).length > 0);
|
const isReportCard = !!(ofsted?.report_card && Object.keys(ofsted.report_card).length > 0);
|
||||||
// Report cards are dated by their own inspection (rc_inspection_date), never
|
// Report cards are dated by their own inspection (rc_inspection_date);
|
||||||
// the legacy inspection_date (report cards exist only from Nov 2025).
|
// anything else by the school's latest visit, never the older inspection a
|
||||||
|
// grade may come from.
|
||||||
const ofstedInspectedDate = isReportCard
|
const ofstedInspectedDate = isReportCard
|
||||||
? ofsted?.rc_inspection_date ?? null
|
? ofsted?.rc_inspection_date ?? null
|
||||||
: ofsted?.inspection_date ?? null;
|
: ofsted?.latest_visit?.date ?? null;
|
||||||
const oeifAreas = ofsted ? ofstedLegacyAreas(ofsted) : [];
|
const oeifAreas = ofsted ? ofstedLegacyAreas(ofsted) : [];
|
||||||
const oeifAllSameGrade =
|
const oeifAllSameGrade =
|
||||||
!!ofsted &&
|
!!ofsted &&
|
||||||
!isReportCard &&
|
!isReportCard &&
|
||||||
|
ofsted.overall_effectiveness != null &&
|
||||||
oeifAreas.length >= 3 &&
|
oeifAreas.length >= 3 &&
|
||||||
oeifAreas.every((a) => a.value === ofsted.overall_effectiveness);
|
oeifAreas.every((a) => a.value === ofsted.overall_effectiveness);
|
||||||
|
|
||||||
@@ -77,7 +79,6 @@ export function PrimarySchoolSections({
|
|||||||
ofstedInspectedDate={ofstedInspectedDate}
|
ofstedInspectedDate={ofstedInspectedDate}
|
||||||
oeifAllSameGrade={oeifAllSameGrade}
|
oeifAllSameGrade={oeifAllSameGrade}
|
||||||
oeifAreas={oeifAreas}
|
oeifAreas={oeifAreas}
|
||||||
variant="primary"
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -154,8 +155,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, isProposedToClose } 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';
|
||||||
@@ -34,8 +35,6 @@ import styles from './SchoolDetailShell.module.css';
|
|||||||
*/
|
*/
|
||||||
export interface SchoolDetailShellProps {
|
export interface SchoolDetailShellProps {
|
||||||
schoolInfo: School;
|
schoolInfo: School;
|
||||||
/** Only for the header's pupil-count fallback. */
|
|
||||||
yearlyData: SchoolResult[];
|
|
||||||
census: SchoolCensus | null;
|
census: SchoolCensus | null;
|
||||||
/** Section list for the sticky nav, computed on the server. */
|
/** Section list for the sticky nav, computed on the server. */
|
||||||
navItems: NavItem[];
|
navItems: NavItem[];
|
||||||
@@ -43,8 +42,14 @@ 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, yearlyData, census, navItems, children,
|
schoolInfo, census, navItems, children,
|
||||||
}: SchoolDetailShellProps) {
|
}: SchoolDetailShellProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { addSchool, removeSchool, isSelected } = useComparison();
|
const { addSchool, removeSchool, isSelected } = useComparison();
|
||||||
@@ -63,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);
|
||||||
|
|
||||||
@@ -122,15 +127,34 @@ export function SchoolDetailShell({
|
|||||||
return () => window.removeEventListener('keydown', onKey);
|
return () => window.removeEventListener('keydown', onKey);
|
||||||
}, [sectionsOpen]);
|
}, [sectionsOpen]);
|
||||||
|
|
||||||
// The chrome needs only these four. The section-shape flags are computed
|
// The chrome needs only these few. The section-shape flags are computed
|
||||||
// once on the server (lib/schoolSections) and consumed by the section
|
// once on the server (lib/schoolSections) and consumed by the section
|
||||||
// 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 latestResults = yearlyData.length > 0 ? yearlyData[yearlyData.length - 1] : null;
|
|
||||||
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;
|
||||||
|
|
||||||
|
// 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) {
|
||||||
removeSchool(schoolInfo.urn);
|
removeSchool(schoolInfo.urn);
|
||||||
@@ -204,29 +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 && (
|
{facts.map((fact) => (
|
||||||
<span className={styles.metaItem}>All-through (primary & secondary)</span>
|
<span key={fact} className={styles.fact}>{fact}</span>
|
||||||
)}
|
))}
|
||||||
{schoolInfo.gender && schoolInfo.gender !== 'Mixed' && (
|
</div>
|
||||||
<span className={styles.metaItem}>{schoolInfo.gender}'s school</span>
|
)}
|
||||||
)}
|
{flags.length > 0 && (
|
||||||
{schoolInfo.age_range && (
|
// role="list": list-style: none drops list semantics in Safari.
|
||||||
<span className={styles.metaItem}>{formatAgeRange(schoolInfo.age_range)}</span>
|
<ul role="list" className={styles.flags} aria-label="Admission and provision">
|
||||||
)}
|
{flags.map((flag) => (
|
||||||
{schoolInfo.nursery_provision && (
|
<li
|
||||||
<span className={styles.metaItem}>Nursery</span>
|
key={flag.label}
|
||||||
)}
|
className={flag.kind === 'condition' ? styles.flagCondition : styles.flagProvision}
|
||||||
{schoolInfo.has_sixth_form && (
|
>
|
||||||
<span className={styles.metaItem}>Sixth form</span>
|
{flag.label}
|
||||||
)}
|
</li>
|
||||||
</div>
|
))}
|
||||||
|
</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
|
||||||
@@ -236,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 && (
|
||||||
<>
|
<>
|
||||||
{' · '}
|
{' · '}
|
||||||
@@ -282,21 +309,6 @@ export function SchoolDetailShell({
|
|||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
{(() => {
|
|
||||||
const total = census?.total_pupils ?? latestResults?.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>{' '}
|
||||||
@@ -305,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;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@@ -63,11 +63,12 @@ export function SecondarySchoolSections({
|
|||||||
const isReportCard = !!(ofsted?.report_card && Object.keys(ofsted.report_card).length > 0);
|
const isReportCard = !!(ofsted?.report_card && Object.keys(ofsted.report_card).length > 0);
|
||||||
const ofstedInspectedDate = isReportCard
|
const ofstedInspectedDate = isReportCard
|
||||||
? ofsted?.rc_inspection_date ?? null
|
? ofsted?.rc_inspection_date ?? null
|
||||||
: ofsted?.inspection_date ?? null;
|
: ofsted?.latest_visit?.date ?? null;
|
||||||
const oeifAreas = ofsted ? ofstedLegacyAreas(ofsted) : [];
|
const oeifAreas = ofsted ? ofstedLegacyAreas(ofsted) : [];
|
||||||
const oeifAllSameGrade =
|
const oeifAllSameGrade =
|
||||||
!!ofsted &&
|
!!ofsted &&
|
||||||
!isReportCard &&
|
!isReportCard &&
|
||||||
|
ofsted.overall_effectiveness != null &&
|
||||||
oeifAreas.length >= 3 &&
|
oeifAreas.length >= 3 &&
|
||||||
oeifAreas.every((a) => a.value === ofsted.overall_effectiveness);
|
oeifAreas.every((a) => a.value === ofsted.overall_effectiveness);
|
||||||
|
|
||||||
@@ -81,7 +82,6 @@ export function SecondarySchoolSections({
|
|||||||
ofstedInspectedDate={ofstedInspectedDate}
|
ofstedInspectedDate={ofstedInspectedDate}
|
||||||
oeifAllSameGrade={oeifAllSameGrade}
|
oeifAllSameGrade={oeifAllSameGrade}
|
||||||
oeifAreas={oeifAreas}
|
oeifAreas={oeifAreas}
|
||||||
variant="secondary"
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -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}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ export function WellbeingSection({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{(() => {
|
{(() => {
|
||||||
const total = census?.total_pupils ?? schoolInfo.total_pupils ?? latestResults?.total_pupils ?? null;
|
// Not latestResults.total_pupils: that is the GCSE year group.
|
||||||
|
const total = census?.total_pupils ?? schoolInfo.total_pupils ?? null;
|
||||||
if (total == null) return null;
|
if (total == null) return null;
|
||||||
const female = census?.female_pupils ?? null;
|
const female = census?.female_pupils ?? null;
|
||||||
const male = census?.male_pupils ?? null;
|
const male = census?.male_pupils ?? null;
|
||||||
|
|||||||
@@ -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.';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,9 +100,8 @@ export function summariseReportCard(ofsted: OfstedInspection): ReportCardSummary
|
|||||||
|
|
||||||
export type OfstedDisplay =
|
export type OfstedDisplay =
|
||||||
| { kind: 'none' }
|
| { kind: 'none' }
|
||||||
| { kind: 'graded'; grade: number; gradeLabel: string; carriedForward: false }
|
| { kind: 'graded' | 'confirmed'; grade: number; gradeLabel: string; gradeDate: string | null }
|
||||||
| { kind: 'carried_forward'; grade: number; gradeLabel: string; carriedForward: true }
|
| { kind: 'no_overall_grade' }
|
||||||
| { kind: 'transitional' }
|
|
||||||
| { kind: 'report_card'; summary: ReportCardSummary };
|
| { kind: 'report_card'; summary: ReportCardSummary };
|
||||||
|
|
||||||
export function ofstedDisplay(
|
export function ofstedDisplay(
|
||||||
@@ -116,19 +115,19 @@ export function ofstedDisplay(
|
|||||||
return { kind: 'report_card', summary: summariseReportCard(ofsted) };
|
return { kind: 'report_card', summary: summariseReportCard(ofsted) };
|
||||||
}
|
}
|
||||||
|
|
||||||
const grade = ofsted.overall_effectiveness;
|
// The grade still in force (backend: fact_ofsted_latest), never one carried
|
||||||
const gradeLabel = grade != null ? OFSTED_LEGACY_GRADES[grade] : undefined;
|
// past a later inspection that gave none.
|
||||||
if (grade == null || gradeLabel === undefined) {
|
const current = ofsted.current_grade;
|
||||||
if (ofsted.inspection_date) {
|
const gradeLabel = current ? OFSTED_LEGACY_GRADES[current.grade] : undefined;
|
||||||
return { kind: 'transitional' };
|
if (current && gradeLabel !== undefined) {
|
||||||
}
|
return {
|
||||||
return { kind: 'none' };
|
kind: current.basis === 'confirmed' ? 'confirmed' : 'graded',
|
||||||
|
grade: current.grade,
|
||||||
|
gradeLabel,
|
||||||
|
gradeDate: current.date,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
return ofsted.latest_visit ? { kind: 'no_overall_grade' } : { kind: 'none' };
|
||||||
if (ofsted.grade_source === 'ungraded_carried_forward') {
|
|
||||||
return { kind: 'carried_forward', grade, gradeLabel, carriedForward: true };
|
|
||||||
}
|
|
||||||
return { kind: 'graded', grade, gradeLabel, carriedForward: false };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/**
|
||||||
|
* The sentences the school page and the compare page print about where an
|
||||||
|
* Ofsted grade came from and what the latest visit was. One wording, two pages.
|
||||||
|
* Rule: docs/superpowers/specs/2026-10-05-ofsted-current-status-design.md
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type { OfstedCurrentGrade, OfstedInspection, OfstedLatestVisit } from './types';
|
||||||
|
|
||||||
|
export function formatOfstedDate(iso: string | null | undefined): string {
|
||||||
|
if (!iso) return '';
|
||||||
|
const d = new Date(iso);
|
||||||
|
if (Number.isNaN(d.getTime())) return '';
|
||||||
|
return d.toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const VISIT_KIND: Record<OfstedLatestVisit['kind'], string> = {
|
||||||
|
report_card: 'Report card inspection',
|
||||||
|
graded: 'Graded inspection',
|
||||||
|
ungraded: 'Ungraded inspection',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** "Graded inspection, 6 July 2016" or "Confirmed at an ungraded inspection, 14 March 2023". */
|
||||||
|
export function gradeSourceLine(current: OfstedCurrentGrade): string {
|
||||||
|
const when = formatOfstedDate(current.date);
|
||||||
|
const what = current.basis === 'confirmed' ? 'Confirmed at an ungraded inspection' : 'Graded inspection';
|
||||||
|
return when ? `${what}, ${when}` : what;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "Ungraded inspection, 13 November 2024: Standards maintained". */
|
||||||
|
export function latestVisitLine(visit: OfstedLatestVisit): string {
|
||||||
|
const head = `${VISIT_KIND[visit.kind]}, ${formatOfstedDate(visit.date)}`;
|
||||||
|
return visit.outcome ? `${head}: ${visit.outcome}` : head;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the latest visit needs its own line: when it is not where the grade
|
||||||
|
* came from, or when there is no grade but an ungraded outcome to report. A
|
||||||
|
* graded visit without a grade is already dated by the section title.
|
||||||
|
*/
|
||||||
|
export function showLatestVisitLine(
|
||||||
|
ofsted: Pick<OfstedInspection, 'current_grade' | 'latest_visit'>,
|
||||||
|
): boolean {
|
||||||
|
const visit = ofsted.latest_visit;
|
||||||
|
if (!visit || visit.kind === 'report_card') return false;
|
||||||
|
const current = ofsted.current_grade;
|
||||||
|
if (current) return current.date !== visit.date;
|
||||||
|
return visit.kind === 'ungraded';
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
+27
-4
@@ -17,10 +17,13 @@ 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;
|
||||||
nursery_provision?: boolean | null;
|
/** GIAS text; read it through hasNurseryClasses(). */
|
||||||
|
nursery_provision?: string | null;
|
||||||
status?: string | null; // GIAS establishment status ("Open" / "Open, but proposed to close")
|
status?: string | null; // GIAS establishment status ("Open" / "Open, but proposed to close")
|
||||||
|
|
||||||
// Address
|
// Address
|
||||||
@@ -73,10 +76,14 @@ export interface School {
|
|||||||
parliamentary_constituency?: string | null;
|
parliamentary_constituency?: string | null;
|
||||||
|
|
||||||
// Ofsted (for list view — summary only)
|
// Ofsted (for list view — summary only)
|
||||||
|
/** The overall grade still in force; null when the latest inspection gave none. */
|
||||||
ofsted_grade?: 1 | 2 | 3 | 4 | null;
|
ofsted_grade?: 1 | 2 | 3 | 4 | null;
|
||||||
|
/** Date the grade was awarded or confirmed (null without a grade). */
|
||||||
|
ofsted_grade_date?: string | null;
|
||||||
/** Report-card inspection date (Nov 2025+); non-null identifies a report
|
/** Report-card inspection date (Nov 2025+); non-null identifies a report
|
||||||
* card in the list/map, where the full report_card object isn't available. */
|
* card in the list/map, where the full report_card object isn't available. */
|
||||||
ofsted_rc_date?: string | null;
|
ofsted_rc_date?: string | null;
|
||||||
|
/** The school's latest inspection of any kind. */
|
||||||
ofsted_date?: string | null;
|
ofsted_date?: string | null;
|
||||||
ofsted_framework?: string | null;
|
ofsted_framework?: string | null;
|
||||||
}
|
}
|
||||||
@@ -92,6 +99,7 @@ export interface OfstedInspection {
|
|||||||
rc_inspection_date?: string | null;
|
rc_inspection_date?: string | null;
|
||||||
inspection_type: string | null;
|
inspection_type: string | null;
|
||||||
// OEIF fields (old framework, pre-Nov 2025)
|
// OEIF fields (old framework, pre-Nov 2025)
|
||||||
|
/** The graded inspection's own overall grade; never carried forward. */
|
||||||
overall_effectiveness: 1 | 2 | 3 | 4 | null;
|
overall_effectiveness: 1 | 2 | 3 | 4 | null;
|
||||||
quality_of_education: number | null;
|
quality_of_education: number | null;
|
||||||
behaviour_attitudes: number | null;
|
behaviour_attitudes: number | null;
|
||||||
@@ -112,9 +120,12 @@ export interface OfstedInspection {
|
|||||||
rc_leadership_governance: number | null;
|
rc_leadership_governance: number | null;
|
||||||
rc_early_years: number | null;
|
rc_early_years: number | null;
|
||||||
rc_sixth_form: number | null;
|
rc_sixth_form: number | null;
|
||||||
/** Where the effective overall grade came from: a graded (Section 5)
|
/** The overall grade still in force, dated by the inspection that awarded
|
||||||
* inspection, or carried forward from an ungraded (Section 8) outcome. */
|
* ("graded") or confirmed ("confirmed", an ungraded visit) it. Null when the
|
||||||
grade_source?: 'graded' | 'ungraded_carried_forward' | null;
|
* latest inspection gave no overall grade, or for a report card. */
|
||||||
|
current_grade?: OfstedCurrentGrade | null;
|
||||||
|
/** The school's most recent inspection of any kind. */
|
||||||
|
latest_visit?: OfstedLatestVisit | null;
|
||||||
/** Renewed-framework (Nov 2025) area judgements, coded + labelled by the
|
/** Renewed-framework (Nov 2025) area judgements, coded + labelled by the
|
||||||
* backend from the live-sampled Ofsted vocabulary. Empty when the school
|
* backend from the live-sampled Ofsted vocabulary. Empty when the school
|
||||||
* has no report-card inspection. Safeguarding is never included here. */
|
* has no report-card inspection. Safeguarding is never included here. */
|
||||||
@@ -124,6 +135,18 @@ export interface OfstedInspection {
|
|||||||
report_url?: string | null;
|
report_url?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface OfstedCurrentGrade {
|
||||||
|
grade: 1 | 2 | 3 | 4;
|
||||||
|
date: string | null;
|
||||||
|
basis: 'graded' | 'confirmed';
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OfstedLatestVisit {
|
||||||
|
date: string;
|
||||||
|
kind: 'report_card' | 'graded' | 'ungraded';
|
||||||
|
outcome: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ReportCardEntry {
|
export interface ReportCardEntry {
|
||||||
code: number;
|
code: number;
|
||||||
label: string;
|
label: string;
|
||||||
|
|||||||
+65
-180
@@ -2,7 +2,7 @@
|
|||||||
* Utility functions for SchoolCompare
|
* Utility functions for SchoolCompare
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { School, MetricDefinition, OfstedInspection, SchoolAdmissions, SchoolResult } from './types';
|
import type { School, MetricDefinition } from './types';
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// String Utilities
|
// String Utilities
|
||||||
@@ -99,6 +99,26 @@ export function formatAgeRange(ageRange: string | null | undefined): string {
|
|||||||
return /^\d+–\d+$/.test(span) ? `Ages ${span}` : span;
|
return /^\d+–\d+$/.test(span) ? `Ages ${span}` : span;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GIAS NurseryProvision is text: "Has Nursery Classes", "No Nursery Classes"
|
||||||
|
* or "Not applicable". Only the first means a nursery, so never test the raw
|
||||||
|
* value for truthiness.
|
||||||
|
*/
|
||||||
|
export function hasNurseryClasses(value: string | null | undefined): boolean {
|
||||||
|
return value?.trim().toLowerCase() === 'has nursery classes';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "Girls' school" / "Boys' school" for a single-sex school, null otherwise.
|
||||||
|
* GIAS genders are plural, so the possessive is a bare apostrophe.
|
||||||
|
*/
|
||||||
|
export function singleSexLabel(gender: string | null | undefined): string | null {
|
||||||
|
const g = gender?.trim().toLowerCase();
|
||||||
|
if (g === 'girls') return "Girls' school";
|
||||||
|
if (g === 'boys') return "Boys' school";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Number Formatting
|
// Number Formatting
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -599,172 +619,6 @@ export function getCurrentAcademicYear(): number {
|
|||||||
return month >= 8 ? year : year - 1;
|
return month >= 8 ? year : year - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// School Detail Hero Helpers
|
|
||||||
// ============================================================================
|
|
||||||
|
|
||||||
const OFSTED_OEIF_WORDS: Record<number, string> = {
|
|
||||||
1: 'Outstanding', 2: 'Good', 3: 'Requires Improvement', 4: 'Inadequate',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Format an Ofsted inspection date as "Month YYYY" (e.g. "November 2023").
|
|
||||||
*/
|
|
||||||
function formatOfstedMonth(date: string | null | undefined): string {
|
|
||||||
if (!date) return '';
|
|
||||||
const d = new Date(date);
|
|
||||||
if (Number.isNaN(d.getTime())) return '';
|
|
||||||
return d.toLocaleDateString('en-GB', { month: 'long', year: 'numeric' });
|
|
||||||
}
|
|
||||||
|
|
||||||
export type HeroTone = 'teal' | 'green' | 'gold' | 'coral' | 'neutral';
|
|
||||||
|
|
||||||
export interface OfstedHeroChip {
|
|
||||||
state: 'oeif' | 'reportCard' | 'none';
|
|
||||||
title: string; // Main label (e.g. "Ofsted Outstanding", "Ofsted Report Card")
|
|
||||||
subtitle: string; // Context line (e.g. "Inspected November 2023")
|
|
||||||
detail?: string; // Optional extra line (e.g. "Safeguarding: Met")
|
|
||||||
tone: HeroTone; // Maps to dedicated hero tone classes (not badge classes)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build the hero-strip Ofsted chip, branching on the inspection framework.
|
|
||||||
* Never synthesises a single overall grade for ReportCard schools.
|
|
||||||
*
|
|
||||||
* Note: the API may return ``framework`` as a literal string ``"NULL"`` for
|
|
||||||
* older inspections, so we explicitly only branch into the ReportCard layout
|
|
||||||
* when the value is exactly ``"ReportCard"``. Anything else with an
|
|
||||||
* ``overall_effectiveness`` score is treated as OEIF.
|
|
||||||
*/
|
|
||||||
export function buildOfstedHeroChip(ofsted: OfstedInspection | null | undefined): OfstedHeroChip {
|
|
||||||
if (!ofsted) {
|
|
||||||
return {
|
|
||||||
state: 'none',
|
|
||||||
title: 'Ofsted pending',
|
|
||||||
subtitle: 'No inspection on record',
|
|
||||||
tone: 'neutral',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const when = formatOfstedMonth(ofsted.inspection_date);
|
|
||||||
|
|
||||||
// ReportCard branch — only if the API explicitly says so
|
|
||||||
if (ofsted.framework === 'ReportCard') {
|
|
||||||
const safeguarding = ofsted.rc_safeguarding_met;
|
|
||||||
return {
|
|
||||||
state: 'reportCard',
|
|
||||||
title: 'Ofsted Report Card',
|
|
||||||
subtitle: when ? `Inspected ${when}` : 'New framework inspection',
|
|
||||||
detail:
|
|
||||||
safeguarding == null
|
|
||||||
? undefined
|
|
||||||
: safeguarding ? 'Safeguarding: Met' : 'Safeguarding: Not met',
|
|
||||||
tone: safeguarding === false ? 'coral' : 'green',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise treat as OEIF (covers framework === 'OEIF', null, "NULL", etc.)
|
|
||||||
const grade = ofsted.overall_effectiveness;
|
|
||||||
if (grade && OFSTED_OEIF_WORDS[grade]) {
|
|
||||||
const oeifTone: HeroTone =
|
|
||||||
grade === 1 ? 'teal' :
|
|
||||||
grade === 2 ? 'green' :
|
|
||||||
grade === 3 ? 'gold' :
|
|
||||||
'coral';
|
|
||||||
return {
|
|
||||||
state: 'oeif',
|
|
||||||
title: `Ofsted ${OFSTED_OEIF_WORDS[grade]}`,
|
|
||||||
subtitle: when ? `Inspected ${when}` : 'Inspected',
|
|
||||||
tone: oeifTone,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
state: 'oeif',
|
|
||||||
title: 'Ofsted inspected',
|
|
||||||
subtitle: when ? `Inspected ${when}` : 'Inspection on record',
|
|
||||||
tone: 'neutral',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build a one-sentence editorial summary for the school detail hero.
|
|
||||||
* Branches on Ofsted framework so Report Card schools are never described
|
|
||||||
* with an overall grade they do not have.
|
|
||||||
*/
|
|
||||||
export function buildSchoolSummary(
|
|
||||||
schoolInfo: School,
|
|
||||||
ofsted: OfstedInspection | null | undefined,
|
|
||||||
admissions: SchoolAdmissions | null | undefined,
|
|
||||||
latestResults: SchoolResult | null | undefined,
|
|
||||||
): string {
|
|
||||||
const parts: string[] = [];
|
|
||||||
|
|
||||||
// Size descriptor
|
|
||||||
const pupils = latestResults?.total_pupils ?? schoolInfo.total_pupils ?? null;
|
|
||||||
const sizeWord =
|
|
||||||
pupils == null ? '' :
|
|
||||||
pupils < 200 ? 'Small' :
|
|
||||||
pupils < 500 ? 'Mid-sized' :
|
|
||||||
'Large';
|
|
||||||
|
|
||||||
// Phase descriptor — avoid the raw code
|
|
||||||
const phase = (schoolInfo.phase ?? '').toLowerCase();
|
|
||||||
const phaseWord =
|
|
||||||
phase.includes('secondary') ? 'secondary' :
|
|
||||||
phase === 'all-through' ? 'all-through' :
|
|
||||||
phase.includes('primary') ? 'primary' :
|
|
||||||
'school';
|
|
||||||
|
|
||||||
// Religious character
|
|
||||||
const religion = schoolInfo.religious_denomination;
|
|
||||||
const religionWord =
|
|
||||||
!religion || /none|does not apply/i.test(religion) ? '' :
|
|
||||||
/roman catholic|catholic/i.test(religion) ? 'Catholic ' :
|
|
||||||
/church of england|ce|anglican/i.test(religion) ? 'Church of England ' :
|
|
||||||
/jewish/i.test(religion) ? 'Jewish ' :
|
|
||||||
/muslim|islam/i.test(religion) ? 'Muslim ' :
|
|
||||||
/hindu/i.test(religion) ? 'Hindu ' :
|
|
||||||
/sikh/i.test(religion) ? 'Sikh ' :
|
|
||||||
'';
|
|
||||||
|
|
||||||
// Locality — prefer town from address parsing (fallback to LA)
|
|
||||||
const locality = schoolInfo.town || schoolInfo.local_authority || '';
|
|
||||||
|
|
||||||
const lead = [sizeWord, religionWord + phaseWord].filter(Boolean).join(' ');
|
|
||||||
let opening = lead || 'School';
|
|
||||||
if (locality) opening += ` in ${locality}`;
|
|
||||||
parts.push(opening);
|
|
||||||
|
|
||||||
// Ofsted clause (framework-aware)
|
|
||||||
if (ofsted?.framework === 'OEIF' && ofsted.overall_effectiveness) {
|
|
||||||
parts.push(`rated ${OFSTED_OEIF_WORDS[ofsted.overall_effectiveness]} by Ofsted`);
|
|
||||||
} else if (ofsted?.framework === 'ReportCard') {
|
|
||||||
const when = formatOfstedMonth(ofsted.inspection_date);
|
|
||||||
parts.push(
|
|
||||||
when
|
|
||||||
? `most recently inspected under Ofsted's Report Card framework in ${when}`
|
|
||||||
: "recently inspected under Ofsted's new Report Card framework",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Admissions clause
|
|
||||||
if (admissions?.oversubscribed) {
|
|
||||||
if (admissions.first_preference_offer_pct != null) {
|
|
||||||
const pct = Math.round(admissions.first_preference_offer_pct);
|
|
||||||
parts.push(
|
|
||||||
`oversubscribed (${pct}% of first-choice applicants are offered a place)`,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
parts.push('oversubscribed');
|
|
||||||
}
|
|
||||||
} else if (admissions?.first_preference_offer_pct != null && admissions.first_preference_offer_pct >= 90) {
|
|
||||||
parts.push('most families get their first-choice offer');
|
|
||||||
}
|
|
||||||
|
|
||||||
return parts.join(', ') + '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Legacy (OEIF) sub-judgement areas ────────────────────────────────────────
|
// ─── Legacy (OEIF) sub-judgement areas ────────────────────────────────────────
|
||||||
|
|
||||||
export interface OfstedLegacyArea {
|
export interface OfstedLegacyArea {
|
||||||
@@ -817,15 +671,18 @@ export interface OfstedListBadge {
|
|||||||
* Checked FIRST so it wins over any carried-forward legacy grade — the
|
* Checked FIRST so it wins over any carried-forward legacy grade — the
|
||||||
* list has no full report_card object, and ofsted_framework is the raw
|
* list has no full report_card object, and ofsted_framework is the raw
|
||||||
* event grouping ("Schools - S5"), never "ReportCard".
|
* event grouping ("Schools - S5"), never "ReportCard".
|
||||||
* - OEIF school (ofsted_grade set): grade word + year, colour-keyed
|
* - Current grade (ofsted_grade set): grade word + the year it was awarded
|
||||||
* - Inspected without an overall grade (OEIF post-Sept-2024, where Ofsted no
|
* or confirmed (ofsted_grade_date), colour-keyed. Never the year of a later
|
||||||
* longer issues an overall judgement): "Inspected · YYYY" — mirrors the
|
* visit: that paired old grades with new inspections (audit C1).
|
||||||
* detail page's hero chip so a school never reads as both inspected and
|
* - Inspected with no grade in force (every inspection Sept 2024 – Nov 2025,
|
||||||
|
* or an ungraded visit whose outcome names no grade): "Inspected · YYYY",
|
||||||
|
* dated by the latest visit, so a school never reads as both inspected and
|
||||||
* "Not yet inspected"
|
* "Not yet inspected"
|
||||||
* - No inspection on record: "Not yet inspected" in grey
|
* - No inspection on record: "Not yet inspected" in grey
|
||||||
*/
|
*/
|
||||||
export function buildOfstedListBadge(school: {
|
export function buildOfstedListBadge(school: {
|
||||||
ofsted_grade?: 1 | 2 | 3 | 4 | null;
|
ofsted_grade?: 1 | 2 | 3 | 4 | null;
|
||||||
|
ofsted_grade_date?: string | null;
|
||||||
ofsted_date?: string | null;
|
ofsted_date?: string | null;
|
||||||
ofsted_framework?: string | null;
|
ofsted_framework?: string | null;
|
||||||
ofsted_rc_date?: string | null;
|
ofsted_rc_date?: string | null;
|
||||||
@@ -838,10 +695,7 @@ export function buildOfstedListBadge(school: {
|
|||||||
return { label: `Report Card · ${rcYear}`, cssClass: 'ofstedRc' };
|
return { label: `Report Card · ${rcYear}`, cssClass: 'ofstedRc' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const year = school.ofsted_date
|
const yearOf = (iso?: string | null) => (iso ? new Date(iso).getFullYear() : null);
|
||||||
? new Date(school.ofsted_date).getFullYear()
|
|
||||||
: null;
|
|
||||||
const yearStr = year ? ` · ${year}` : '';
|
|
||||||
|
|
||||||
if (school.ofsted_grade) {
|
if (school.ofsted_grade) {
|
||||||
const labels: Record<number, string> = {
|
const labels: Record<number, string> = {
|
||||||
@@ -850,17 +704,19 @@ export function buildOfstedListBadge(school: {
|
|||||||
3: 'Req. Improvement',
|
3: 'Req. Improvement',
|
||||||
4: 'Inadequate',
|
4: 'Inadequate',
|
||||||
};
|
};
|
||||||
|
const gradeYear = yearOf(school.ofsted_grade_date);
|
||||||
return {
|
return {
|
||||||
label: `${labels[school.ofsted_grade]}${yearStr}`,
|
label: `${labels[school.ofsted_grade]}${gradeYear ? ` · ${gradeYear}` : ''}`,
|
||||||
cssClass: `ofsted${school.ofsted_grade}`,
|
cssClass: `ofsted${school.ofsted_grade}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// An inspection is on record (date or framework present) but carries no
|
// An inspection is on record but no overall grade is in force: every
|
||||||
// overall grade — a post-Sept-2024 OEIF inspection. Distinct from a school
|
// inspection from Sept 2024 to Nov 2025, or an ungraded visit whose outcome
|
||||||
// that has genuinely never been inspected.
|
// names no grade. Dated by the latest visit.
|
||||||
if (school.ofsted_date != null || school.ofsted_framework != null) {
|
if (school.ofsted_date != null || school.ofsted_framework != null) {
|
||||||
return { label: `Inspected${yearStr}`, cssClass: 'ofstedInspected' };
|
const visitYear = yearOf(school.ofsted_date);
|
||||||
|
return { label: `Inspected${visitYear ? ` · ${visitYear}` : ''}`, cssClass: 'ofstedInspected' };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { label: 'Not yet inspected', cssClass: 'ofstedPending' };
|
return { label: 'Not yet inspected', cssClass: 'ofstedPending' };
|
||||||
@@ -902,6 +758,35 @@ export function isSpecialSchool(school: { school_type?: string | null }): boolea
|
|||||||
return /\bspecial\b/.test(t) || /pupil referral/.test(t) || /alternative provision/.test(t);
|
return /\bspecial\b/.test(t) || /pupil referral/.test(t) || /alternative provision/.test(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Independent (fee-paying) schools: GIAS types "Other independent school" and
|
||||||
|
* "Other independent special school". DfE's Attainment 8 for them leaves out
|
||||||
|
* IGCSEs, and DfE's LA averages cover state-funded schools only, so callers
|
||||||
|
* drop the "vs LA avg" comparison for them (audit H2).
|
||||||
|
*/
|
||||||
|
export function isIndependentSchool(school: { school_type?: string | null }): boolean {
|
||||||
|
return /\bindependent\b/i.test(school.school_type ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether GIAS records a religious character. "None", "Does not apply" and
|
||||||
|
* "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 {
|
||||||
|
const v = value?.trim().toLowerCase() ?? '';
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The school's combined Reading, Writing & Maths figure, or null when there is
|
* The school's combined Reading, Writing & Maths figure, or null when there is
|
||||||
* no real one to show.
|
* no real one to show.
|
||||||
|
|||||||
@@ -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(
|
||||||
@@ -190,7 +193,7 @@ with DAG(
|
|||||||
|
|
||||||
dbt_build_ees = BashOperator(
|
dbt_build_ees = 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_ees_ks2+ stg_legacy_ks2+ stg_ees_ks4+ stg_legacy_ks4+ stg_ees_census+ stg_ees_admissions+ stg_ees_ks2_national+ stg_ees_ks4_national+ stg_ees_ks4_destinations+ stg_ees_ks5_destinations+ stg_ees_ks4_destinations_national+ stg_ees_ks5_destinations_national+",
|
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_ees_ks2+ stg_legacy_ks2+ stg_ees_ks4+ stg_legacy_ks4+ stg_ees_census+ stg_ees_admissions+ stg_ees_ks2_national+ stg_ees_ks4_national+ stg_ees_ks4_la+ stg_ees_ks4_destinations+ stg_ees_ks5_destinations+ stg_ees_ks4_destinations_national+ stg_ees_ks5_destinations_national+",
|
||||||
)
|
)
|
||||||
|
|
||||||
sync_typesense_ees = BashOperator(
|
sync_typesense_ees = BashOperator(
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
"""KS4 school information: the fields the stream declares, and the older
|
||||||
|
names DfE used for them.
|
||||||
|
|
||||||
|
2023/24 information exists only in the 2023/24 release, whose
|
||||||
|
202324_information_about_schools_final.csv (re-issued 10 March 2026) uses the
|
||||||
|
older names. Without the renames every 2023/24 field loaded as null (audit C2).
|
||||||
|
Newer files contain none of the older names, so the renames leave them alone.
|
||||||
|
|
||||||
|
Free of the Singer SDK so CI's pytest can load it.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Declared Singer fields besides the required time_period and school_urn.
|
||||||
|
KS4_INFO_FIELDS = (
|
||||||
|
"school_laestab",
|
||||||
|
"school_name",
|
||||||
|
"establishment_type_group",
|
||||||
|
"reldenom",
|
||||||
|
"admpol_pt",
|
||||||
|
"egender",
|
||||||
|
"agerange",
|
||||||
|
"allks_pupil_count",
|
||||||
|
"allks_boys_count",
|
||||||
|
"allks_girls_count",
|
||||||
|
"endks4_pupil_count",
|
||||||
|
"ks2_scaledscore_average",
|
||||||
|
"sen_with_ehcp_pupil_percent",
|
||||||
|
"sen_pupil_percent",
|
||||||
|
"sen_no_ehcp_pupil_percent",
|
||||||
|
"attainment8_diffn",
|
||||||
|
"progress8_diffn",
|
||||||
|
"progress8_banding",
|
||||||
|
)
|
||||||
|
|
||||||
|
# 2023/24 column name → declared field.
|
||||||
|
KS4_INFO_RENAMES = {
|
||||||
|
"t_allks_pupils": "allks_pupil_count",
|
||||||
|
"t_allks_boys": "allks_boys_count",
|
||||||
|
"t_allks_girls": "allks_girls_count",
|
||||||
|
"t_pupils": "endks4_pupil_count",
|
||||||
|
"avg_ks2_scaledscore": "ks2_scaledscore_average",
|
||||||
|
"pt_sen_with_ehcp": "sen_with_ehcp_pupil_percent",
|
||||||
|
"pt_sen": "sen_pupil_percent",
|
||||||
|
"pt_sen_no_ehcp": "sen_no_ehcp_pupil_percent",
|
||||||
|
"diffn_att8": "attainment8_diffn",
|
||||||
|
"diffn_p8mea": "progress8_diffn",
|
||||||
|
"p8_banding": "progress8_banding",
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
"""DfE's KS4 "summary, all state-funded" data set (Key stage 4 performance).
|
||||||
|
|
||||||
|
One CSV holds England, regional and local-authority headline rows for every
|
||||||
|
year since 2018/19. The England stream (ees_ks4_national) and the LA stream
|
||||||
|
(ees_ks4_la) both read it. Its LA rows match DfE's published performance-table
|
||||||
|
LA averages exactly (audit H2). Suppressed values ('z', 'x') become NULL in
|
||||||
|
dbt; Progress 8 is 'z' in years with no KS2 baseline (2024/25): DfE policy,
|
||||||
|
not missing data.
|
||||||
|
|
||||||
|
Free of the Singer SDK so CI's pytest can load it.
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
KS4_SUMMARY_CSV_URL = (
|
||||||
|
"https://explore-education-statistics.service.gov.uk/data-catalogue/"
|
||||||
|
"data-set/1b649e16-01e8-435b-a814-56be2faf9054/csv"
|
||||||
|
)
|
||||||
|
|
||||||
|
# CSV column → Singer field: the same 8 headline measures at every level.
|
||||||
|
KS4_HEADLINE_COL_MAP = {
|
||||||
|
"attainment8_average": "attainment_8_score",
|
||||||
|
"progress8_average": "progress_8_score",
|
||||||
|
"engmath_94_percent": "english_maths_standard_pass_pct",
|
||||||
|
"engmath_95_percent": "english_maths_strong_pass_pct",
|
||||||
|
"ebacc_entering_percent": "ebacc_entry_pct",
|
||||||
|
"ebacc_94_percent": "ebacc_standard_pass_pct",
|
||||||
|
"ebacc_95_percent": "ebacc_strong_pass_pct",
|
||||||
|
"ebacc_aps_average": "ebacc_avg_score",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def headline_rows(df: pd.DataFrame, geographic_level: str) -> pd.DataFrame:
|
||||||
|
"""All-pupil rows for all state-funded schools at one geographic level
|
||||||
|
("National" or "Local authority"). Column names are lower-cased first;
|
||||||
|
a filter column the file lacks is not applied."""
|
||||||
|
df = df.copy()
|
||||||
|
df.columns = [c.strip().lower() for c in df.columns]
|
||||||
|
for col, want in (
|
||||||
|
("geographic_level", geographic_level),
|
||||||
|
("establishment_type_group", "All state-funded"),
|
||||||
|
("breakdown_topic", "Total"),
|
||||||
|
("breakdown", "Total"),
|
||||||
|
):
|
||||||
|
if col in df.columns:
|
||||||
|
df = df[df[col].str.strip().str.lower() == want.lower()]
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
def headline_record(row: pd.Series, keys: tuple[str, ...]) -> dict[str, str]:
|
||||||
|
"""A Singer record: the identifying columns, then the headline measures."""
|
||||||
|
record = {key: str(row.get(key, "")).strip() for key in keys}
|
||||||
|
for csv_col, field in KS4_HEADLINE_COL_MAP.items():
|
||||||
|
record[field] = str(row.get(csv_col, "")).strip()
|
||||||
|
return record
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
"""Which release a row comes from when DfE re-publishes a year.
|
||||||
|
|
||||||
|
DfE re-publishes earlier years inside later releases: the 2024/25 KS4 results
|
||||||
|
file holds 2022/23, 2023/24 and 2024/25. The 2023/24 release's own file,
|
||||||
|
re-issued on 10 March 2026 under older column names, was read after it and
|
||||||
|
overwrote every 2023/24 row with blanks (audit C2). A stream that opts in
|
||||||
|
treats the newest release as the authority for every year it contains.
|
||||||
|
|
||||||
|
Free of the Singer SDK so CI's pytest, which installs only the backend's
|
||||||
|
requirements, can load it.
|
||||||
|
"""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
_SLUG_YEAR = re.compile(r"^(\d{4})-(\d{2})(?:-|$)")
|
||||||
|
|
||||||
|
|
||||||
|
def slug_to_time_period(slug: str) -> str | None:
|
||||||
|
"""A release slug's academic year as a time_period: '2022-23' → '202223'.
|
||||||
|
|
||||||
|
Suffixed slugs ('2024-25-revised', '2025-26-provisional') give the same
|
||||||
|
year, so newest_first places them by year; read as unknown, a revised
|
||||||
|
release went last and lost its year to the first release.
|
||||||
|
"""
|
||||||
|
match = _SLUG_YEAR.match(slug or "")
|
||||||
|
return match.group(1) + match.group(2) if match else None
|
||||||
|
|
||||||
|
|
||||||
|
def newest_first(releases: list[dict]) -> list[dict]:
|
||||||
|
"""Releases by time_period, newest first. A release whose time_period is
|
||||||
|
unknown goes last, in the order given."""
|
||||||
|
dated = [r for r in releases if r.get("time_period")]
|
||||||
|
undated = [r for r in releases if not r.get("time_period")]
|
||||||
|
return sorted(dated, key=lambda r: r["time_period"], reverse=True) + undated
|
||||||
|
|
||||||
|
|
||||||
|
def periods_in(df: pd.DataFrame) -> set[str]:
|
||||||
|
"""The years a release's rows cover."""
|
||||||
|
if "time_period" not in df.columns:
|
||||||
|
return set()
|
||||||
|
return set(df["time_period"].astype(str).str.strip()) - {""}
|
||||||
|
|
||||||
|
|
||||||
|
def drop_owned_periods(
|
||||||
|
df: pd.DataFrame, owned: set[str]
|
||||||
|
) -> tuple[pd.DataFrame, dict[str, int]]:
|
||||||
|
"""Drop the rows for years a newer release already supplied.
|
||||||
|
|
||||||
|
Returns the rows kept and, for each year dropped, how many rows went.
|
||||||
|
"""
|
||||||
|
if "time_period" not in df.columns or not owned:
|
||||||
|
return df, {}
|
||||||
|
periods = df["time_period"].astype(str).str.strip()
|
||||||
|
dropped = periods.isin(owned)
|
||||||
|
skipped = {str(k): int(v) for k, v in periods[dropped].value_counts().items()}
|
||||||
|
return df[~dropped], skipped
|
||||||
@@ -17,6 +17,20 @@ import requests
|
|||||||
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_ees.ks4_info import KS4_INFO_FIELDS, KS4_INFO_RENAMES
|
||||||
|
from tap_uk_ees.ks4_summary import (
|
||||||
|
KS4_HEADLINE_COL_MAP,
|
||||||
|
KS4_SUMMARY_CSV_URL,
|
||||||
|
headline_record,
|
||||||
|
headline_rows,
|
||||||
|
)
|
||||||
|
from tap_uk_ees.release_precedence import (
|
||||||
|
drop_owned_periods,
|
||||||
|
newest_first,
|
||||||
|
periods_in,
|
||||||
|
slug_to_time_period,
|
||||||
|
)
|
||||||
|
|
||||||
CONTENT_API_BASE = (
|
CONTENT_API_BASE = (
|
||||||
"https://content.explore-education-statistics.service.gov.uk/api"
|
"https://content.explore-education-statistics.service.gov.uk/api"
|
||||||
)
|
)
|
||||||
@@ -31,14 +45,6 @@ def get_content_release_id(publication_slug: str) -> str:
|
|||||||
return resp.json()["id"]
|
return resp.json()["id"]
|
||||||
|
|
||||||
|
|
||||||
def _slug_to_time_period(slug: str) -> str | None:
|
|
||||||
"""Convert a release slug like '2022-23' to a time_period like '202223'."""
|
|
||||||
parts = slug.split("-")
|
|
||||||
if len(parts) == 2 and len(parts[0]) == 4 and len(parts[1]) == 2:
|
|
||||||
return parts[0] + parts[1]
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_all_releases(publication_slug: str) -> list[dict]:
|
def get_all_releases(publication_slug: str) -> list[dict]:
|
||||||
"""Return all releases for a publication as dicts with 'id' and 'time_period'.
|
"""Return all releases for a publication as dicts with 'id' and 'time_period'.
|
||||||
|
|
||||||
@@ -63,7 +69,7 @@ def get_all_releases(publication_slug: str) -> list[dict]:
|
|||||||
total_pages = paging.get("totalPages", 1)
|
total_pages = paging.get("totalPages", 1)
|
||||||
|
|
||||||
for r in releases:
|
for r in releases:
|
||||||
time_period = _slug_to_time_period(r.get("slug", ""))
|
time_period = slug_to_time_period(r.get("slug", ""))
|
||||||
result.append({"id": r["id"], "time_period": time_period})
|
result.append({"id": r["id"], "time_period": time_period})
|
||||||
|
|
||||||
if page >= total_pages:
|
if page >= total_pages:
|
||||||
@@ -88,6 +94,8 @@ class EESDatasetStream(Stream):
|
|||||||
target CSV path inside the ZIP (substring match, not exact).
|
target CSV path inside the ZIP (substring match, not exact).
|
||||||
Subclasses may set _column_renames to map messy CSV column names to
|
Subclasses may set _column_renames to map messy CSV column names to
|
||||||
clean Singer field names before yielding records.
|
clean Singer field names before yielding records.
|
||||||
|
Subclasses may set _newest_release_owns_period when DfE re-publishes
|
||||||
|
earlier years in later releases and the newest copy is the authority.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
replication_key = None
|
replication_key = None
|
||||||
@@ -96,6 +104,7 @@ class EESDatasetStream(Stream):
|
|||||||
_urn_column: str = "school_urn" # column name for URN in the CSV
|
_urn_column: str = "school_urn" # column name for URN in the CSV
|
||||||
_encoding: str = "utf-8" # CSV file encoding (some DfE files use latin-1)
|
_encoding: str = "utf-8" # CSV file encoding (some DfE files use latin-1)
|
||||||
_column_renames: dict = {} # CSV column name → Singer field name
|
_column_renames: dict = {} # CSV column name → Singer field name
|
||||||
|
_newest_release_owns_period: bool = False # see release_precedence.py
|
||||||
|
|
||||||
def get_records(self, context):
|
def get_records(self, context):
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -110,6 +119,9 @@ class EESDatasetStream(Stream):
|
|||||||
self.logger.info(
|
self.logger.info(
|
||||||
"Found %d release(s) for %s", len(releases), self._publication_slug
|
"Found %d release(s) for %s", len(releases), self._publication_slug
|
||||||
)
|
)
|
||||||
|
if self._newest_release_owns_period:
|
||||||
|
releases = newest_first(releases)
|
||||||
|
owned_periods: set[str] = set()
|
||||||
|
|
||||||
for release in releases:
|
for release in releases:
|
||||||
release_id = release["id"]
|
release_id = release["id"]
|
||||||
@@ -163,6 +175,15 @@ class EESDatasetStream(Stream):
|
|||||||
if urn_col in df.columns:
|
if urn_col in df.columns:
|
||||||
df = df[df[urn_col].notna() & (df[urn_col] != "")]
|
df = df[df[urn_col].notna() & (df[urn_col] != "")]
|
||||||
|
|
||||||
|
if self._newest_release_owns_period:
|
||||||
|
df, skipped = drop_owned_periods(df, owned_periods)
|
||||||
|
for period, count in sorted(skipped.items()):
|
||||||
|
self.logger.info(
|
||||||
|
"Skipping %d rows for %s from release %s: a newer release supplied that year",
|
||||||
|
count, period, release_id,
|
||||||
|
)
|
||||||
|
owned_periods |= periods_in(df)
|
||||||
|
|
||||||
self.logger.info("Emitting %d school-level rows from release %s", len(df), release_id)
|
self.logger.info("Emitting %d school-level rows from release %s", len(df), release_id)
|
||||||
|
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
@@ -251,6 +272,9 @@ class EESKS4PerformanceStream(EESDatasetStream):
|
|||||||
primary_keys = ["school_urn", "time_period", "breakdown_topic", "breakdown", "sex"]
|
primary_keys = ["school_urn", "time_period", "breakdown_topic", "breakdown", "sex"]
|
||||||
_publication_slug = "key-stage-4-performance"
|
_publication_slug = "key-stage-4-performance"
|
||||||
_target_filename = "performance_tables_schools"
|
_target_filename = "performance_tables_schools"
|
||||||
|
# DfE's 2024/25 file re-publishes 2022/23 and 2023/24 under current names;
|
||||||
|
# the 2023/24 release's own file uses older ones (audit C2).
|
||||||
|
_newest_release_owns_period = True
|
||||||
schema = th.PropertiesList(
|
schema = th.PropertiesList(
|
||||||
th.Property("time_period", th.StringType, required=True),
|
th.Property("time_period", th.StringType, required=True),
|
||||||
th.Property("school_urn", th.StringType, required=True),
|
th.Property("school_urn", th.StringType, required=True),
|
||||||
@@ -310,34 +334,20 @@ class EESKS4PerformanceStream(EESDatasetStream):
|
|||||||
|
|
||||||
|
|
||||||
# ── KS4 Information (wide format: one row per school, context/demographics) ──
|
# ── KS4 Information (wide format: one row per school, context/demographics) ──
|
||||||
# File: 202425_information_about_schools_provisional.csv (38 cols)
|
# Files: 202425_information_about_schools_final.csv (38 cols, current names);
|
||||||
|
# 202324_information_about_schools_final.csv (60 cols, older names — the only
|
||||||
|
# source of 2023/24 information). Field list and renames: ks4_info.py.
|
||||||
|
|
||||||
class EESKS4InfoStream(EESDatasetStream):
|
class EESKS4InfoStream(EESDatasetStream):
|
||||||
name = "ees_ks4_info"
|
name = "ees_ks4_info"
|
||||||
primary_keys = ["school_urn", "time_period"]
|
primary_keys = ["school_urn", "time_period"]
|
||||||
_publication_slug = "key-stage-4-performance"
|
_publication_slug = "key-stage-4-performance"
|
||||||
_target_filename = "information_about_schools"
|
_target_filename = "information_about_schools"
|
||||||
|
_column_renames = KS4_INFO_RENAMES
|
||||||
schema = th.PropertiesList(
|
schema = th.PropertiesList(
|
||||||
th.Property("time_period", th.StringType, required=True),
|
th.Property("time_period", th.StringType, required=True),
|
||||||
th.Property("school_urn", th.StringType, required=True),
|
th.Property("school_urn", th.StringType, required=True),
|
||||||
th.Property("school_laestab", th.StringType),
|
*[th.Property(field, th.StringType) for field in KS4_INFO_FIELDS],
|
||||||
th.Property("school_name", th.StringType),
|
|
||||||
th.Property("establishment_type_group", th.StringType),
|
|
||||||
th.Property("reldenom", th.StringType),
|
|
||||||
th.Property("admpol_pt", th.StringType),
|
|
||||||
th.Property("egender", th.StringType),
|
|
||||||
th.Property("agerange", th.StringType),
|
|
||||||
th.Property("allks_pupil_count", th.StringType),
|
|
||||||
th.Property("allks_boys_count", th.StringType),
|
|
||||||
th.Property("allks_girls_count", th.StringType),
|
|
||||||
th.Property("endks4_pupil_count", th.StringType),
|
|
||||||
th.Property("ks2_scaledscore_average", th.StringType),
|
|
||||||
th.Property("sen_with_ehcp_pupil_percent", th.StringType),
|
|
||||||
th.Property("sen_pupil_percent", th.StringType),
|
|
||||||
th.Property("sen_no_ehcp_pupil_percent", th.StringType),
|
|
||||||
th.Property("attainment8_diffn", th.StringType),
|
|
||||||
th.Property("progress8_diffn", th.StringType),
|
|
||||||
th.Property("progress8_banding", th.StringType),
|
|
||||||
).to_dict()
|
).to_dict()
|
||||||
|
|
||||||
|
|
||||||
@@ -564,37 +574,23 @@ class EESKs2NationalStream(Stream):
|
|||||||
yield record
|
yield record
|
||||||
|
|
||||||
|
|
||||||
# ── KS4 National Headlines (national level only — one row per year) ──────────
|
# ── KS4 National and LA Headlines (one data set, two streams) ────────────────
|
||||||
# Dataset: "National characteristics summary data" (Key stage 4 performance).
|
# DfE's "summary, all state-funded" data set: England, regional and LA rows,
|
||||||
# Official England state-funded headline measures, 2018/19 → latest.
|
# 2018/19 → latest. URL, measures and filters: ks4_summary.py.
|
||||||
# Suppressed values ('z', 'x') → NULL downstream. Progress 8 is legitimately
|
|
||||||
# absent in years with no KS2 baseline (e.g. 2024/25) — that is DfE policy,
|
|
||||||
# not missing data.
|
|
||||||
|
|
||||||
_KS4_NATIONAL_CSV_URL = (
|
def _read_ks4_summary(logger):
|
||||||
"https://explore-education-statistics.service.gov.uk/data-catalogue/"
|
"""Download DfE's KS4 summary data set."""
|
||||||
"data-set/1b649e16-01e8-435b-a814-56be2faf9054/csv"
|
import pandas as pd
|
||||||
)
|
|
||||||
|
|
||||||
_KS4_NATIONAL_COL_MAP = {
|
logger.info("Downloading KS4 summary data set: %s", KS4_SUMMARY_CSV_URL)
|
||||||
"attainment8_average": "attainment_8_score",
|
resp = requests.get(KS4_SUMMARY_CSV_URL, timeout=60)
|
||||||
"progress8_average": "progress_8_score",
|
resp.raise_for_status()
|
||||||
"engmath_94_percent": "english_maths_standard_pass_pct",
|
return pd.read_csv(io.BytesIO(resp.content), dtype=str, keep_default_na=False)
|
||||||
"engmath_95_percent": "english_maths_strong_pass_pct",
|
|
||||||
"ebacc_entering_percent": "ebacc_entry_pct",
|
|
||||||
"ebacc_94_percent": "ebacc_standard_pass_pct",
|
|
||||||
"ebacc_95_percent": "ebacc_strong_pass_pct",
|
|
||||||
"ebacc_aps_average": "ebacc_avg_score",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class EESKs4NationalStream(Stream):
|
class EESKs4NationalStream(Stream):
|
||||||
"""National KS4 headline averages — one row per academic year.
|
"""National KS4 headline averages — one row per academic year (England,
|
||||||
|
all state-funded schools, all pupils)."""
|
||||||
Filters to geographic_level == 'National', establishment_type_group ==
|
|
||||||
'All state-funded', breakdown_topic == 'Total', breakdown == 'Total'
|
|
||||||
so only the England-wide all-pupils row per year is emitted.
|
|
||||||
"""
|
|
||||||
|
|
||||||
name = "ees_ks4_national"
|
name = "ees_ks4_national"
|
||||||
primary_keys = ["time_period"]
|
primary_keys = ["time_period"]
|
||||||
@@ -602,34 +598,41 @@ class EESKs4NationalStream(Stream):
|
|||||||
|
|
||||||
schema = th.PropertiesList(
|
schema = th.PropertiesList(
|
||||||
th.Property("time_period", th.StringType, required=True),
|
th.Property("time_period", th.StringType, required=True),
|
||||||
*[th.Property(out, th.StringType) for out in _KS4_NATIONAL_COL_MAP.values()],
|
*[th.Property(out, th.StringType) for out in KS4_HEADLINE_COL_MAP.values()],
|
||||||
).to_dict()
|
).to_dict()
|
||||||
|
|
||||||
def get_records(self, context):
|
def get_records(self, context):
|
||||||
import pandas as pd
|
df = headline_rows(_read_ks4_summary(self.logger), "National")
|
||||||
|
|
||||||
self.logger.info("Downloading KS4 national headlines: %s", _KS4_NATIONAL_CSV_URL)
|
|
||||||
resp = requests.get(_KS4_NATIONAL_CSV_URL, timeout=60)
|
|
||||||
resp.raise_for_status()
|
|
||||||
|
|
||||||
df = pd.read_csv(io.BytesIO(resp.content), dtype=str, keep_default_na=False)
|
|
||||||
df.columns = [c.strip().lower() for c in df.columns]
|
|
||||||
|
|
||||||
for col, want in [
|
|
||||||
("geographic_level", "national"),
|
|
||||||
("establishment_type_group", "all state-funded"),
|
|
||||||
("breakdown_topic", "total"),
|
|
||||||
("breakdown", "total"),
|
|
||||||
]:
|
|
||||||
if col in df.columns:
|
|
||||||
df = df[df[col].str.strip().str.lower() == want]
|
|
||||||
|
|
||||||
self.logger.info("Emitting %d national KS4 rows", len(df))
|
self.logger.info("Emitting %d national KS4 rows", len(df))
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
record = {"time_period": row.get("time_period", "").strip()}
|
yield headline_record(row, ("time_period",))
|
||||||
for csv_col, field in _KS4_NATIONAL_COL_MAP.items():
|
|
||||||
record[field] = row.get(csv_col, "").strip()
|
|
||||||
yield record
|
class EESKs4LaStream(Stream):
|
||||||
|
"""DfE's KS4 local-authority averages — one row per academic year and LA
|
||||||
|
(all state-funded schools, all pupils), from the same data set as
|
||||||
|
ees_ks4_national. They match DfE's published performance-table LA averages
|
||||||
|
and replace a mean the API took over every school, independent and special
|
||||||
|
included (audit H2). old_la_code is the GIAS LA code: schools join on it,
|
||||||
|
not on the name."""
|
||||||
|
|
||||||
|
name = "ees_ks4_la"
|
||||||
|
primary_keys = ["time_period", "old_la_code"]
|
||||||
|
replication_key = None
|
||||||
|
|
||||||
|
schema = th.PropertiesList(
|
||||||
|
th.Property("time_period", th.StringType, required=True),
|
||||||
|
th.Property("old_la_code", th.StringType, required=True),
|
||||||
|
th.Property("new_la_code", th.StringType),
|
||||||
|
th.Property("la_name", th.StringType),
|
||||||
|
*[th.Property(out, th.StringType) for out in KS4_HEADLINE_COL_MAP.values()],
|
||||||
|
).to_dict()
|
||||||
|
|
||||||
|
def get_records(self, context):
|
||||||
|
df = headline_rows(_read_ks4_summary(self.logger), "Local authority")
|
||||||
|
self.logger.info("Emitting %d LA KS4 rows", len(df))
|
||||||
|
for _, row in df.iterrows():
|
||||||
|
yield headline_record(row, ("time_period", "old_la_code", "new_la_code", "la_name"))
|
||||||
|
|
||||||
|
|
||||||
# ── Legacy KS2 (pre-COVID wide format from DfE performance tables) ────────────
|
# ── Legacy KS2 (pre-COVID wide format from DfE performance tables) ────────────
|
||||||
@@ -972,6 +975,7 @@ class TapUKEES(Tap):
|
|||||||
LegacyKS4Stream(self),
|
LegacyKS4Stream(self),
|
||||||
EESKs2NationalStream(self),
|
EESKs2NationalStream(self),
|
||||||
EESKs4NationalStream(self),
|
EESKs4NationalStream(self),
|
||||||
|
EESKs4LaStream(self),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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,67 @@
|
|||||||
|
"""KS4 school information for 2023/24 exists only in the 2023/24 release,
|
||||||
|
whose file uses DfE's older column names. The stream declared only the newer
|
||||||
|
ones, so every 2023/24 field loaded as null (audit C2). The headers below are
|
||||||
|
DfE's, copied from 202324_information_about_schools_final.csv and
|
||||||
|
202425_information_about_schools_final.csv.
|
||||||
|
"""
|
||||||
|
import importlib.util
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
MODULE = (Path(__file__).resolve().parents[1] / 'plugins' / 'extractors' / 'tap-uk-ees'
|
||||||
|
/ 'tap_uk_ees' / 'ks4_info.py')
|
||||||
|
|
||||||
|
HEADER_2023_24 = (
|
||||||
|
'time_period', 'time_identifier', 'geographic_level', 'country_code', 'country_name',
|
||||||
|
'school_laestab', 'school_urn', 'school_name', 'old_la_code', 'new_la_code', 'la_name',
|
||||||
|
'version', 'establishment_type_group', 'full_address', 'telnum', 'pcon_code', 'pcon_name',
|
||||||
|
'contflag', 'iclose', 'reldenom', 'admpol_pt', 'egender', 'feeder', 'agerange',
|
||||||
|
't_allks_pupils', 't_allks_boys', 't_allks_girls', 't_pupils', 't_boys', 'pt_boys',
|
||||||
|
't_girls', 'pt_girls', 'avg_ks2_scaledscore', 't_prior_lo', 'pt_prior_lo', 't_prior_av',
|
||||||
|
'pt_prior_av', 't_prior_hi', 'pt_prior_hi', 't_disadvantaged', 'pt_disadvantaged',
|
||||||
|
't_not_disadvantaged', 'pt_not_disadvantaged', 't_language_not_english',
|
||||||
|
'pt_language_not_english', 't_language_english', 'pt_language_english',
|
||||||
|
't_language_unknown', 'pt_language_unknown', 't_not_mobile', 'pt_not_mobile',
|
||||||
|
't_sen_with_ehcp', 'pt_sen_with_ehcp', 't_sen', 'pt_sen', 't_sen_no_ehcp',
|
||||||
|
'pt_sen_no_ehcp', 'diffn_att8', 'diffn_p8mea', 'p8_banding',
|
||||||
|
)
|
||||||
|
|
||||||
|
HEADER_2024_25 = (
|
||||||
|
'time_period', 'time_identifier', 'geographic_level', 'country_code', 'country_name',
|
||||||
|
'school_laestab', 'school_urn', 'school_name', 'old_la_code', 'new_la_code', 'la_name',
|
||||||
|
'version', 'establishment_type_group', 'full_address', 'telnum', 'pcon_code', 'pcon_name',
|
||||||
|
'contflag', 'iclose', 'reldenom', 'admpol_pt', 'egender', 'feeder', 'agerange',
|
||||||
|
'allks_pupil_count', 'allks_boys_count', 'allks_girls_count', 'endks4_pupil_count',
|
||||||
|
'ks2_scaledscore_average', 'sen_with_ehcp_pupil_count', 'sen_with_ehcp_pupil_percent',
|
||||||
|
'sen_pupil_count', 'sen_pupil_percent', 'sen_no_ehcp_pupil_count',
|
||||||
|
'sen_no_ehcp_pupil_percent', 'attainment8_diffn', 'progress8_diffn', 'progress8_banding',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def ks4_info():
|
||||||
|
spec = importlib.util.spec_from_file_location('ks4_info', MODULE)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
def test_every_declared_field_is_in_the_2023_24_file_once_renamed(ks4_info):
|
||||||
|
renamed = {ks4_info.KS4_INFO_RENAMES.get(c, c) for c in HEADER_2023_24}
|
||||||
|
assert set(ks4_info.KS4_INFO_FIELDS) - renamed == set()
|
||||||
|
|
||||||
|
|
||||||
|
def test_every_declared_field_is_in_the_2024_25_file(ks4_info):
|
||||||
|
assert set(ks4_info.KS4_INFO_FIELDS) - set(HEADER_2024_25) == set()
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_renames_cannot_collide_with_either_file(ks4_info):
|
||||||
|
# An old name in the current file, or a new name already in the old file,
|
||||||
|
# would let a rename overwrite a real column.
|
||||||
|
assert set(ks4_info.KS4_INFO_RENAMES) & set(HEADER_2024_25) == set()
|
||||||
|
assert set(ks4_info.KS4_INFO_RENAMES.values()) & set(HEADER_2023_24) == set()
|
||||||
|
|
||||||
|
|
||||||
|
def test_every_rename_names_a_declared_field(ks4_info):
|
||||||
|
assert set(ks4_info.KS4_INFO_RENAMES.values()) <= set(ks4_info.KS4_INFO_FIELDS)
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
"""DfE's KS4 "summary, all state-funded" data set holds England, regional and
|
||||||
|
LA rows. The England stream kept only the England row; its LA rows match
|
||||||
|
DfE's published LA averages exactly, where the API's own mean was 7 points
|
||||||
|
low (audit H2). Values below are DfE's for Kensington and Chelsea (207) and
|
||||||
|
Wandsworth (212).
|
||||||
|
"""
|
||||||
|
import importlib.util
|
||||||
|
import io
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
MODULE = (Path(__file__).resolve().parents[1] / 'plugins' / 'extractors' / 'tap-uk-ees'
|
||||||
|
/ 'tap_uk_ees' / 'ks4_summary.py')
|
||||||
|
|
||||||
|
CSV = """time_period,geographic_level,old_la_code,new_la_code,la_name,establishment_type_group,breakdown_topic,breakdown,attainment8_average,progress8_average,engmath_94_percent,engmath_95_percent,ebacc_entering_percent,ebacc_94_percent,ebacc_95_percent,ebacc_aps_average
|
||||||
|
202425,National,,,,All state-funded,Total,Total,46.1,z,64.5,45.7,40.5,26.9,17.7,4.1
|
||||||
|
202425,National,,,,All state-funded,Sex,Boys,44.1,z,62.0,43.0,38.0,24.0,16.0,3.9
|
||||||
|
202425,Regional,,,,All state-funded,Total,Total,47.2,z,66.0,47.0,41.0,28.0,18.0,4.2
|
||||||
|
202425,Local authority,207,E09000020,Kensington and Chelsea,All state-funded,Total,Total,54.5,z,77,61.4,45.6,32,26.6,4.89
|
||||||
|
202425,Local authority,207,E09000020,Kensington and Chelsea,All state-funded,Sex,Girls,57.0,z,80,64.0,48.0,35,28.0,5.1
|
||||||
|
202324,Local authority,207,E09000020,Kensington and Chelsea,All state-funded,Total,Total,54.5,0.29,76,60.0,44.0,31,25.0,4.8
|
||||||
|
202425,Local authority,212,E09000032,Wandsworth,All state-funded,Total,Total,51.8,z,72,55.0,50.0,33,24.0,4.6
|
||||||
|
202425,Local authority,212,E09000032,Wandsworth,Academies and free schools,Total,Total,52.0,z,73,56.0,51.0,34,25.0,4.7
|
||||||
|
"""
|
||||||
|
|
||||||
|
LA_KEYS = ('time_period', 'old_la_code', 'new_la_code', 'la_name')
|
||||||
|
|
||||||
|
|
||||||
|
def _df():
|
||||||
|
return pd.read_csv(io.StringIO(CSV), dtype=str, keep_default_na=False)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def summary():
|
||||||
|
spec = importlib.util.spec_from_file_location('ks4_summary', MODULE)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
def test_la_rows_are_one_per_la_and_year(summary):
|
||||||
|
rows = summary.headline_rows(_df(), 'Local authority')
|
||||||
|
assert sorted(zip(rows['time_period'], rows['old_la_code'])) == [
|
||||||
|
('202324', '207'), ('202425', '207'), ('202425', '212')]
|
||||||
|
|
||||||
|
|
||||||
|
def test_an_la_record_carries_codes_name_and_the_headline_measures(summary):
|
||||||
|
rows = summary.headline_rows(_df(), 'Local authority')
|
||||||
|
row = rows[(rows['time_period'] == '202425') & (rows['old_la_code'] == '207')].iloc[0]
|
||||||
|
assert summary.headline_record(row, LA_KEYS) == {
|
||||||
|
'time_period': '202425', 'old_la_code': '207', 'new_la_code': 'E09000020',
|
||||||
|
'la_name': 'Kensington and Chelsea',
|
||||||
|
'attainment_8_score': '54.5', 'progress_8_score': 'z',
|
||||||
|
'english_maths_standard_pass_pct': '77', 'english_maths_strong_pass_pct': '61.4',
|
||||||
|
'ebacc_entry_pct': '45.6', 'ebacc_standard_pass_pct': '32',
|
||||||
|
'ebacc_strong_pass_pct': '26.6', 'ebacc_avg_score': '4.89',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_england_rows_are_one_per_year(summary):
|
||||||
|
rows = summary.headline_rows(_df(), 'National')
|
||||||
|
assert list(rows['time_period']) == ['202425']
|
||||||
|
assert summary.headline_record(rows.iloc[0], ('time_period',))['attainment_8_score'] == '46.1'
|
||||||
|
|
||||||
|
|
||||||
|
def test_column_names_and_labels_match_whatever_their_case(summary):
|
||||||
|
df = _df()
|
||||||
|
df.columns = [c.upper() for c in df.columns]
|
||||||
|
df['GEOGRAPHIC_LEVEL'] = df['GEOGRAPHIC_LEVEL'].str.upper()
|
||||||
|
assert len(summary.headline_rows(df, 'Local authority')) == 3
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
"""DfE re-publishes earlier years inside later KS4 releases.
|
||||||
|
|
||||||
|
The 2024/25 results file holds 2022/23, 2023/24 and 2024/25 under current
|
||||||
|
column names. The 2023/24 release's own file, re-issued in March 2026 under
|
||||||
|
older names, was read after it and overwrote every 2023/24 row with blanks
|
||||||
|
(audit C2). For the KS4 results stream the newest release owns every year it
|
||||||
|
contains.
|
||||||
|
"""
|
||||||
|
import importlib.util
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
TAP_DIR = (Path(__file__).resolve().parents[1] / 'plugins' / 'extractors' / 'tap-uk-ees'
|
||||||
|
/ 'tap_uk_ees')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def precedence():
|
||||||
|
spec = importlib.util.spec_from_file_location(
|
||||||
|
'release_precedence', TAP_DIR / 'release_precedence.py')
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
def _release(period):
|
||||||
|
return {'id': f'release-{period}', 'time_period': period}
|
||||||
|
|
||||||
|
|
||||||
|
def test_releases_are_taken_newest_first_whatever_order_the_api_gives(precedence):
|
||||||
|
releases = [_release('202223'), _release('202425'), _release(None), _release('202324')]
|
||||||
|
ordered = precedence.newest_first(releases)
|
||||||
|
assert [r['time_period'] for r in ordered] == ['202425', '202324', '202223', None]
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_year_a_newer_release_supplied_is_dropped_from_an_older_one(precedence):
|
||||||
|
newer = pd.DataFrame({'time_period': ['202425', '202324', '202223'], 'school_urn': ['1'] * 3})
|
||||||
|
older = pd.DataFrame({'time_period': ['202324', '202324', '201920'], 'school_urn': ['1', '2', '1']})
|
||||||
|
|
||||||
|
kept, skipped = precedence.drop_owned_periods(older, precedence.periods_in(newer))
|
||||||
|
|
||||||
|
assert list(kept['time_period']) == ['201920']
|
||||||
|
assert skipped == {'202324': 2}
|
||||||
|
|
||||||
|
|
||||||
|
def test_periods_match_despite_surrounding_spaces(precedence):
|
||||||
|
owned = precedence.periods_in(pd.DataFrame({'time_period': [' 202324 ']}))
|
||||||
|
kept, skipped = precedence.drop_owned_periods(pd.DataFrame({'time_period': ['202324']}), owned)
|
||||||
|
assert owned == {'202324'}
|
||||||
|
assert kept.empty
|
||||||
|
assert skipped == {'202324': 1}
|
||||||
|
|
||||||
|
|
||||||
|
def test_nothing_is_dropped_before_any_year_is_owned(precedence):
|
||||||
|
df = pd.DataFrame({'time_period': ['202324'], 'school_urn': ['1']})
|
||||||
|
kept, skipped = precedence.drop_owned_periods(df, set())
|
||||||
|
assert kept.equals(df)
|
||||||
|
assert skipped == {}
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_file_without_time_period_is_left_alone(precedence):
|
||||||
|
df = pd.DataFrame({'school_urn': ['1']})
|
||||||
|
kept, skipped = precedence.drop_owned_periods(df, {'202324'})
|
||||||
|
assert kept.equals(df)
|
||||||
|
assert skipped == {}
|
||||||
|
assert precedence.periods_in(df) == set()
|
||||||
|
|
||||||
|
|
||||||
|
def test_only_the_ks4_results_stream_opts_in():
|
||||||
|
# A general rule would wipe KS2: the 2024/25 KS2 file holds 98,448 of the
|
||||||
|
# 955,956 rows the 2023/24 release has for 2023/24.
|
||||||
|
source = (TAP_DIR / 'tap.py').read_text()
|
||||||
|
opted_in = [chunk.split('(')[0] for chunk in source.split('\nclass ')[1:]
|
||||||
|
if re.search(r'_newest_release_owns_period\s*=\s*True', chunk)]
|
||||||
|
assert opted_in == ['EESKS4PerformanceStream']
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('slug, period', [
|
||||||
|
('2024-25', '202425'),
|
||||||
|
('2024-25-revised', '202425'),
|
||||||
|
('2025-26-provisional', '202526'),
|
||||||
|
('latest', None),
|
||||||
|
('', None),
|
||||||
|
])
|
||||||
|
def test_a_release_slug_gives_its_year_whatever_its_suffix(precedence, slug, period):
|
||||||
|
# KS2 already publishes "2024-25-revised" and "2025-26-provisional". An
|
||||||
|
# unread suffix sent the release last, behind the provisional one for the
|
||||||
|
# same year, which then owned the year and dropped every revised row.
|
||||||
|
assert precedence.slug_to_time_period(slug) == period
|
||||||
|
|
||||||
|
|
||||||
|
def test_within_a_year_the_api_order_is_kept(precedence):
|
||||||
|
# The API lists a year's revised release before its first release.
|
||||||
|
releases = [{'id': 'revised', 'time_period': '202526'},
|
||||||
|
{'id': 'first', 'time_period': '202526'},
|
||||||
|
{'id': 'older', 'time_period': '202425'}]
|
||||||
|
assert [r['id'] for r in precedence.newest_first(releases)] == ['revised', 'first', 'older']
|
||||||
@@ -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
|
||||||
@@ -3,7 +3,9 @@
|
|||||||
Casts a string column to numeric, treating any non-numeric value as NULL.
|
Casts a string column to numeric, treating any non-numeric value as NULL.
|
||||||
Handles all EES suppression codes (z, c, x, q, u, etc.) without needing
|
Handles all EES suppression codes (z, c, x, q, u, etc.) without needing
|
||||||
an explicit list — any string that doesn't look like a number becomes NULL.
|
an explicit list — any string that doesn't look like a number becomes NULL.
|
||||||
|
A trailing percent sign is accepted: DfE's 2023/24 KS2 information file
|
||||||
|
writes percentages as "34%" (audit C2).
|
||||||
#}
|
#}
|
||||||
{% macro safe_numeric(col) -%}
|
{% macro safe_numeric(col) -%}
|
||||||
CASE WHEN {{ col }} ~ '^-?[0-9]+(\.[0-9]+)?$' THEN {{ col }}::numeric ELSE NULL END
|
CASE WHEN {{ col }} ~ '^-?[0-9]+(\.[0-9]+)?%?$' THEN rtrim({{ col }}, '%')::numeric ELSE NULL END
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
@@ -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:
|
||||||
@@ -255,11 +279,24 @@ models:
|
|||||||
tests: [not_null, unique]
|
tests: [not_null, unique]
|
||||||
|
|
||||||
- name: fact_ks4_national_averages
|
- name: fact_ks4_national_averages
|
||||||
description: Computed national KS4 averages (means across state schools in our dataset — not official DfE figures) — one row per academic year
|
description: Official DfE KS4 national headline averages (England, all state-funded schools, all pupils) — one row per academic year
|
||||||
columns:
|
columns:
|
||||||
- name: year
|
- name: year
|
||||||
tests: [not_null, unique]
|
tests: [not_null, unique]
|
||||||
|
|
||||||
|
- name: fact_ks4_la_averages
|
||||||
|
description: Official DfE KS4 local-authority averages (all state-funded schools, all pupils) — one row per academic year and LA; la_code is the GIAS LA code
|
||||||
|
columns:
|
||||||
|
- name: year
|
||||||
|
tests: [not_null]
|
||||||
|
- name: la_code
|
||||||
|
tests: [not_null]
|
||||||
|
- name: la_name
|
||||||
|
tests: [not_null]
|
||||||
|
tests:
|
||||||
|
- unique:
|
||||||
|
column_name: "year || '-' || la_code"
|
||||||
|
|
||||||
- name: fact_deprivation
|
- name: fact_deprivation
|
||||||
description: IDACI deprivation index — one row per URN
|
description: IDACI deprivation index — one row per URN
|
||||||
columns:
|
columns:
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ select
|
|||||||
s.nursery_provision,
|
s.nursery_provision,
|
||||||
s.admissions_policy_code,
|
s.admissions_policy_code,
|
||||||
|
|
||||||
-- Latest Ofsted (populated after monthly Ofsted pipeline runs)
|
-- Latest Ofsted (populated after monthly Ofsted pipeline runs). The grade
|
||||||
|
-- still in force and the latest visit, from int_ofsted_latest — never a
|
||||||
|
-- grade carried past a newer inspection.
|
||||||
{% if ofsted_relation is not none %}
|
{% if ofsted_relation is not none %}
|
||||||
-- Prefer the graded overall effectiveness; fall back to the grade parsed
|
o.current_grade as ofsted_grade,
|
||||||
-- from the latest ungraded (Section 8) outcome when no graded grade exists.
|
o.latest_visit_date as ofsted_date,
|
||||||
coalesce(o.overall_effectiveness, o.ungraded_grade) as ofsted_grade,
|
|
||||||
o.inspection_date as ofsted_date,
|
|
||||||
o.framework as ofsted_framework
|
o.framework as ofsted_framework
|
||||||
{% else %}
|
{% else %}
|
||||||
null::text as ofsted_grade,
|
null::text as ofsted_grade,
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
unit_tests:
|
||||||
|
- name: dim_school_ofsted_grade_is_the_one_still_in_force
|
||||||
|
description: >
|
||||||
|
Rabbsfarm (102408). Its 2025 inspection gave no overall grade, so the 2020
|
||||||
|
"School remains Good" must not reach dim_school (which feeds Typesense's
|
||||||
|
rating), and ofsted_date is the latest visit (audit C1, M1).
|
||||||
|
model: dim_school
|
||||||
|
given:
|
||||||
|
- input: ref('stg_gias_establishments')
|
||||||
|
rows:
|
||||||
|
- {urn: 102408, school_name: 'Rabbsfarm Primary School', status_code: 1, school_type_code: 1, local_authority_code: 312, phase_code: 2}
|
||||||
|
- input: ref('int_ofsted_latest')
|
||||||
|
rows:
|
||||||
|
- {urn: 102408, inspection_date: '2025-06-17', overall_effectiveness: null, ungraded_grade: 2, framework: 'Schools - S5', latest_visit_date: '2025-06-17', current_grade: null}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 102408, ofsted_grade: null, ofsted_date: '2025-06-17', ofsted_framework: 'Schools - S5'}
|
||||||
|
|
||||||
|
- name: dim_school_ofsted_grade_keeps_its_own_date_out_of_ofsted_date
|
||||||
|
description: >
|
||||||
|
Washwood Heath (139888). Good from a 2020 graded inspection; latest visit
|
||||||
|
an ungraded one in May 2025. ofsted_date is the latest visit.
|
||||||
|
model: dim_school
|
||||||
|
given:
|
||||||
|
- input: ref('stg_gias_establishments')
|
||||||
|
rows:
|
||||||
|
- {urn: 139888, school_name: 'Washwood Heath Academy', status_code: 1, school_type_code: 28, local_authority_code: 330, phase_code: 7}
|
||||||
|
- input: ref('int_ofsted_latest')
|
||||||
|
rows:
|
||||||
|
- {urn: 139888, inspection_date: '2020-03-03', overall_effectiveness: 2, ungraded_grade: null, framework: 'Schools - S5', latest_visit_date: '2025-05-21', current_grade: 2}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 139888, ofsted_grade: 2, ofsted_date: '2025-05-21'}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{{ config(materialized='table') }}
|
||||||
|
|
||||||
|
-- Mart: OFFICIAL DfE KS4 local-authority averages — one row per academic year
|
||||||
|
-- and LA (all state-funded schools, all pupils), from the same EES data set
|
||||||
|
-- as fact_ks4_national_averages. Feeds "vs LA avg" on search rows and map
|
||||||
|
-- cards, replacing a mean the API took over every school in the LA,
|
||||||
|
-- independent and special included (audit H2). la_code is the GIAS LA code.
|
||||||
|
|
||||||
|
select
|
||||||
|
year,
|
||||||
|
la_code,
|
||||||
|
la_name,
|
||||||
|
attainment_8_score,
|
||||||
|
progress_8_score,
|
||||||
|
english_maths_standard_pass_pct,
|
||||||
|
english_maths_strong_pass_pct,
|
||||||
|
ebacc_entry_pct,
|
||||||
|
ebacc_standard_pass_pct,
|
||||||
|
ebacc_strong_pass_pct,
|
||||||
|
ebacc_avg_score
|
||||||
|
from {{ ref('stg_ees_ks4_la') }}
|
||||||
|
order by year, la_code
|
||||||
@@ -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') }}
|
||||||
@@ -79,6 +79,9 @@ sources:
|
|||||||
- name: ees_ks4_national
|
- name: ees_ks4_national
|
||||||
description: Official KS4 national headline averages from DfE EES data catalogue — one row per academic year
|
description: Official KS4 national headline averages from DfE EES data catalogue — one row per academic year
|
||||||
|
|
||||||
|
- name: ees_ks4_la
|
||||||
|
description: Official KS4 local-authority averages (all state-funded schools) from the same DfE EES data set as ees_ks4_national — one row per academic year and LA
|
||||||
|
|
||||||
# Phonics: no school-level data on EES (only national/LA level)
|
# Phonics: no school-level data on EES (only national/LA level)
|
||||||
|
|
||||||
- name: fbit_finance
|
- name: fbit_finance
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
unit_tests:
|
||||||
|
- name: stg_ees_ks2_reads_percentages_written_with_a_sign
|
||||||
|
description: >
|
||||||
|
DfE's 2023/24 KS2 information file writes percentages as "34%", and every
|
||||||
|
2023/24 percentage loaded as null (audit C2). Plain numbers still load;
|
||||||
|
suppression codes stay null. School 147411's 2023/24 figures are DfE's.
|
||||||
|
model: stg_ees_ks2
|
||||||
|
given:
|
||||||
|
- input: source('raw', 'ees_ks2_attainment')
|
||||||
|
rows:
|
||||||
|
- {school_urn: '147411', time_period: '202324', subject: 'Reading, writing and maths', breakdown_topic: 'All pupils', breakdown: 'Total', expected_standard_pupil_percent: '70'}
|
||||||
|
- {school_urn: '100000', time_period: '202425', subject: 'Reading, writing and maths', breakdown_topic: 'All pupils', breakdown: 'Total', expected_standard_pupil_percent: '79'}
|
||||||
|
- input: source('raw', 'ees_ks2_info')
|
||||||
|
rows:
|
||||||
|
- {school_urn: '147411', time_period: '202324', totpups: '818', telig: '112', ptfsm6cla1a: '34%', ptealgrp2: '56%', psenelk: '20%', psenele: 'c', ptmobn: '87.5%'}
|
||||||
|
- {school_urn: '100000', time_period: '202425', totpups: '792', telig: '105', ptfsm6cla1a: '32', ptealgrp2: 'x', psenelk: '14', psenele: '2', ptmobn: '87'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {urn: 147411, year: 202324, total_pupils: 818, rwm_expected_pct: 70, disadvantaged_pct: 34, eal_pct: 56, sen_support_pct: 20, sen_ehcp_pct: null, stability_pct: 87.5}
|
||||||
|
- {urn: 100000, year: 202425, total_pupils: 792, rwm_expected_pct: 79, disadvantaged_pct: 32, eal_pct: null, sen_support_pct: 14, sen_ehcp_pct: 2, stability_pct: 87}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
-- Staging model: official DfE KS4 local-authority averages — one row per
|
||||||
|
-- academic year and LA (all state-funded schools, all pupils). Same EES data
|
||||||
|
-- set as stg_ees_ks4_national. la_code is the GIAS LA code
|
||||||
|
-- (dim_location.local_authority_code). Suppressed values ('z', 'x') are
|
||||||
|
-- coerced to NULL by safe_numeric.
|
||||||
|
|
||||||
|
select
|
||||||
|
cast(trim(time_period) as integer) as year,
|
||||||
|
cast(trim(old_la_code) as integer) as la_code,
|
||||||
|
trim(la_name) as la_name,
|
||||||
|
{{ safe_numeric('attainment_8_score') }} as attainment_8_score,
|
||||||
|
{{ safe_numeric('progress_8_score') }} as progress_8_score,
|
||||||
|
{{ safe_numeric('english_maths_standard_pass_pct') }} as english_maths_standard_pass_pct,
|
||||||
|
{{ safe_numeric('english_maths_strong_pass_pct') }} as english_maths_strong_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_entry_pct') }} as ebacc_entry_pct,
|
||||||
|
{{ safe_numeric('ebacc_standard_pass_pct') }} as ebacc_standard_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_strong_pass_pct') }} as ebacc_strong_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_avg_score') }} as ebacc_avg_score
|
||||||
|
from {{ source('raw', 'ees_ks4_la') }}
|
||||||
|
where time_period ~ '^[0-9]+$'
|
||||||
|
and old_la_code ~ '^[0-9]+$'
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
version: 2
|
||||||
|
|
||||||
|
unit_tests:
|
||||||
|
- name: stg_ees_ks4_la_casts_codes_years_and_measures
|
||||||
|
description: DfE's LA rows, keyed by the GIAS LA code. Suppressed values ('z') become null.
|
||||||
|
model: stg_ees_ks4_la
|
||||||
|
given:
|
||||||
|
- input: source('raw', 'ees_ks4_la')
|
||||||
|
rows:
|
||||||
|
- {time_period: '202425', old_la_code: '207', new_la_code: 'E09000020', la_name: 'Kensington and Chelsea', attainment_8_score: '54.5', progress_8_score: 'z', english_maths_standard_pass_pct: '77'}
|
||||||
|
- {time_period: '202324', old_la_code: '207', new_la_code: 'E09000020', la_name: 'Kensington and Chelsea', attainment_8_score: '54.5', progress_8_score: '0.29', english_maths_standard_pass_pct: '76'}
|
||||||
|
expect:
|
||||||
|
rows:
|
||||||
|
- {year: 202425, la_code: 207, la_name: 'Kensington and Chelsea', attainment_8_score: 54.5, progress_8_score: null, english_maths_standard_pass_pct: 77}
|
||||||
|
- {year: 202324, la_code: 207, la_name: 'Kensington and Chelsea', attainment_8_score: 54.5, progress_8_score: 0.29, english_maths_standard_pass_pct: 76}
|
||||||
@@ -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,31 +50,36 @@ 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
|
dated as (
|
||||||
)
|
select
|
||||||
|
*,
|
||||||
|
case
|
||||||
|
when rc_safeguarding_met is not null
|
||||||
|
or rc_inclusion is not null
|
||||||
|
or rc_curriculum_teaching is not null
|
||||||
|
or rc_achievement is not null
|
||||||
|
or rc_attendance_behaviour is not null
|
||||||
|
or rc_personal_development is not null
|
||||||
|
or rc_leadership_governance is not null
|
||||||
|
then rc_inspection_date_raw
|
||||||
|
end as rc_inspection_date
|
||||||
|
from renamed
|
||||||
)
|
)
|
||||||
|
|
||||||
select
|
select
|
||||||
*,
|
*,
|
||||||
case
|
-- For readers that predate the separate dates (fact_ofsted_inspection and
|
||||||
when rc_safeguarding_met is not null
|
-- the backend until it reads fact_ofsted_latest). Never null below.
|
||||||
or rc_inclusion is not null
|
coalesce(graded_inspection_date, ungraded_inspection_date, rc_inspection_date) as inspection_date
|
||||||
or rc_curriculum_teaching is not null
|
from dated
|
||||||
or rc_achievement is not null
|
where coalesce(graded_inspection_date, ungraded_inspection_date, rc_inspection_date) is not null
|
||||||
or rc_attendance_behaviour is not null
|
|
||||||
or rc_personal_development is not null
|
|
||||||
or rc_leadership_governance is not null
|
|
||||||
then rc_inspection_date_raw
|
|
||||||
end as rc_inspection_date
|
|
||||||
from renamed
|
|
||||||
where 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,16 @@
|
|||||||
|
-- Where a year's KS2 school information loaded (pupil counts present), its
|
||||||
|
-- percentages loaded too. DfE's files give a disadvantaged % for 96–97% of
|
||||||
|
-- those schools; 2023/24 loaded none because the file writes "34%" (audit
|
||||||
|
-- C2). A year without an information file (2022/23) has no pupil counts and
|
||||||
|
-- is skipped.
|
||||||
|
|
||||||
|
select
|
||||||
|
year,
|
||||||
|
count(total_pupils) as with_pupils,
|
||||||
|
count(*) filter (where total_pupils is not null and disadvantaged_pct is not null)
|
||||||
|
as with_disadvantaged
|
||||||
|
from {{ ref('stg_ees_ks2') }}
|
||||||
|
group by year
|
||||||
|
having count(total_pupils) >= 1000
|
||||||
|
and count(*) filter (where total_pupils is not null and disadvantaged_pct is not null)
|
||||||
|
< 0.9 * count(total_pupils)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-- DfE publishes an average for about 152 LAs a year. Fewer than 145 in the
|
||||||
|
-- latest year (or none at all) means the LA filter in tap_uk_ees
|
||||||
|
-- (ks4_summary.headline_rows) stopped matching, e.g. after DfE renamed a label.
|
||||||
|
|
||||||
|
with latest as (
|
||||||
|
select max(year) as year from {{ ref('fact_ks4_la_averages') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
select l.year, count(f.la_code) as las
|
||||||
|
from latest l
|
||||||
|
left join {{ ref('fact_ks4_la_averages') }} f on f.year = l.year
|
||||||
|
group by l.year
|
||||||
|
having count(f.la_code) < 145
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{{ config(severity='warn') }}
|
||||||
|
|
||||||
|
-- DfE's LA averages cover the latest year with school results. They come from
|
||||||
|
-- a fixed EES data set (ks4_summary.KS4_SUMMARY_CSV_URL); when DfE publishes a
|
||||||
|
-- new year under a new data set, the school results move on and this mart does
|
||||||
|
-- not, so /api/la-averages serves an empty map and every "vs LA avg" goes.
|
||||||
|
-- A warning, not an error: it must not hold back a new year's school results.
|
||||||
|
|
||||||
|
with schools as (
|
||||||
|
select max(year) as year from {{ ref('stg_ees_ks4') }} where attainment_8_score is not null
|
||||||
|
),
|
||||||
|
|
||||||
|
las as (
|
||||||
|
select max(year) as year from {{ ref('fact_ks4_la_averages') }}
|
||||||
|
)
|
||||||
|
|
||||||
|
select s.year as latest_school_year, l.year as latest_la_year
|
||||||
|
from schools s
|
||||||
|
cross join las l
|
||||||
|
where l.year is null or l.year < s.year
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
-- Every year loaded from EES has an Attainment 8 for at least half its
|
||||||
|
-- schools. DfE's files reach 82% each year; 2023/24 loaded at 0% after DfE
|
||||||
|
-- re-issued its file under older column names (audit C2). Pre-2019 years come
|
||||||
|
-- from stg_legacy_ks4 and are not checked here.
|
||||||
|
|
||||||
|
select
|
||||||
|
year,
|
||||||
|
count(*) as schools,
|
||||||
|
count(attainment_8_score) as with_attainment_8
|
||||||
|
from {{ ref('stg_ees_ks4') }}
|
||||||
|
group by year
|
||||||
|
having count(attainment_8_score) < 0.5 * count(*)
|
||||||
@@ -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