Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
870af949ee | ||
|
|
c6ff77f05b | ||
|
|
c7ddf0505d | ||
|
|
e659867590 | ||
|
|
c26b65246f | ||
|
|
3728a63275 | ||
|
|
90b7d09086 | ||
|
|
f86d6f45d1 | ||
|
|
5eed09dfa7 | ||
|
|
d37baa572b | ||
|
|
9ef48da4b1 | ||
|
|
a42c586cc8 | ||
|
|
a9e3a6a700 | ||
|
|
96732c56d1 | ||
|
|
befaf950a7 | ||
|
|
b6e48c4930 | ||
|
|
9f4f2507cc | ||
|
|
94bfac9caf | ||
|
|
65a2619e1d |
No files matched your search
+57
-10
@@ -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:
|
||||||
@@ -1272,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 = [
|
||||||
|
|||||||
+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"
|
||||||
|
|||||||
@@ -574,6 +574,7 @@ SCHOOL_COLUMNS = [
|
|||||||
"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"})
|
||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -417,12 +417,15 @@ test('a secondary search row compares its Attainment 8 with the LA average', asy
|
|||||||
// guards the comparison itself; the unit test pins the cache mode.
|
// guards the comparison itself; the unit test pins the cache mode.
|
||||||
const la = await (await page.request.get('/api/la-averages')).json();
|
const la = await (await page.request.get('/api/la-averages')).json();
|
||||||
const averages: Record<string, number> = la.secondary?.attainment_8_by_la ?? {};
|
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');
|
const res = await page.request.get('/api/schools?search=school&phase=secondary&page_size=50');
|
||||||
expect(res.ok()).toBeTruthy();
|
expect(res.ok()).toBeTruthy();
|
||||||
const school = ((await res.json()).schools ?? []).find(
|
const school = ((await res.json()).schools ?? []).find(
|
||||||
(s: { attainment_8_score?: number | null; local_authority?: string; school_type?: string }) =>
|
(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
|
s.attainment_8_score != null && s.local_authority != null && averages[s.local_authority] != null
|
||||||
&& !/special|pupil referral|alternative provision/i.test(s.school_type ?? ''));
|
&& !/special|pupil referral|alternative provision|independent/i.test(s.school_type ?? ''));
|
||||||
test.skip(!school, 'no mainstream secondary with an LA average here');
|
test.skip(!school, 'no mainstream secondary with an LA average here');
|
||||||
|
|
||||||
await searchByName(page, school.school_name);
|
await searchByName(page, school.school_name);
|
||||||
@@ -433,6 +436,52 @@ test('a secondary search row compares its Attainment 8 with the LA average', asy
|
|||||||
await expect(stats.getByText(/vs LA avg/)).toBeVisible();
|
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.
|
||||||
@@ -474,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();
|
||||||
|
|||||||
@@ -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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -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/);
|
||||||
|
});
|
||||||
@@ -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();
|
||||||
|
});
|
||||||
@@ -116,3 +116,38 @@ describe('SecondarySchoolRow shares the school page flags', () => {
|
|||||||
expect(screen.getByText('Fee-paying')).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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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', () => {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -147,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');
|
||||||
@@ -377,3 +391,20 @@ describe('singleSexLabel', () => {
|
|||||||
expect(singleSexLabel(undefined)).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);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -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' }),
|
||||||
|
|||||||
@@ -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' : '';
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
'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 { schoolFlags, schoolTypeLabel } from '@/lib/schoolFacts';
|
||||||
import styles from './SecondarySchoolRow.module.css';
|
import styles from './SecondarySchoolRow.module.css';
|
||||||
|
|
||||||
@@ -45,10 +45,12 @@ 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;
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -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"
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -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';
|
||||||
|
}
|
||||||
+23
-3
@@ -76,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;
|
||||||
}
|
}
|
||||||
@@ -95,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;
|
||||||
@@ -115,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. */
|
||||||
@@ -127,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;
|
||||||
|
|||||||
+26
-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
|
||||||
@@ -619,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 {
|
||||||
@@ -837,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;
|
||||||
@@ -858,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> = {
|
||||||
@@ -870,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' };
|
||||||
@@ -922,6 +758,16 @@ 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
|
* 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
|
* "Not applicable" are the register's ways of saying it has none; the place
|
||||||
|
|||||||
@@ -106,9 +106,12 @@ print(f'Validation passed: {{count}} GIAS rows')
|
|||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Marts fed by annual EES staging models are rebuilt by the EES DAG, even
|
||||||
|
# when they join dim_school. Selecting them here fails in any database
|
||||||
|
# where that DAG hasn't run (pipeline/tests/test_dag_selectors.py).
|
||||||
dbt_build = BashOperator(
|
dbt_build = BashOperator(
|
||||||
task_id="dbt_build",
|
task_id="dbt_build",
|
||||||
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_gias_establishments+ stg_gias_links+ gias_code_names+ --exclude int_ks2_with_lineage+ int_ks4_with_lineage+",
|
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_gias_establishments+ stg_gias_links+ gias_code_names+ --exclude int_ks2_with_lineage+ int_ks4_with_lineage+ stg_ees_ks4_destinations+ stg_ees_ks5_destinations+",
|
||||||
)
|
)
|
||||||
|
|
||||||
sync_typesense = BashOperator(
|
sync_typesense = BashOperator(
|
||||||
@@ -143,7 +146,7 @@ with DAG(
|
|||||||
|
|
||||||
dbt_build_ofsted = BashOperator(
|
dbt_build_ofsted = BashOperator(
|
||||||
task_id="dbt_build",
|
task_id="dbt_build",
|
||||||
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_ofsted_inspections+ int_ofsted_latest+ fact_ofsted_inspection+ dim_school+",
|
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_ofsted_inspections+ int_ofsted_latest+ fact_ofsted_inspection+ dim_school+ --exclude stg_ees_ks4_destinations+ stg_ees_ks5_destinations+",
|
||||||
)
|
)
|
||||||
|
|
||||||
sync_typesense_ofsted = BashOperator(
|
sync_typesense_ofsted = BashOperator(
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
"""Read a GIAS extract from the raw bytes of the download.
|
||||||
|
|
||||||
|
GIAS writes its CSVs in Windows-1252 and sends no charset, so `resp.text`
|
||||||
|
leaves requests to guess the codec. On 3 Oct 2026 it guessed windows-1250 and
|
||||||
|
"à" became "ŕ". Decode the bytes ourselves instead.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import io
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
GIAS_ENCODING = "cp1252"
|
||||||
|
|
||||||
|
|
||||||
|
def read_gias_csv(content: bytes, logger=None) -> pd.DataFrame:
|
||||||
|
"""Every column as a string; a blank cell stays ''."""
|
||||||
|
# Windows-1252 leaves five bytes undefined. One stray byte must not stop
|
||||||
|
# the daily refresh of every school, so it becomes U+FFFD and is logged.
|
||||||
|
text = content.decode(GIAS_ENCODING, errors="replace")
|
||||||
|
undecodable = text.count("�")
|
||||||
|
if undecodable and logger is not None:
|
||||||
|
logger.warning("%d byte(s) in the GIAS extract could not be decoded as %s",
|
||||||
|
undecodable, GIAS_ENCODING)
|
||||||
|
return pd.read_csv(io.StringIO(text), dtype=str, keep_default_na=False)
|
||||||
@@ -7,6 +7,8 @@ from datetime import date, timedelta
|
|||||||
from singer_sdk import Stream, Tap
|
from singer_sdk import Stream, Tap
|
||||||
from singer_sdk import typing as th
|
from singer_sdk import typing as th
|
||||||
|
|
||||||
|
from tap_uk_gias.gias_csv import read_gias_csv
|
||||||
|
|
||||||
GIAS_URL_TEMPLATE = (
|
GIAS_URL_TEMPLATE = (
|
||||||
"https://ea-edubase-api-prod.azurewebsites.net"
|
"https://ea-edubase-api-prod.azurewebsites.net"
|
||||||
"/edubase/downloads/public/edubasealldata{date}.csv"
|
"/edubase/downloads/public/edubasealldata{date}.csv"
|
||||||
@@ -74,9 +76,6 @@ class GIASEstablishmentsStream(Stream):
|
|||||||
|
|
||||||
def get_records(self, context):
|
def get_records(self, context):
|
||||||
"""Download GIAS CSV and yield rows."""
|
"""Download GIAS CSV and yield rows."""
|
||||||
import io
|
|
||||||
|
|
||||||
import pandas as pd
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
today = date.today()
|
today = date.today()
|
||||||
@@ -94,12 +93,7 @@ class GIASEstablishmentsStream(Stream):
|
|||||||
|
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
df = pd.read_csv(
|
df = read_gias_csv(resp.content, self.logger)
|
||||||
io.StringIO(resp.text),
|
|
||||||
encoding="latin-1",
|
|
||||||
dtype=str,
|
|
||||||
keep_default_na=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
record = row.to_dict()
|
record = row.to_dict()
|
||||||
@@ -126,9 +120,6 @@ class GIASLinksStream(Stream):
|
|||||||
|
|
||||||
def get_records(self, context):
|
def get_records(self, context):
|
||||||
"""Download GIAS links CSV and yield rows."""
|
"""Download GIAS links CSV and yield rows."""
|
||||||
import io
|
|
||||||
|
|
||||||
import pandas as pd
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
today = date.today()
|
today = date.today()
|
||||||
@@ -146,12 +137,7 @@ class GIASLinksStream(Stream):
|
|||||||
|
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
df = pd.read_csv(
|
df = read_gias_csv(resp.content, self.logger)
|
||||||
io.StringIO(resp.text),
|
|
||||||
encoding="latin-1",
|
|
||||||
dtype=str,
|
|
||||||
keep_default_na=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
record = row.to_dict()
|
record = row.to_dict()
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
"""Every scheduled dbt build must only build models whose parents exist.
|
||||||
|
|
||||||
|
The daily GIAS build selects `stg_gias_establishments+`, so any mart that joins
|
||||||
|
dim_school joins the daily build too. When such a mart also reads a staging
|
||||||
|
model that only the manually triggered EES DAG builds, the daily build fails in
|
||||||
|
any database where that DAG has not run since. Sync and cache invalidation then
|
||||||
|
never run either. The destinations marts did this from late August 2026.
|
||||||
|
|
||||||
|
The graph is read from the model SQL, because CI has no dbt.
|
||||||
|
"""
|
||||||
|
import re
|
||||||
|
from collections import defaultdict
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
PIPELINE = Path(__file__).resolve().parents[1]
|
||||||
|
MODELS = PIPELINE / 'transform' / 'models'
|
||||||
|
DAG_FILE = PIPELINE / 'dags' / 'school_data_pipeline.py'
|
||||||
|
|
||||||
|
REF = re.compile(r"ref\(\s*'([a-z0-9_]+)'\s*\)")
|
||||||
|
DBT_BUILD = re.compile(r'dbt_build\w*\s*=\s*BashOperator\(.*?build --profiles-dir \. --target production ([^"]+)"', re.S)
|
||||||
|
DAG_ID = re.compile(r'dag_id="([a-z0-9_]+)"')
|
||||||
|
|
||||||
|
DAILY = 'school_data_daily'
|
||||||
|
|
||||||
|
# dim_school reads int_ofsted_latest only when the relation exists
|
||||||
|
# (adapter.get_relation), so a missing table is not a failure.
|
||||||
|
OPTIONAL_PARENTS = {'int_ofsted_latest'}
|
||||||
|
|
||||||
|
|
||||||
|
def model_parents():
|
||||||
|
"""{model: models it refs}. Seeds are left out: they are loaded once and always exist."""
|
||||||
|
sql = {p.stem: p.read_text() for p in MODELS.rglob('*.sql')}
|
||||||
|
return {name: set(REF.findall(text)) & set(sql) for name, text in sql.items()}
|
||||||
|
|
||||||
|
|
||||||
|
def downstream(node, children):
|
||||||
|
seen, stack = {node}, [node]
|
||||||
|
while stack:
|
||||||
|
for child in children[stack.pop()]:
|
||||||
|
if child not in seen:
|
||||||
|
seen.add(child)
|
||||||
|
stack.append(child)
|
||||||
|
return seen
|
||||||
|
|
||||||
|
|
||||||
|
def expand(tokens, children):
|
||||||
|
out = set()
|
||||||
|
for token in tokens:
|
||||||
|
out |= downstream(token[:-1], children) if token.endswith('+') else {token}
|
||||||
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def scheduled_builds():
|
||||||
|
"""{dag_id: dbt selection arguments} for every dbt build in the DAG file."""
|
||||||
|
text = DAG_FILE.read_text()
|
||||||
|
starts = [(m.start(), m.group(1)) for m in DAG_ID.finditer(text)]
|
||||||
|
builds = {}
|
||||||
|
for i, (start, dag_id) in enumerate(starts):
|
||||||
|
end = starts[i + 1][0] if i + 1 < len(starts) else len(text)
|
||||||
|
found = DBT_BUILD.search(text, start, end)
|
||||||
|
if found:
|
||||||
|
builds[dag_id] = found.group(1)
|
||||||
|
return builds
|
||||||
|
|
||||||
|
|
||||||
|
def selected_models(args, parents):
|
||||||
|
children = defaultdict(set)
|
||||||
|
for model, ps in parents.items():
|
||||||
|
for p in ps:
|
||||||
|
children[p].add(model)
|
||||||
|
select = re.search(r'--select (.+?)(?= --exclude|$)', args).group(1).split()
|
||||||
|
excluded = re.search(r'--exclude (.+)$', args)
|
||||||
|
exclude = excluded.group(1).split() if excluded else []
|
||||||
|
return (expand(select, children) - expand(exclude, children)) & set(parents)
|
||||||
|
|
||||||
|
|
||||||
|
PARENTS = model_parents()
|
||||||
|
BUILDS = scheduled_builds()
|
||||||
|
DAILY_MODELS = selected_models(BUILDS[DAILY], PARENTS)
|
||||||
|
|
||||||
|
|
||||||
|
def test_every_dag_with_a_dbt_build_is_parsed():
|
||||||
|
assert set(BUILDS) == {
|
||||||
|
'school_data_daily', 'school_data_monthly_ofsted', 'school_data_annual_ees',
|
||||||
|
'school_data_annual_idaci', 'school_data_annual_distance',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('dag_id', sorted(BUILDS))
|
||||||
|
def test_selected_models_only_read_models_that_exist(dag_id):
|
||||||
|
selected = selected_models(BUILDS[dag_id], PARENTS)
|
||||||
|
# The daily build is the base layer: other DAGs may rely on what it builds.
|
||||||
|
available = selected | OPTIONAL_PARENTS | (DAILY_MODELS if dag_id != DAILY else set())
|
||||||
|
missing = {model: sorted(PARENTS[model] - available) for model in sorted(selected)
|
||||||
|
if PARENTS[model] - available}
|
||||||
|
assert missing == {}, f'{dag_id} builds models whose parents it never builds: {missing}'
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
"""GIAS publishes its extracts in Windows-1252 and declares no charset.
|
||||||
|
|
||||||
|
The tap used to hand pandas `resp.text`, so requests guessed the codec.
|
||||||
|
On 3 Oct 2026 it guessed windows-1250, and "St Thomas à Becket" was stored
|
||||||
|
as "St Thomas ŕ Becket". The `encoding=` passed to read_csv did nothing,
|
||||||
|
because the text was already decoded.
|
||||||
|
"""
|
||||||
|
import importlib.util
|
||||||
|
import logging
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
MODULE = (Path(__file__).resolve().parents[1] / 'plugins' / 'extractors' / 'tap-uk-gias'
|
||||||
|
/ 'tap_uk_gias' / 'gias_csv.py')
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def gias_csv():
|
||||||
|
spec = importlib.util.spec_from_file_location('gias_csv', MODULE)
|
||||||
|
module = importlib.util.module_from_spec(spec)
|
||||||
|
spec.loader.exec_module(module)
|
||||||
|
return module
|
||||||
|
|
||||||
|
|
||||||
|
# Byte for byte as GIAS writes it: 0xE0 à, 0x92 ’, 0xE9 é, 0xB0 °, 0xE7 ç.
|
||||||
|
EXTRACT = (
|
||||||
|
b'"URN","EstablishmentName","HeadLastName"\r\n'
|
||||||
|
b'"138950","St Thomas \xe0 Becket Catholic Secondary School","Smith"\r\n'
|
||||||
|
b'"100000","The Dean and Chapter of St Paul\x92s Cathedral","Pr\xe9vert"\r\n'
|
||||||
|
b'"140677","North Star 180\xb0","Fran\xe7ois"\r\n'
|
||||||
|
b'"100001","No head recorded",""\r\n'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_names_decode_as_windows_1252(gias_csv):
|
||||||
|
df = gias_csv.read_gias_csv(EXTRACT)
|
||||||
|
assert list(df['EstablishmentName']) == [
|
||||||
|
'St Thomas à Becket Catholic Secondary School',
|
||||||
|
'The Dean and Chapter of St Paul’s Cathedral',
|
||||||
|
'North Star 180°',
|
||||||
|
'No head recorded',
|
||||||
|
]
|
||||||
|
assert list(df['HeadLastName']) == ['Smith', 'Prévert', 'François', '']
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_codec_requests_guessed_is_not_used(gias_csv):
|
||||||
|
# What the tap stored on 3 Oct: the same bytes read as windows-1250.
|
||||||
|
assert 'ŕ' in EXTRACT.decode('cp1250')
|
||||||
|
names = ' '.join(gias_csv.read_gias_csv(EXTRACT)['EstablishmentName'])
|
||||||
|
assert 'ŕ' not in names
|
||||||
|
|
||||||
|
|
||||||
|
def test_values_stay_strings(gias_csv):
|
||||||
|
df = gias_csv.read_gias_csv(EXTRACT)
|
||||||
|
assert df.loc[0, 'URN'] == '138950'
|
||||||
|
|
||||||
|
|
||||||
|
def test_a_byte_windows_1252_leaves_undefined_does_not_stop_the_load(gias_csv, caplog):
|
||||||
|
# 0x81 has no Windows-1252 character. One odd name must not block the daily
|
||||||
|
# refresh of every school, but it must be visible in the log.
|
||||||
|
extract = b'"URN","EstablishmentName"\r\n"100002","Odd \x81 Name"\r\n'
|
||||||
|
with caplog.at_level(logging.WARNING):
|
||||||
|
df = gias_csv.read_gias_csv(extract, logger=logging.getLogger('gias'))
|
||||||
|
assert df.loc[0, 'EstablishmentName'] == 'Odd � Name'
|
||||||
|
assert 'could not be decoded' in caplog.text
|
||||||
@@ -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'}
|
||||||
Reference in new issue
Block a user