Compare commits
75
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c1df77961 | ||
|
|
5e370d09f1 | ||
|
|
f6bb037c47 | ||
|
|
9c93c3d9c2 | ||
|
|
17bd4d5a5e | ||
|
|
31ae13451a | ||
|
|
4e6be0ce65 | ||
|
|
452ec77449 | ||
|
|
aa87fa917d | ||
|
|
e36125b24a | ||
|
|
fdda52ff0a | ||
|
|
a2c63b3cda | ||
|
|
b2b2cad5ac | ||
|
|
5ec4f3f7cd | ||
|
|
74bdbebd57 | ||
|
|
b31e71ac88 | ||
|
|
b05f3bebc7 | ||
|
|
ce422e6436 | ||
|
|
2ac26acf91 | ||
|
|
3e77057567 | ||
|
|
e0d5a9969e | ||
|
|
dc21e80a5e | ||
|
|
6d3a203699 | ||
|
|
b0c5b6bb57 | ||
|
|
a1128bd801 | ||
|
|
2fd997bfe6 | ||
|
|
bdd9bef349 | ||
|
|
e5f7f4c959 | ||
|
|
60918da483 | ||
|
|
284215fbce | ||
|
|
200a97d0b9 | ||
|
|
f3fa12806b | ||
|
|
1004f08daf | ||
|
|
79246edc22 | ||
|
|
64b63b96c8 | ||
|
|
5944d88f0b | ||
|
|
163b501be6 | ||
|
|
80176cac4d | ||
|
|
84baf95f68 | ||
|
|
99b769ca9e | ||
|
|
e8f78a1598 | ||
|
|
8e0b730629 | ||
|
|
20a27f3958 | ||
|
|
852ed11e4d | ||
|
|
77d7052662 | ||
|
|
c9e324635b | ||
|
|
1d855f3c17 | ||
|
|
9773483221 | ||
|
|
e00a1b38a8 | ||
|
|
026a7ab6aa | ||
|
|
a86a2be96c | ||
|
|
d98e88f0b4 | ||
|
|
609bb923d9 | ||
|
|
4bfcd9ba9a | ||
|
|
95f10bf352 | ||
|
|
674470ceb6 | ||
|
|
8abff7a0a1 | ||
|
|
6f62c25f47 | ||
|
|
e74d3882ce | ||
|
|
3fb3db1cc4 | ||
|
|
b4b0249a06 | ||
|
|
e39aef2935 | ||
|
|
fef83b3bf2 | ||
|
|
cf458fe05c | ||
|
|
f579630fab | ||
|
|
19b41b6999 | ||
|
|
66bc5523f6 | ||
|
|
3cb72d0a0f | ||
|
|
b89fa47ec5 | ||
|
|
0c7ad0f309 | ||
|
|
e4565e9f15 | ||
|
|
06e4898c30 | ||
|
|
a9611e21c3 | ||
|
|
0696518995 | ||
|
|
315f1feede |
@@ -67,9 +67,12 @@ jobs:
|
|||||||
echo "Promoting $FULL_SHA (images tagged $SHORT_SHA)"
|
echo "Promoting $FULL_SHA (images tagged $SHORT_SHA)"
|
||||||
|
|
||||||
- name: Verify the staging E2E gate passed for this commit
|
- name: Verify the staging E2E gate passed for this commit
|
||||||
|
# Use the built-in Actions token (GITHUB_TOKEN is the documented name;
|
||||||
|
# it carries repository read scope), NOT REGISTRY_TOKEN — the registry
|
||||||
|
# token has no repo scope, so the commit-status API returns 403.
|
||||||
run: |
|
run: |
|
||||||
STATUS_JSON=$(curl -fsS \
|
STATUS_JSON=$(curl -fsS \
|
||||||
-H "Authorization: token ${{ secrets.REGISTRY_TOKEN }}" \
|
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||||
"https://${REGISTRY}/api/v1/repos/${{ gitea.repository }}/commits/${{ steps.resolve.outputs.full }}/status")
|
"https://${REGISTRY}/api/v1/repos/${{ gitea.repository }}/commits/${{ steps.resolve.outputs.full }}/status")
|
||||||
echo "$STATUS_JSON" | python3 -c "
|
echo "$STATUS_JSON" | python3 -c "
|
||||||
import json, sys
|
import json, sys
|
||||||
|
|||||||
@@ -1,2 +1,7 @@
|
|||||||
venv
|
venv
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|
||||||
|
# dbt local build artifacts (embed absolute paths + anonymous-usage UUID)
|
||||||
|
pipeline/transform/target/
|
||||||
|
pipeline/transform/logs/
|
||||||
|
pipeline/transform/.user.yml
|
||||||
|
|||||||
+39
-24
@@ -30,6 +30,7 @@ from .data_loader import (
|
|||||||
load_latest_school_data,
|
load_latest_school_data,
|
||||||
geocode_single_postcode,
|
geocode_single_postcode,
|
||||||
get_supplementary_data,
|
get_supplementary_data,
|
||||||
|
get_supplementary_data_batch,
|
||||||
search_schools_typesense,
|
search_schools_typesense,
|
||||||
)
|
)
|
||||||
from .data_loader import get_data_info as get_db_info
|
from .data_loader import get_data_info as get_db_info
|
||||||
@@ -676,15 +677,43 @@ async def compare_schools(
|
|||||||
"deprivation": None,
|
"deprivation": None,
|
||||||
}
|
}
|
||||||
supplementary_by_urn: dict = {}
|
supplementary_by_urn: dict = {}
|
||||||
|
census_benchmarks = None
|
||||||
db = None
|
db = None
|
||||||
try:
|
try:
|
||||||
db = database.SessionLocal()
|
db = database.SessionLocal()
|
||||||
|
# One query per table for all schools, not ~5 queries per school.
|
||||||
|
batch = get_supplementary_data_batch(db, urn_list)
|
||||||
for urn in urn_list:
|
for urn in urn_list:
|
||||||
supp = get_supplementary_data(db, urn)
|
supp = batch.get(urn, {})
|
||||||
supplementary_by_urn[urn] = {
|
supplementary_by_urn[urn] = {
|
||||||
key: supp.get(key, default)
|
key: supp.get(key, default)
|
||||||
for key, default in _EMPTY_SUPPLEMENTARY.items()
|
for key, default in _EMPTY_SUPPLEMENTARY.items()
|
||||||
}
|
}
|
||||||
|
# Import-time census context benchmarks (fact_census_benchmarks);
|
||||||
|
# absent mart → None, and compute_benchmarks leaves those fields null.
|
||||||
|
try:
|
||||||
|
from .models import CensusBenchmark
|
||||||
|
|
||||||
|
rows = db.query(CensusBenchmark).all()
|
||||||
|
by_phase = {
|
||||||
|
r.phase: {
|
||||||
|
"year": r.year,
|
||||||
|
"fsm_pct": r.fsm_pct,
|
||||||
|
"eal_pct": r.eal_pct,
|
||||||
|
"median_pupils": r.median_pupils,
|
||||||
|
}
|
||||||
|
for r in rows
|
||||||
|
if getattr(r, "phase", None) in ("primary", "secondary")
|
||||||
|
}
|
||||||
|
if by_phase:
|
||||||
|
census_benchmarks = by_phase
|
||||||
|
except Exception:
|
||||||
|
# Missing mart (or a stubbed session in tests) must never break
|
||||||
|
# the compare payload — and not every session has rollback().
|
||||||
|
try:
|
||||||
|
db.rollback()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
supplementary_by_urn = {}
|
supplementary_by_urn = {}
|
||||||
finally:
|
finally:
|
||||||
@@ -711,6 +740,9 @@ async def compare_schools(
|
|||||||
"religious_denomination": convert_to_native(latest.get("religious_denomination")),
|
"religious_denomination": convert_to_native(latest.get("religious_denomination")),
|
||||||
"age_range": convert_to_native(latest.get("age_range")),
|
"age_range": convert_to_native(latest.get("age_range")),
|
||||||
"gender": convert_to_native(latest.get("gender")),
|
"gender": convert_to_native(latest.get("gender")),
|
||||||
|
# Needed by the admissions "What this means" copy: selective
|
||||||
|
# schools get entrance-test framing, never the distance template.
|
||||||
|
"admissions_policy": convert_to_native(latest.get("admissions_policy")),
|
||||||
"has_sixth_form": convert_to_native(latest.get("has_sixth_form")),
|
"has_sixth_form": convert_to_native(latest.get("has_sixth_form")),
|
||||||
"capacity": convert_to_native(latest.get("capacity")),
|
"capacity": convert_to_native(latest.get("capacity")),
|
||||||
"gias_total_pupils": convert_to_native(latest.get("gias_total_pupils")),
|
"gias_total_pupils": convert_to_native(latest.get("gias_total_pupils")),
|
||||||
@@ -725,7 +757,7 @@ async def compare_schools(
|
|||||||
# Official DfE anchors + computed state-school benchmarks so the
|
# Official DfE anchors + computed state-school benchmarks so the
|
||||||
# compare UI can label provenance correctly (spec §8.6).
|
# compare UI can label provenance correctly (spec §8.6).
|
||||||
"national_averages": _national_averages_payload(df),
|
"national_averages": _national_averages_payload(df),
|
||||||
"benchmarks": compute_benchmarks(df),
|
"benchmarks": compute_benchmarks(df, census_benchmarks=census_benchmarks),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -794,11 +826,11 @@ def _national_averages_payload(df: pd.DataFrame) -> dict:
|
|||||||
/api/compare.
|
/api/compare.
|
||||||
|
|
||||||
Both series are persisted marts computed at import time: official DfE
|
Both series are persisted marts computed at import time: official DfE
|
||||||
KS2 figures (fact_ks2_national_averages) and dataset-computed KS4
|
KS2 figures (fact_ks2_national_averages) and official DfE KS4 figures
|
||||||
averages (fact_ks4_national_averages) — the API never aggregates the
|
(fact_ks4_national_averages) — the API never aggregates the performance
|
||||||
performance dataframe per request. If the KS4 mart hasn't been built
|
dataframe per request. If the KS4 mart hasn't been built yet, the
|
||||||
yet (deploy lands before the next DAG run), fall back to computing the
|
secondary series is empty — never a computed stand-in, because the UI
|
||||||
latest year only — a single-year scan, never the historical loop.
|
labels these figures as official DfE data.
|
||||||
"""
|
"""
|
||||||
if df.empty:
|
if df.empty:
|
||||||
return {"primary": {}, "secondary": {}}
|
return {"primary": {}, "secondary": {}}
|
||||||
@@ -838,23 +870,6 @@ def _national_averages_payload(df: pd.DataFrame) -> dict:
|
|||||||
primary_by_year = {r.year: _row_metrics(r, _KS2_NATIONAL_METRICS) for r in ks2_rows}
|
primary_by_year = {r.year: _row_metrics(r, _KS2_NATIONAL_METRICS) for r in ks2_rows}
|
||||||
secondary_by_year = {r.year: _row_metrics(r, _KS4_NATIONAL_METRICS) for r in ks4_rows}
|
secondary_by_year = {r.year: _row_metrics(r, _KS4_NATIONAL_METRICS) for r in ks4_rows}
|
||||||
|
|
||||||
if not any(secondary_by_year.values()):
|
|
||||||
# KS4 mart missing/empty: compute the latest year only.
|
|
||||||
df_latest = df[df["year"] == latest_year]
|
|
||||||
sec = (
|
|
||||||
df_latest[df_latest["attainment_8_score"].notna()]
|
|
||||||
if "attainment_8_score" in df_latest.columns
|
|
||||||
else df_latest.iloc[0:0]
|
|
||||||
)
|
|
||||||
vals = {}
|
|
||||||
for col in _KS4_NATIONAL_METRICS:
|
|
||||||
if col in sec.columns:
|
|
||||||
v = sec[col].dropna()
|
|
||||||
if len(v) > 0:
|
|
||||||
vals[col] = round(float(v.mean()), 2)
|
|
||||||
if vals:
|
|
||||||
secondary_by_year[latest_year] = vals
|
|
||||||
|
|
||||||
all_years = sorted(set(primary_by_year) | set(secondary_by_year))
|
all_years = sorted(set(primary_by_year) | set(secondary_by_year))
|
||||||
by_year = [
|
by_year = [
|
||||||
{
|
{
|
||||||
|
|||||||
+162
-89
@@ -172,6 +172,7 @@ _MAIN_QUERY = text("""
|
|||||||
foi.ofsted_grade,
|
foi.ofsted_grade,
|
||||||
foi.ofsted_date,
|
foi.ofsted_date,
|
||||||
foi.ofsted_framework,
|
foi.ofsted_framework,
|
||||||
|
foi.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,
|
||||||
@@ -256,7 +257,12 @@ _MAIN_QUERY = text("""
|
|||||||
-- Fall back to the ungraded-inspection grade when no graded grade exists.
|
-- Fall back to the ungraded-inspection grade when no graded grade exists.
|
||||||
COALESCE(overall_effectiveness, ungraded_grade) AS ofsted_grade,
|
COALESCE(overall_effectiveness, ungraded_grade) AS ofsted_grade,
|
||||||
inspection_date AS ofsted_date,
|
inspection_date AS ofsted_date,
|
||||||
framework AS ofsted_framework
|
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
|
FROM marts.fact_ofsted_inspection
|
||||||
ORDER BY urn, inspection_date DESC NULLS LAST
|
ORDER BY urn, inspection_date DESC NULLS LAST
|
||||||
) foi ON s.urn = foi.urn
|
) foi ON s.urn = foi.urn
|
||||||
@@ -525,13 +531,20 @@ def get_data_info(db: Session = None) -> dict:
|
|||||||
# SUPPLEMENTARY DATA — per-school detail page
|
# SUPPLEMENTARY DATA — per-school detail page
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
def compute_benchmarks(df: pd.DataFrame) -> dict:
|
def compute_benchmarks(df: pd.DataFrame, census_benchmarks: dict | None = None) -> dict:
|
||||||
"""State-school benchmarks computed from our dataset (spec §5/§8.6).
|
"""State-school benchmarks computed from our dataset (spec §5/§8.6).
|
||||||
|
|
||||||
NOT official DfE figures — consumers must label them
|
NOT official DfE figures — consumers must label them
|
||||||
"state-school average (computed from our dataset)". The disadvantaged
|
"state-school average (computed from our dataset)". The disadvantaged
|
||||||
attainment average is weighted by cohort size (eligible_pupils) so
|
attainment average is weighted by cohort size (eligible_pupils) so
|
||||||
small schools don't dominate; context measures are medians.
|
small schools don't dominate.
|
||||||
|
|
||||||
|
Context measures (FSM/EAL/pupil counts) come from `census_benchmarks`
|
||||||
|
(the fact_census_benchmarks mart, pupil-weighted, keyed by phase): the
|
||||||
|
performance df has no fsm_pct at all, and its eal/disadvantaged columns
|
||||||
|
are KS2-only — medianing them for "secondary" produced junk anchors
|
||||||
|
from the handful of all-through schools. When the mart is unavailable
|
||||||
|
these are None; never fall back across measure definitions.
|
||||||
"""
|
"""
|
||||||
if df.empty or "year" not in df.columns:
|
if df.empty or "year" not in df.columns:
|
||||||
return {}
|
return {}
|
||||||
@@ -567,17 +580,14 @@ def compute_benchmarks(df: pd.DataFrame) -> dict:
|
|||||||
)
|
)
|
||||||
return round(float(w), 1)
|
return round(float(w), 1)
|
||||||
|
|
||||||
def _block(sub, with_disadvantaged):
|
def _block(sub, phase, with_disadvantaged):
|
||||||
median_pupils = None
|
census = (census_benchmarks or {}).get(phase) or {}
|
||||||
if "total_pupils" in sub.columns:
|
|
||||||
mp = sub["total_pupils"].median()
|
|
||||||
if pd.notna(mp):
|
|
||||||
median_pupils = int(mp)
|
|
||||||
block = {
|
block = {
|
||||||
"eal_pct": _median(sub, "eal_pct"),
|
"eal_pct": census.get("eal_pct"),
|
||||||
"sen_support_pct": _median(sub, "sen_support_pct"),
|
"sen_support_pct": _median(sub, "sen_support_pct"),
|
||||||
"disadvantaged_pct": _median(sub, "disadvantaged_pct"),
|
"disadvantaged_pct": _median(sub, "disadvantaged_pct") if with_disadvantaged else None,
|
||||||
"median_pupils": median_pupils,
|
"fsm_pct": census.get("fsm_pct"),
|
||||||
|
"median_pupils": census.get("median_pupils"),
|
||||||
}
|
}
|
||||||
if with_disadvantaged:
|
if with_disadvantaged:
|
||||||
block["disadvantaged_rwm_expected_pct"] = _weighted_disadvantaged(sub)
|
block["disadvantaged_rwm_expected_pct"] = _weighted_disadvantaged(sub)
|
||||||
@@ -586,8 +596,8 @@ def compute_benchmarks(df: pd.DataFrame) -> dict:
|
|||||||
return {
|
return {
|
||||||
"source": "state-school average (computed from our dataset)",
|
"source": "state-school average (computed from our dataset)",
|
||||||
"year": int(latest_year),
|
"year": int(latest_year),
|
||||||
"primary": _block(prim, with_disadvantaged=True),
|
"primary": _block(prim, "primary", with_disadvantaged=True),
|
||||||
"secondary": _block(sec, with_disadvantaged=False),
|
"secondary": _block(sec, "secondary", with_disadvantaged=False),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -616,6 +626,11 @@ def _ofsted_block(o, urn: int) -> dict:
|
|||||||
block = {
|
block = {
|
||||||
"framework": o.framework,
|
"framework": o.framework,
|
||||||
"inspection_date": o.inspection_date.isoformat() if o.inspection_date else None,
|
"inspection_date": o.inspection_date.isoformat() if o.inspection_date else None,
|
||||||
|
"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": overall,
|
||||||
"grade_source": grade_source,
|
"grade_source": grade_source,
|
||||||
@@ -662,92 +677,150 @@ def _admissions_row_dict(a) -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_supplementary_data(db: Session, urn: int) -> dict:
|
def _census_dict(pc) -> dict:
|
||||||
"""Fetch all supplementary data for a single school URN."""
|
return {
|
||||||
result = {}
|
"year": pc.year,
|
||||||
|
"total_pupils": pc.total_pupils,
|
||||||
|
"female_pupils": pc.female_pupils,
|
||||||
|
"male_pupils": pc.male_pupils,
|
||||||
|
"fsm_pct": pc.fsm_pct,
|
||||||
|
"eal_pct": pc.eal_pct,
|
||||||
|
}
|
||||||
|
|
||||||
def safe_query(model, pk_field, latest_field=None):
|
|
||||||
|
def _deprivation_dict(d) -> dict:
|
||||||
|
return {
|
||||||
|
"lsoa_code": d.lsoa_code,
|
||||||
|
"idaci_score": d.idaci_score,
|
||||||
|
"idaci_decile": d.idaci_decile,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _finance_dict(f) -> dict:
|
||||||
|
return {
|
||||||
|
"year": f.year,
|
||||||
|
"per_pupil_spend": f.per_pupil_spend,
|
||||||
|
"staff_cost_pct": f.staff_cost_pct,
|
||||||
|
"teacher_cost_pct": f.teacher_cost_pct,
|
||||||
|
"support_staff_cost_pct": f.support_staff_cost_pct,
|
||||||
|
"premises_cost_pct": f.premises_cost_pct,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _empty_supplementary() -> dict:
|
||||||
|
return {
|
||||||
|
"ofsted": None,
|
||||||
|
"census": None,
|
||||||
|
"admissions": None,
|
||||||
|
"admissions_history": [],
|
||||||
|
"sen_detail": None,
|
||||||
|
"phonics": None,
|
||||||
|
"deprivation": None,
|
||||||
|
"finance": None,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_supplementary_data_batch(db: Session, urns: list[int]) -> dict:
|
||||||
|
"""Fetch supplementary data for many URNs with one query per table
|
||||||
|
(WHERE urn IN (...)) instead of ~5 queries per school, collapsing the
|
||||||
|
per-request round-trips from 5*N to a constant 5. Returns {urn: block}
|
||||||
|
with the same shape get_supplementary_data produces per URN.
|
||||||
|
|
||||||
|
Each table is queried independently and failures degrade that table to
|
||||||
|
empty for every URN — a missing mart never blanks the others.
|
||||||
|
"""
|
||||||
|
urns = [int(u) for u in urns]
|
||||||
|
result = {urn: _empty_supplementary() for urn in urns}
|
||||||
|
if not urns:
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _safe(fn):
|
||||||
try:
|
try:
|
||||||
q = db.query(model).filter(getattr(model, pk_field) == urn)
|
fn()
|
||||||
if latest_field:
|
|
||||||
q = q.order_by(getattr(model, latest_field).desc())
|
|
||||||
return q.first()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import logging
|
import logging
|
||||||
logging.getLogger(__name__).error("safe_query failed for %s: %s", model.__name__, e)
|
logging.getLogger(__name__).error("batch supplementary query failed: %s", e)
|
||||||
db.rollback()
|
db.rollback()
|
||||||
return None
|
|
||||||
|
|
||||||
# Latest Ofsted inspection
|
# Ofsted — latest inspection per URN. Ordered so the first row seen per
|
||||||
o = safe_query(FactOfstedInspection, "urn", "inspection_date")
|
# URN is the most recent.
|
||||||
result["ofsted"] = _ofsted_block(o, urn) if o else None
|
def _ofsted():
|
||||||
|
rows = (
|
||||||
# Census (latest year of fact_pupil_characteristics)
|
db.query(FactOfstedInspection)
|
||||||
pc = safe_query(FactPupilCharacteristics, "urn", "year")
|
.filter(FactOfstedInspection.urn.in_(urns))
|
||||||
result["census"] = (
|
.order_by(FactOfstedInspection.urn, FactOfstedInspection.inspection_date.desc())
|
||||||
{
|
|
||||||
"year": pc.year,
|
|
||||||
"total_pupils": pc.total_pupils,
|
|
||||||
"female_pupils": pc.female_pupils,
|
|
||||||
"male_pupils": pc.male_pupils,
|
|
||||||
"fsm_pct": pc.fsm_pct,
|
|
||||||
"eal_pct": pc.eal_pct,
|
|
||||||
}
|
|
||||||
if pc
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
|
||||||
# Admissions — all years, oldest first (for the multi-year trend view).
|
|
||||||
try:
|
|
||||||
admissions_rows = (
|
|
||||||
db.query(FactAdmissions)
|
|
||||||
.filter(FactAdmissions.urn == urn)
|
|
||||||
.order_by(FactAdmissions.year.asc())
|
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
except Exception as e:
|
seen = set()
|
||||||
import logging
|
for o in rows:
|
||||||
logging.getLogger(__name__).error("admissions history query failed: %s", e)
|
if o.urn in seen:
|
||||||
db.rollback()
|
continue
|
||||||
admissions_rows = []
|
seen.add(o.urn)
|
||||||
|
result[o.urn]["ofsted"] = _ofsted_block(o, o.urn)
|
||||||
|
_safe(_ofsted)
|
||||||
|
|
||||||
history = [_admissions_row_dict(a) for a in admissions_rows]
|
# Census — latest year per URN.
|
||||||
result["admissions_history"] = history
|
def _census():
|
||||||
# Keep the single latest-year object for backwards-compatible consumers
|
rows = (
|
||||||
# (hero chips, etc.).
|
db.query(FactPupilCharacteristics)
|
||||||
result["admissions"] = history[-1] if history else None
|
.filter(FactPupilCharacteristics.urn.in_(urns))
|
||||||
|
.order_by(FactPupilCharacteristics.urn, FactPupilCharacteristics.year.desc())
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
seen = set()
|
||||||
|
for pc in rows:
|
||||||
|
if pc.urn in seen:
|
||||||
|
continue
|
||||||
|
seen.add(pc.urn)
|
||||||
|
result[pc.urn]["census"] = _census_dict(pc)
|
||||||
|
_safe(_census)
|
||||||
|
|
||||||
# SEN detail — not available in current marts
|
# Admissions — all years per URN, oldest first (multi-year trend view).
|
||||||
result["sen_detail"] = None
|
def _admissions():
|
||||||
|
rows = (
|
||||||
|
db.query(FactAdmissions)
|
||||||
|
.filter(FactAdmissions.urn.in_(urns))
|
||||||
|
.order_by(FactAdmissions.urn, FactAdmissions.year.asc())
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
history: dict = {urn: [] for urn in urns}
|
||||||
|
for a in rows:
|
||||||
|
history[a.urn].append(_admissions_row_dict(a))
|
||||||
|
for urn, rows_for_urn in history.items():
|
||||||
|
result[urn]["admissions_history"] = rows_for_urn
|
||||||
|
result[urn]["admissions"] = rows_for_urn[-1] if rows_for_urn else None
|
||||||
|
_safe(_admissions)
|
||||||
|
|
||||||
# Phonics — no school-level data on EES
|
# Deprivation — one row per URN.
|
||||||
result["phonics"] = None
|
def _deprivation():
|
||||||
|
rows = (
|
||||||
|
db.query(FactDeprivation)
|
||||||
|
.filter(FactDeprivation.urn.in_(urns))
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
for d in rows:
|
||||||
|
result[d.urn]["deprivation"] = _deprivation_dict(d)
|
||||||
|
_safe(_deprivation)
|
||||||
|
|
||||||
# Deprivation
|
# Finance — latest year per URN.
|
||||||
d = safe_query(FactDeprivation, "urn")
|
def _finance():
|
||||||
result["deprivation"] = (
|
rows = (
|
||||||
{
|
db.query(FactFinance)
|
||||||
"lsoa_code": d.lsoa_code,
|
.filter(FactFinance.urn.in_(urns))
|
||||||
"idaci_score": d.idaci_score,
|
.order_by(FactFinance.urn, FactFinance.year.desc())
|
||||||
"idaci_decile": d.idaci_decile,
|
.all()
|
||||||
}
|
)
|
||||||
if d
|
seen = set()
|
||||||
else None
|
for f in rows:
|
||||||
)
|
if f.urn in seen:
|
||||||
|
continue
|
||||||
# Finance (latest year)
|
seen.add(f.urn)
|
||||||
f = safe_query(FactFinance, "urn", "year")
|
result[f.urn]["finance"] = _finance_dict(f)
|
||||||
result["finance"] = (
|
_safe(_finance)
|
||||||
{
|
|
||||||
"year": f.year,
|
|
||||||
"per_pupil_spend": f.per_pupil_spend,
|
|
||||||
"staff_cost_pct": f.staff_cost_pct,
|
|
||||||
"teacher_cost_pct": f.teacher_cost_pct,
|
|
||||||
"support_staff_cost_pct": f.support_staff_cost_pct,
|
|
||||||
"premises_cost_pct": f.premises_cost_pct,
|
|
||||||
}
|
|
||||||
if f
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def get_supplementary_data(db: Session, urn: int) -> dict:
|
||||||
|
"""Supplementary data for a single URN (thin wrapper over the batch)."""
|
||||||
|
return get_supplementary_data_batch(db, [urn])[int(urn)]
|
||||||
|
|||||||
+23
-1
@@ -156,6 +156,9 @@ class FactOfstedInspection(Base):
|
|||||||
rc_leadership_governance = Column(Integer)
|
rc_leadership_governance = Column(Integer)
|
||||||
rc_early_years = Column(Integer)
|
rc_early_years = Column(Integer)
|
||||||
rc_sixth_form = Column(Integer)
|
rc_sixth_form = Column(Integer)
|
||||||
|
# Start date of the report-card inspection itself (renewed framework,
|
||||||
|
# Nov 2025+). Null for rows without report-card grades.
|
||||||
|
rc_inspection_date = Column(Date)
|
||||||
report_url = Column(Text)
|
report_url = Column(Text)
|
||||||
|
|
||||||
|
|
||||||
@@ -231,8 +234,27 @@ class FactFinance(Base):
|
|||||||
premises_cost_pct = Column(Float)
|
premises_cost_pct = Column(Float)
|
||||||
|
|
||||||
|
|
||||||
|
class CensusBenchmark(Base):
|
||||||
|
"""State-school context benchmarks from the pupil census — one row per phase.
|
||||||
|
|
||||||
|
fsm_pct / eal_pct are pupil-weighted means. Computed at import time;
|
||||||
|
consumers label them "state-school average (computed from our dataset)".
|
||||||
|
"""
|
||||||
|
__tablename__ = "fact_census_benchmarks"
|
||||||
|
__table_args__ = MARTS
|
||||||
|
|
||||||
|
phase = Column(String(20), primary_key=True)
|
||||||
|
year = Column(Integer)
|
||||||
|
fsm_pct = Column(Float)
|
||||||
|
eal_pct = Column(Float)
|
||||||
|
median_pupils = Column(Integer)
|
||||||
|
|
||||||
|
|
||||||
class Ks4NationalAverage(Base):
|
class Ks4NationalAverage(Base):
|
||||||
"""Computed national KS4 averages (from our dataset) — one row per year."""
|
"""Official DfE KS4 national headline averages — one row per academic year.
|
||||||
|
|
||||||
|
gcse_grade_91_pct has no official national series and is always NULL.
|
||||||
|
"""
|
||||||
__tablename__ = "fact_ks4_national_averages"
|
__tablename__ = "fact_ks4_national_averages"
|
||||||
__table_args__ = MARTS
|
__table_args__ = MARTS
|
||||||
|
|
||||||
|
|||||||
@@ -550,6 +550,7 @@ SCHOOL_COLUMNS = [
|
|||||||
"ofsted_grade",
|
"ofsted_grade",
|
||||||
"ofsted_date",
|
"ofsted_date",
|
||||||
"ofsted_framework",
|
"ofsted_framework",
|
||||||
|
"ofsted_rc_date",
|
||||||
"latitude",
|
"latitude",
|
||||||
"longitude",
|
"longitude",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -17,33 +17,33 @@ def _df():
|
|||||||
# weighted = (40*100 + 60*300) / 400 = 55.0 ; unweighted mean = 50.0
|
# weighted = (40*100 + 60*300) / 400 = 55.0 ; unweighted mean = 50.0
|
||||||
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=100,
|
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=100,
|
||||||
rwm_expected_disadvantaged_pct=40.0, eal_pct=10.0,
|
rwm_expected_disadvantaged_pct=40.0, eal_pct=10.0,
|
||||||
sen_support_pct=10.0, disadvantaged_pct=20.0, total_pupils=200),
|
sen_support_pct=10.0, disadvantaged_pct=20.0, fsm_pct=15.0, total_pupils=200),
|
||||||
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=300,
|
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=300,
|
||||||
rwm_expected_disadvantaged_pct=60.0, eal_pct=20.0,
|
rwm_expected_disadvantaged_pct=60.0, eal_pct=20.0,
|
||||||
sen_support_pct=14.0, disadvantaged_pct=24.0, total_pupils=280),
|
sen_support_pct=14.0, disadvantaged_pct=24.0, fsm_pct=17.0, total_pupils=280),
|
||||||
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=np.nan,
|
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=np.nan,
|
||||||
rwm_expected_disadvantaged_pct=99.0, eal_pct=30.0,
|
rwm_expected_disadvantaged_pct=99.0, eal_pct=30.0,
|
||||||
sen_support_pct=18.0, disadvantaged_pct=30.0, total_pupils=300),
|
sen_support_pct=18.0, disadvantaged_pct=30.0, fsm_pct=19.0, total_pupils=300),
|
||||||
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=50,
|
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=50,
|
||||||
rwm_expected_disadvantaged_pct=np.nan, eal_pct=np.nan,
|
rwm_expected_disadvantaged_pct=np.nan, eal_pct=np.nan,
|
||||||
sen_support_pct=np.nan, disadvantaged_pct=np.nan, total_pupils=np.nan),
|
sen_support_pct=np.nan, disadvantaged_pct=np.nan, fsm_pct=np.nan, total_pupils=np.nan),
|
||||||
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=40,
|
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=40,
|
||||||
rwm_expected_disadvantaged_pct=np.nan, eal_pct=40.0,
|
rwm_expected_disadvantaged_pct=np.nan, eal_pct=40.0,
|
||||||
sen_support_pct=20.0, disadvantaged_pct=40.0, total_pupils=350),
|
sen_support_pct=20.0, disadvantaged_pct=40.0, fsm_pct=21.0, total_pupils=350),
|
||||||
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=60,
|
dict(year=LATEST, attainment_8_score=np.nan, eligible_pupils=60,
|
||||||
rwm_expected_disadvantaged_pct=np.nan, eal_pct=50.0,
|
rwm_expected_disadvantaged_pct=np.nan, eal_pct=50.0,
|
||||||
sen_support_pct=22.0, disadvantaged_pct=44.0, total_pupils=400),
|
sen_support_pct=22.0, disadvantaged_pct=44.0, fsm_pct=23.0, total_pupils=400),
|
||||||
# Two secondary schools (attainment_8 non-null)
|
# Two secondary schools (attainment_8 non-null)
|
||||||
dict(year=LATEST, attainment_8_score=45.0, eligible_pupils=180,
|
dict(year=LATEST, attainment_8_score=45.0, eligible_pupils=180,
|
||||||
rwm_expected_disadvantaged_pct=np.nan, eal_pct=15.0,
|
rwm_expected_disadvantaged_pct=np.nan, eal_pct=15.0,
|
||||||
sen_support_pct=12.0, disadvantaged_pct=22.0, total_pupils=1000),
|
sen_support_pct=12.0, disadvantaged_pct=22.0, fsm_pct=12.0, total_pupils=1000),
|
||||||
dict(year=LATEST, attainment_8_score=50.0, eligible_pupils=200,
|
dict(year=LATEST, attainment_8_score=50.0, eligible_pupils=200,
|
||||||
rwm_expected_disadvantaged_pct=np.nan, eal_pct=25.0,
|
rwm_expected_disadvantaged_pct=np.nan, eal_pct=25.0,
|
||||||
sen_support_pct=16.0, disadvantaged_pct=26.0, total_pupils=1200),
|
sen_support_pct=16.0, disadvantaged_pct=26.0, fsm_pct=14.0, total_pupils=1200),
|
||||||
# An older-year primary row that must NOT influence anything
|
# An older-year primary row that must NOT influence anything
|
||||||
dict(year=202324, attainment_8_score=np.nan, eligible_pupils=500,
|
dict(year=202324, attainment_8_score=np.nan, eligible_pupils=500,
|
||||||
rwm_expected_disadvantaged_pct=1.0, eal_pct=99.0,
|
rwm_expected_disadvantaged_pct=1.0, eal_pct=99.0,
|
||||||
sen_support_pct=99.0, disadvantaged_pct=99.0, total_pupils=9999),
|
sen_support_pct=99.0, disadvantaged_pct=99.0, fsm_pct=99.0, total_pupils=9999),
|
||||||
]
|
]
|
||||||
return pd.DataFrame(rows)
|
return pd.DataFrame(rows)
|
||||||
|
|
||||||
@@ -57,16 +57,40 @@ def test_weighted_disadvantaged_average():
|
|||||||
def test_medians_ignore_nan_and_older_years():
|
def test_medians_ignore_nan_and_older_years():
|
||||||
b = compute_benchmarks(_df())
|
b = compute_benchmarks(_df())
|
||||||
assert b["year"] == LATEST
|
assert b["year"] == LATEST
|
||||||
# eal medians over [10,20,30,40,50] = 30
|
# sen medians over [10,14,18,20,22] = 18 — the only context measure still
|
||||||
assert b["primary"]["eal_pct"] == 30.0
|
# sourced from the performance df (the rest come from the census mart).
|
||||||
# median pupils over [200,280,300,350,400] = 300
|
assert b["primary"]["sen_support_pct"] == 18.0
|
||||||
assert b["primary"]["median_pupils"] == 300
|
# disadvantaged_pct medians over [20,24,30,40,44] = 30
|
||||||
|
assert b["primary"]["disadvantaged_pct"] == 30.0
|
||||||
|
|
||||||
|
|
||||||
|
def test_benchmarks_use_census_mart_for_context():
|
||||||
|
census = {
|
||||||
|
"primary": {"year": LATEST, "fsm_pct": 25.3, "eal_pct": 21.8, "median_pupils": 240},
|
||||||
|
"secondary": {"year": LATEST, "fsm_pct": 24.1, "eal_pct": 18.9, "median_pupils": 980},
|
||||||
|
}
|
||||||
|
b = compute_benchmarks(_df(), census_benchmarks=census)
|
||||||
|
assert b["primary"]["fsm_pct"] == 25.3
|
||||||
|
assert b["primary"]["eal_pct"] == 21.8
|
||||||
|
assert b["secondary"]["eal_pct"] == 18.9
|
||||||
|
assert b["secondary"]["median_pupils"] == 980
|
||||||
|
|
||||||
|
|
||||||
|
def test_benchmarks_context_none_when_mart_missing():
|
||||||
|
# The performance df has no fsm_pct and its eal/disadvantaged columns are
|
||||||
|
# KS2-only — never silently fall back to medianing them for context.
|
||||||
|
b = compute_benchmarks(_df(), census_benchmarks=None)
|
||||||
|
assert b["primary"]["fsm_pct"] is None
|
||||||
|
assert b["primary"]["eal_pct"] is None
|
||||||
|
assert b["primary"]["median_pupils"] is None
|
||||||
|
|
||||||
|
|
||||||
def test_secondary_block_has_no_disadvantaged_rwm():
|
def test_secondary_block_has_no_disadvantaged_rwm():
|
||||||
b = compute_benchmarks(_df())
|
b = compute_benchmarks(_df())
|
||||||
assert "disadvantaged_rwm_expected_pct" not in b["secondary"]
|
assert "disadvantaged_rwm_expected_pct" not in b["secondary"]
|
||||||
assert b["secondary"]["median_pupils"] == 1100
|
# KS2-only columns must not produce a fake secondary disadvantaged anchor
|
||||||
|
# (the old median over all-through schools' KS2 rows produced 50%).
|
||||||
|
assert b["secondary"]["disadvantaged_pct"] is None
|
||||||
|
|
||||||
|
|
||||||
def test_provenance_string():
|
def test_provenance_string():
|
||||||
|
|||||||
@@ -67,7 +67,9 @@ def client(monkeypatch):
|
|||||||
|
|
||||||
monkeypatch.setattr(app_module, "load_school_data", _two_primary_schools_df)
|
monkeypatch.setattr(app_module, "load_school_data", _two_primary_schools_df)
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
app_module, "get_supplementary_data", lambda db, urn: dict(CANNED_SUPPLEMENTARY)
|
app_module,
|
||||||
|
"get_supplementary_data_batch",
|
||||||
|
lambda db, urns: {int(u): dict(CANNED_SUPPLEMENTARY) for u in urns},
|
||||||
)
|
)
|
||||||
monkeypatch.setattr(database_module, "SessionLocal", _StubSession)
|
monkeypatch.setattr(database_module, "SessionLocal", _StubSession)
|
||||||
return TestClient(app_module.app, raise_server_exceptions=False)
|
return TestClient(app_module.app, raise_server_exceptions=False)
|
||||||
@@ -102,10 +104,10 @@ def test_top_level_national_averages_and_benchmarks(client):
|
|||||||
def test_supplementary_failure_degrades_not_500(client, monkeypatch):
|
def test_supplementary_failure_degrades_not_500(client, monkeypatch):
|
||||||
from backend import app as app_module
|
from backend import app as app_module
|
||||||
|
|
||||||
def _boom(db, urn):
|
def _boom(db, urns):
|
||||||
raise RuntimeError("marts unavailable")
|
raise RuntimeError("marts unavailable")
|
||||||
|
|
||||||
monkeypatch.setattr(app_module, "get_supplementary_data", _boom)
|
monkeypatch.setattr(app_module, "get_supplementary_data_batch", _boom)
|
||||||
resp = client.get("/api/compare?urns=100140")
|
resp = client.get("/api/compare?urns=100140")
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
school = resp.json()["comparison"]["100140"]
|
school = resp.json()["comparison"]["100140"]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""_national_averages_payload reads persisted marts (computed at import
|
"""_national_averages_payload reads persisted marts (computed at import
|
||||||
time) — it must never loop the dataframe per year. The only dataframe work
|
time) — it must never aggregate the dataframe. Both marts hold OFFICIAL
|
||||||
allowed is the single-latest-year KS4 fallback for the window between a
|
DfE figures, so a missing KS4 mart yields an empty secondary series —
|
||||||
deploy and the next DAG run."""
|
never a computed stand-in the UI would mislabel as official."""
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -84,10 +84,11 @@ def test_ks4_averages_come_from_the_mart_not_the_dataframe(payload):
|
|||||||
assert body["by_year"][-1]["secondary"]["progress_8_score"] == -0.02
|
assert body["by_year"][-1]["secondary"]["progress_8_score"] == -0.02
|
||||||
|
|
||||||
|
|
||||||
def test_missing_ks4_mart_falls_back_to_latest_year_only(payload):
|
def test_ks4_secondary_empty_when_mart_missing(payload):
|
||||||
|
# No computed stand-in: the UI labels national figures as official DfE
|
||||||
|
# data, so an empty mart must yield an empty secondary series.
|
||||||
body = payload(_Ks4MissingSession)
|
body = payload(_Ks4MissingSession)
|
||||||
# Fallback computes the latest year from the df: mean(50, 30) = 40.0
|
assert body["secondary"] == {}
|
||||||
assert body["secondary"]["attainment_8_score"] == 40.0
|
assert all(not e["secondary"] for e in body["by_year"])
|
||||||
# ...and only the latest year — no historical KS4 loop
|
# The KS2 series is unaffected.
|
||||||
ks4_years = [e["year"] for e in body["by_year"] if e["secondary"]]
|
assert body["primary"]["rwm_expected_pct"] == 62.1
|
||||||
assert ks4_years == [LATEST]
|
|
||||||
|
|||||||
@@ -0,0 +1,111 @@
|
|||||||
|
"""get_supplementary_data_batch fetches one query per table for all URNs
|
||||||
|
(not ~5 per school) and returns the same per-URN block shape as the
|
||||||
|
single-URN function, picking the latest row per URN where relevant."""
|
||||||
|
|
||||||
|
import types
|
||||||
|
|
||||||
|
from backend import data_loader
|
||||||
|
from backend.data_loader import get_supplementary_data_batch
|
||||||
|
|
||||||
|
|
||||||
|
class _FakeQuery:
|
||||||
|
"""Records that a query ran and serves canned rows filtered by an in-list."""
|
||||||
|
|
||||||
|
def __init__(self, recorder, model_name, rows):
|
||||||
|
self._rec = recorder
|
||||||
|
self._model = model_name
|
||||||
|
self._rows = rows
|
||||||
|
|
||||||
|
def filter(self, *args, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def order_by(self, *args, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def all(self):
|
||||||
|
self._rec.append(self._model)
|
||||||
|
return self._rows
|
||||||
|
|
||||||
|
def first(self):
|
||||||
|
self._rec.append(self._model)
|
||||||
|
return self._rows[0] if self._rows else None
|
||||||
|
|
||||||
|
|
||||||
|
class _FakeSession:
|
||||||
|
def __init__(self, rows_by_model):
|
||||||
|
self.rows_by_model = rows_by_model
|
||||||
|
self.queries: list[str] = []
|
||||||
|
|
||||||
|
def query(self, model):
|
||||||
|
name = model.__name__
|
||||||
|
return _FakeQuery(self.queries, name, self.rows_by_model.get(name, []))
|
||||||
|
|
||||||
|
def rollback(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _ofsted_row(urn, date, oe):
|
||||||
|
base = {f: None for f in (
|
||||||
|
"framework", "inspection_type", "quality_of_education", "behaviour_attitudes",
|
||||||
|
"personal_development", "leadership_management", "early_years_provision",
|
||||||
|
"sixth_form_provision", "ungraded_outcome", "ungraded_grade",
|
||||||
|
"rc_safeguarding_met", "rc_inclusion", "rc_curriculum_teaching", "rc_achievement",
|
||||||
|
"rc_attendance_behaviour", "rc_personal_development", "rc_leadership_governance",
|
||||||
|
"rc_early_years", "rc_sixth_form", "report_url",
|
||||||
|
)}
|
||||||
|
base.update(urn=urn, inspection_date=types.SimpleNamespace(isoformat=lambda: date),
|
||||||
|
overall_effectiveness=oe, grade_source=None)
|
||||||
|
return types.SimpleNamespace(**base)
|
||||||
|
|
||||||
|
|
||||||
|
def _adm_row(urn, year):
|
||||||
|
return types.SimpleNamespace(
|
||||||
|
urn=urn, year=year, school_phase="Primary", places_offered=100,
|
||||||
|
total_applications=200, first_preference_applications=150,
|
||||||
|
first_preference_offers=140, first_preference_offer_pct=93.3,
|
||||||
|
oversubscription_ratio=1.5, oversubscribed=True,
|
||||||
|
total_offers=100, second_preference_offers=5, third_preference_offers=2,
|
||||||
|
cross_la_applications=10, cross_la_offers=3,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_one_query_per_table_and_latest_row_per_urn():
|
||||||
|
rows = {
|
||||||
|
# URN 1 has two Ofsted rows; the batch must keep the most recent (2023).
|
||||||
|
"FactOfstedInspection": [
|
||||||
|
_ofsted_row(1, "2023-01-01", 2),
|
||||||
|
_ofsted_row(1, "2019-01-01", 3),
|
||||||
|
_ofsted_row(2, "2021-06-01", 1),
|
||||||
|
],
|
||||||
|
"FactAdmissions": [_adm_row(1, 202526), _adm_row(1, 202627), _adm_row(2, 202627)],
|
||||||
|
"FactPupilCharacteristics": [],
|
||||||
|
"FactDeprivation": [],
|
||||||
|
"FactFinance": [],
|
||||||
|
}
|
||||||
|
session = _FakeSession(rows)
|
||||||
|
out = get_supplementary_data_batch(session, [1, 2])
|
||||||
|
|
||||||
|
# Exactly one query per table — five total, regardless of two URNs.
|
||||||
|
assert sorted(session.queries) == [
|
||||||
|
"FactAdmissions", "FactDeprivation", "FactFinance",
|
||||||
|
"FactOfstedInspection", "FactPupilCharacteristics",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Latest Ofsted kept per URN
|
||||||
|
assert out[1]["ofsted"]["overall_effectiveness"] == 2
|
||||||
|
assert out[2]["ofsted"]["overall_effectiveness"] == 1
|
||||||
|
|
||||||
|
# Admissions history grouped per URN, latest exposed as `admissions`
|
||||||
|
assert [r["year"] for r in out[1]["admissions_history"]] == [202526, 202627]
|
||||||
|
assert out[1]["admissions"]["year"] == 202627
|
||||||
|
assert out[2]["admissions_history"] == [{**out[2]["admissions_history"][0]}]
|
||||||
|
|
||||||
|
# Empty tables degrade to the null block, not a crash
|
||||||
|
assert out[1]["census"] is None and out[1]["deprivation"] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_single_wrapper_matches_batch(monkeypatch):
|
||||||
|
session = _FakeSession({"FactOfstedInspection": [_ofsted_row(5, "2022-01-01", 2)]})
|
||||||
|
single = data_loader.get_supplementary_data(session, 5)
|
||||||
|
assert single["ofsted"]["overall_effectiveness"] == 2
|
||||||
|
assert single["admissions_history"] == []
|
||||||
@@ -3,6 +3,7 @@ labels, provider-page URL, graded-vs-carried-forward provenance, and the
|
|||||||
admissions preference/cross-LA detail promoted in the data-foundation PR."""
|
admissions preference/cross-LA detail promoted in the data-foundation PR."""
|
||||||
|
|
||||||
import types
|
import types
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
from backend.data_loader import _admissions_row_dict, _ofsted_block
|
from backend.data_loader import _admissions_row_dict, _ofsted_block
|
||||||
|
|
||||||
@@ -40,6 +41,25 @@ def test_grade_source_graded_vs_carried_forward():
|
|||||||
assert _ofsted_block(_row(), urn=1)["grade_source"] is None
|
assert _ofsted_block(_row(), urn=1)["grade_source"] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_ofsted_block_carries_rc_inspection_date():
|
||||||
|
o = _row(
|
||||||
|
ungraded_grade=2,
|
||||||
|
rc_achievement=1,
|
||||||
|
rc_inspection_date=date(2026, 2, 3),
|
||||||
|
inspection_date=date(2021, 10, 7),
|
||||||
|
)
|
||||||
|
block = _ofsted_block(o, urn=138690)
|
||||||
|
assert block["rc_inspection_date"] == "2026-02-03"
|
||||||
|
# The legacy inspection date is still present, unchanged.
|
||||||
|
assert block["inspection_date"] == "2021-10-07"
|
||||||
|
|
||||||
|
|
||||||
|
def test_ofsted_block_rc_inspection_date_none_when_absent():
|
||||||
|
o = _row(overall_effectiveness=1, inspection_date=date(2021, 10, 13))
|
||||||
|
block = _ofsted_block(o, urn=136276)
|
||||||
|
assert block["rc_inspection_date"] is None
|
||||||
|
|
||||||
|
|
||||||
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",
|
||||||
|
|||||||
@@ -0,0 +1,931 @@
|
|||||||
|
# Compare Screen Must-Fix (Final Expert Review) Implementation Plan
|
||||||
|
|
||||||
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||||
|
|
||||||
|
**Goal:** Fix the five promotion-blocking findings from the expert's final staging review: (1) blank all-secondary compare view, (2) report cards dated with pre-Nov-2025 legacy inspection dates, (3) FSM chip benchmarked against the wrong measure, (4) KS4 "national averages" that are dataset means presented as official DfE figures, (5) factually wrong "DfE didn't publish 2021/22" footnote.
|
||||||
|
|
||||||
|
**Architecture:** One branch/PR touching all three layers. Pipeline: a new tap field carries the report-card inspection's own date; a new EES stream ingests official KS4 national headlines; a new census-benchmarks mart replaces junk KS2-derived context medians. Backend: serialize the new fields, stop mislabelling computed KS4 means as official. Frontend: fix the phase-detection effect that leaves all-secondary comparisons stuck on an empty "primary" tab, date report cards correctly, drop the FSM→disadvantaged fallback, fix the footnote copy.
|
||||||
|
|
||||||
|
**Tech Stack:** Meltano/Singer taps (Python), dbt-postgres, FastAPI/SQLAlchemy/pandas, Next.js app router + Jest, Playwright e2e.
|
||||||
|
|
||||||
|
## Global Constraints
|
||||||
|
|
||||||
|
- Never push to `main`; work on branch `fix/compare-final-review-mustfix`, open a PR. Never trigger the "Promote to Production (manual)" workflow — promotion is exclusively the human's call.
|
||||||
|
- User-facing behaviour changes must extend the `e2e/` journeys in the same PR (they gate staging fitness and promotability).
|
||||||
|
- All user-facing copy on the compare screen comes verbatim from `docs/superpowers/specs/mockups/compare-desktop.html` / `compare-mobile.html` — except where this plan explicitly changes copy to fix a factual error (Task 6); the spec/mockup gets the same wording in the same commit.
|
||||||
|
- Benchmark provenance house style: official figures = "England average"; computed figures = "state-school average (computed from our dataset)".
|
||||||
|
- A report card must NEVER be displayed with a pre-November-2025 date. Report cards exist only from November 2025.
|
||||||
|
- Backend tests: `uv run --with-requirements requirements.txt --with pytest --with "httpx==0.27.0" python -m pytest backend/tests -q` (repo root; there is no local pytest).
|
||||||
|
- dbt: `cd pipeline/transform && uv run --with dbt-postgres python -m dbt.cli.main parse --profiles-dir .` (never bare `dbt` — the Fusion binary shadows dbt-postgres).
|
||||||
|
- Frontend: `cd nextjs-app && npx tsc --noEmit && npm test` (run tsc un-piped so exit codes are not masked).
|
||||||
|
- Do NOT start a local server to test the application (CLAUDE.md).
|
||||||
|
- Commits end with the Claude Code `Co-Authored-By` + `Claude-Session` trailers used on this branch's history.
|
||||||
|
|
||||||
|
## Root-Cause Evidence (verified 2026-07-16, do not re-derive)
|
||||||
|
|
||||||
|
- **Finding 1:** `nextjs-app/components/ComparisonView.tsx:164-176` — the auto-phase effect returns early when `selectedSchools.length === 0` (basket hydrates a beat after mount) and its dep array is only `[comparisonData]`, so it never re-fires; `comparePhase` stays `'primary'`, `activeSchools` is empty, the page renders "No primary schools in your comparison" (a11y snapshot confirmed). No console errors — not a crash.
|
||||||
|
- **Finding 2:** In the Ofsted MI CSV (`Management_information_-_state-funded_schools_-_latest_inspections_as_at_31_May_2026.csv`) the report-card grade columns (cols 38–55, "Safeguarding standards", "Inclusion", …) belong to the **latest full inspection** block whose date is col 30 "Inspection start date" (Barclay 138690: `03/02/2026`). The tap's `inspection_date` COLUMN_PRIORITY matches col 60 "Inspection start date of latest OEIF graded inspection" first (the *legacy* date; NULL for Barclay, so stg coalesces to the 2021 *ungraded* date). The rc data is **real Ofsted data, not fabricated** — it is mis-dated. Also `discover_csv_url()` returns `matches[0]` = the oldest (2017) link on the GOV.UK page; staging works only because `mi_url` is set in the environment. Staging raw is stale for at least Watford Grammar 136276 (staging shows rc grades; the current MI file has all rc columns NULL for it) — a fresh extract fixes that via upsert on `(urn, inspection_date)`.
|
||||||
|
- **Finding 3:** `nextjs-app/components/compare/CompareCommunity.tsx:36` — `bench?.fsm_pct ?? bench?.disadvantaged_pct` falls back across definitions. `benchmarks.primary.fsm_pct` is null because `compute_benchmarks` (backend/data_loader.py:528) medians the *performance* df, which has no `fsm_pct` (school FSM comes from `census.fsm_pct` = `fact_pupil_characteristics`). `disadvantaged_pct` / `eal_pct` are KS2-only columns, so the "secondary" medians (50.0 / 10.0) are computed over the few all-through schools' KS2 rows — junk.
|
||||||
|
- **Finding 4:** `fact_ks4_national_averages.sql` computes unweighted school means (A8 38.94 vs official 46.0; national P8 −0.27, impossible). Official series exists on EES: data-set `1b649e16-01e8-435b-a814-56be2faf9054` ("National characteristics summary data", KS4 performance publication), CSV endpoint same pattern as the KS2 national stream, national level, 2018/19→2024/25, `establishment_type_group = 'All state-funded'`, `breakdown_topic = 'Total'`, `breakdown = 'Total'`. Verified values: 2024/25 A8 46.0, P8 `z` (not published — no KS2 baseline for that cohort), EM 9-5 45.4%, EBacc entry 40.5%. It has **no** `gcse_91_percent` column.
|
||||||
|
- **Finding 5:** `ComparisonChart.tsx:245-246` claims "DfE didn't publish school-level figures for 2021/22". False — DfE published school-level KS2 for 2021/22 in Dec 2022; spec §8.1 itself lists loading it as a pipeline task. The honest claim is that the figures aren't in our dataset.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 1: All-secondary comparison renders (phase-detection fix)
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `nextjs-app/components/ComparisonView.tsx:176`
|
||||||
|
- Create: `nextjs-app/__tests__/components/ComparisonView.phase.test.tsx`
|
||||||
|
- Modify: `e2e/tests/journeys.spec.ts` (add helper + journey after the existing `twoPrimaryUrns` helper / primary compare journey)
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: existing `ComparisonView` props (`initialData`, `initialUrns`, `metrics`, `selectedMetric`), `ComparisonProvider`.
|
||||||
|
- Produces: no API changes; the auto-phase effect re-runs when the basket hydrates.
|
||||||
|
|
||||||
|
- [ ] **Step 1: Write the failing Jest test**
|
||||||
|
|
||||||
|
Create `nextjs-app/__tests__/components/ComparisonView.phase.test.tsx` (mirrors the mock setup of `ComparisonView.refresh.test.tsx`):
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
/**
|
||||||
|
* Regression: an all-secondary comparison must render the secondary sections.
|
||||||
|
*
|
||||||
|
* The basket hydrates from the URL a beat after mount, so the auto-phase
|
||||||
|
* effect must re-run once selectedSchools arrives — with deps of only
|
||||||
|
* [comparisonData] it fired once against an empty basket, bailed, and the
|
||||||
|
* page stayed on an empty "primary" tab ("No primary schools in your
|
||||||
|
* comparison") even though all schools were secondary.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { render, screen, waitFor } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { ComparisonView } from '@/components/ComparisonView';
|
||||||
|
import { ComparisonProvider } from '@/context/ComparisonProvider';
|
||||||
|
import type { ComparisonData, School } from '@/lib/types';
|
||||||
|
|
||||||
|
const fetchComparison = jest.fn();
|
||||||
|
jest.mock('@/lib/api', () => ({
|
||||||
|
fetchComparison: (...args: unknown[]) => fetchComparison(...args),
|
||||||
|
}));
|
||||||
|
jest.mock('@/lib/analytics', () => ({ track: jest.fn() }));
|
||||||
|
|
||||||
|
function secondarySchool(urn: number, name: string): School {
|
||||||
|
return {
|
||||||
|
urn,
|
||||||
|
school_name: name,
|
||||||
|
local_authority: 'Testshire',
|
||||||
|
school_type: 'Academy converter',
|
||||||
|
attainment_8_score: 55,
|
||||||
|
phase: 'Secondary',
|
||||||
|
} as School;
|
||||||
|
}
|
||||||
|
|
||||||
|
function data(urn: number, name: string): ComparisonData {
|
||||||
|
return {
|
||||||
|
school_info: secondarySchool(urn, name),
|
||||||
|
yearly_data: [{ year: 202425, attainment_8_score: 55 }] as ComparisonData['yearly_data'],
|
||||||
|
ofsted: null,
|
||||||
|
census: null,
|
||||||
|
admissions: null,
|
||||||
|
admissions_history: [],
|
||||||
|
deprivation: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const INITIAL_DATA = {
|
||||||
|
'300': data(300, 'Gamma High'),
|
||||||
|
'400': data(400, 'Delta Academy'),
|
||||||
|
};
|
||||||
|
|
||||||
|
test('an all-secondary comparison renders the sections, not an empty primary tab', async () => {
|
||||||
|
render(
|
||||||
|
<ComparisonProvider>
|
||||||
|
<ComparisonView
|
||||||
|
initialData={INITIAL_DATA}
|
||||||
|
initialNationalAverages={{
|
||||||
|
year: 202425,
|
||||||
|
primary: {},
|
||||||
|
secondary: { attainment_8_score: 46 },
|
||||||
|
by_year: [],
|
||||||
|
}}
|
||||||
|
initialBenchmarks={undefined}
|
||||||
|
initialUrns={[300, 400]}
|
||||||
|
metrics={[]}
|
||||||
|
selectedMetric="attainment_8_score"
|
||||||
|
/>
|
||||||
|
</ComparisonProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByRole('heading', { name: 'At a glance' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
expect(screen.getAllByText('Gamma High').length).toBeGreaterThan(0);
|
||||||
|
expect(screen.queryByText(/No primary schools in your comparison/)).toBeNull();
|
||||||
|
expect(fetchComparison).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Run it to verify it fails**
|
||||||
|
|
||||||
|
Run: `cd nextjs-app && npx jest __tests__/components/ComparisonView.phase.test.tsx`
|
||||||
|
Expected: FAIL — "No primary schools in your comparison" is rendered / "At a glance" never appears.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Fix the effect dependencies**
|
||||||
|
|
||||||
|
In `nextjs-app/components/ComparisonView.tsx`, the auto-phase effect currently ends:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
}, [comparisonData]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
```
|
||||||
|
|
||||||
|
Change to:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
// selectedSchools is a dep because the basket hydrates after mount: the
|
||||||
|
// first run sees an empty basket and bails, so it must re-fire when the
|
||||||
|
// schools arrive. primarySchools/secondarySchools/metrics/selectedMetric
|
||||||
|
// are intentionally omitted (derived or would cause loops).
|
||||||
|
}, [comparisonData, selectedSchools]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
```
|
||||||
|
|
||||||
|
(`phaseLockedByUser` still suppresses re-detection after a manual tab click; re-running with unchanged inputs sets the same state, which React treats as a no-op.)
|
||||||
|
|
||||||
|
- [ ] **Step 4: Run the new test and the existing suite**
|
||||||
|
|
||||||
|
Run: `cd nextjs-app && npx tsc --noEmit && npm test`
|
||||||
|
Expected: PASS, including `ComparisonView.refresh.test.tsx` (the refresh regression must stay green).
|
||||||
|
|
||||||
|
- [ ] **Step 5: Add the e2e secondary journey**
|
||||||
|
|
||||||
|
In `e2e/tests/journeys.spec.ts`, add below `twoPrimaryUrns`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
async function twoSecondaryUrns(page: Page): Promise<[string, string]> {
|
||||||
|
const res = await page.request.get('/api/schools?search=school&per_page=100');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const body = await res.json();
|
||||||
|
const urns: string[] = (body.schools ?? [])
|
||||||
|
.filter((s: { phase?: string; attainment_8_score?: number | null }) =>
|
||||||
|
s.phase === 'Secondary' && s.attainment_8_score != null,
|
||||||
|
)
|
||||||
|
.map((s: { urn: number }) => String(s.urn));
|
||||||
|
expect(urns.length).toBeGreaterThanOrEqual(2);
|
||||||
|
return [urns[0], urns[1]];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
(If `/api/schools` list rows lack `attainment_8_score`, filter on `s.phase === 'Secondary'` only — check the response first.) Then add a journey test next to the primary compare journey:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
test('comparing two secondary schools renders the secondary sections', async ({ page }) => {
|
||||||
|
const [urn0, urn1] = await twoSecondaryUrns(page);
|
||||||
|
|
||||||
|
await page.goto(`/compare?urns=${urn0},${urn1}`);
|
||||||
|
await expect(page.locator(`a[href*="${urn0}"]`).first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
|
// The parent-first sections must render — this page was completely blank
|
||||||
|
// for all-secondary baskets (expert review must-fix #1).
|
||||||
|
await expect(page.getByRole('heading', { name: 'At a glance' })).toBeVisible();
|
||||||
|
await expect(page.getByRole('heading', { name: 'Ofsted inspection' })).toBeVisible();
|
||||||
|
// A KS4 measure proves the secondary academics variant rendered.
|
||||||
|
await expect(page.getByText(/Attainment 8/i).first()).toBeVisible();
|
||||||
|
await expect(page.getByText(/No primary schools in your comparison/)).toHaveCount(0);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 6: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add nextjs-app/components/ComparisonView.tsx nextjs-app/__tests__/components/ComparisonView.phase.test.tsx e2e/tests/journeys.spec.ts
|
||||||
|
git commit -m "fix(compare): render all-secondary comparisons — re-run phase detection after basket hydration"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 2: Report-card inspection date through the pipeline
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `pipeline/plugins/extractors/tap-uk-ofsted/tap_uk_ofsted/tap.py` (COLUMN_PRIORITY, schema, `discover_csv_url`)
|
||||||
|
- Modify: `pipeline/transform/models/staging/stg_ofsted_inspections.sql`
|
||||||
|
- Modify: `pipeline/transform/models/intermediate/int_ofsted_latest.sql`
|
||||||
|
- Modify: `pipeline/transform/models/marts/fact_ofsted_inspection.sql`
|
||||||
|
- Modify: `pipeline/transform/models/marts/_marts_schema.yml` (add column doc if other fact_ofsted columns are documented there)
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: MI CSV column `Inspection start date` (the latest **full** inspection = the report-card inspection in the renewed framework; NULL when a school's only inspections are legacy OEIF/ungraded — verified for Watford Grammar).
|
||||||
|
- Produces: `marts.fact_ofsted_inspection.rc_inspection_date` (DATE, null unless the row carries report-card grades). Task 3 depends on this exact column name.
|
||||||
|
|
||||||
|
- [ ] **Step 1: Add the tap field**
|
||||||
|
|
||||||
|
In `tap.py` COLUMN_PRIORITY, after the `rc_sixth_form` entry, add:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Date of the latest FULL inspection — in the renewed framework this is
|
||||||
|
# the report-card inspection's own start date (col "Inspection start
|
||||||
|
# date"), distinct from the legacy OEIF graded/ungraded dates above.
|
||||||
|
"rc_inspection_date": ["Inspection start date"],
|
||||||
|
```
|
||||||
|
|
||||||
|
and in the stream schema, next to the other rc properties:
|
||||||
|
|
||||||
|
```python
|
||||||
|
th.Property("rc_inspection_date", th.StringType),
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: `inspection_date`'s own priority list also contains `"Inspection start date"` as a lower-priority candidate — that stays; in renewed-framework files the higher-priority OEIF column exists so they map to different columns, and in legacy files both map to the same column but rc grades are absent, and staging nulls `rc_inspection_date` in that case (Step 3).
|
||||||
|
|
||||||
|
- [ ] **Step 2: Fix `discover_csv_url` to pick the newest file, not `matches[0]`**
|
||||||
|
|
||||||
|
The GOV.UK page lists 2017 files first; `matches[0]` is a 2017 CSV. Replace the body of `discover_csv_url()` to date-sort the `latest_inspections_as_at` links, mirroring `discover_independent_csv_url`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def discover_csv_url() -> str | None:
|
||||||
|
"""Scrape GOV.UK page to find the latest MI CSV download link.
|
||||||
|
|
||||||
|
The page lists a decade of monthly files, oldest first — take the
|
||||||
|
newest 'latest inspections as at <date>' link by parsing its date,
|
||||||
|
never matches[0].
|
||||||
|
"""
|
||||||
|
resp = requests.get(GOV_UK_PAGE, timeout=30)
|
||||||
|
resp.raise_for_status()
|
||||||
|
csv_links = re.findall(
|
||||||
|
r'href="(https://assets\.publishing\.service\.gov\.uk/[^"]+\.csv)"',
|
||||||
|
resp.text,
|
||||||
|
)
|
||||||
|
|
||||||
|
months = {
|
||||||
|
'january': 1, 'february': 2, 'march': 3, 'april': 4, 'may': 5, 'june': 6,
|
||||||
|
'july': 7, 'august': 8, 'september': 9, 'october': 10, 'november': 11, 'december': 12,
|
||||||
|
'jan': 1, 'feb': 2, 'mar': 3, 'apr': 4, 'jun': 6,
|
||||||
|
'jul': 7, 'aug': 8, 'sep': 9, 'oct': 10, 'nov': 11, 'dec': 12,
|
||||||
|
}
|
||||||
|
parsed_links = []
|
||||||
|
for link in csv_links:
|
||||||
|
normalized = link.lower().replace('-', '_')
|
||||||
|
if 'latest_inspections_as_at' not in normalized:
|
||||||
|
continue
|
||||||
|
match = re.search(r'as_at_(\d{1,2})_([a-z]+)_(\d{4})', normalized)
|
||||||
|
if match:
|
||||||
|
day, month_str, year = match.groups()
|
||||||
|
month = months.get(month_str)
|
||||||
|
if month:
|
||||||
|
try:
|
||||||
|
parsed_links.append((datetime(int(year), month, int(day)), link))
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
parsed_links.sort(reverse=True)
|
||||||
|
if parsed_links:
|
||||||
|
return parsed_links[0][1]
|
||||||
|
if csv_links:
|
||||||
|
return csv_links[-1]
|
||||||
|
matches = re.findall(
|
||||||
|
r'href="(https://assets\.publishing\.service\.gov\.uk/[^"]+\.ods)"',
|
||||||
|
resp.text,
|
||||||
|
)
|
||||||
|
return matches[0] if matches else None
|
||||||
|
```
|
||||||
|
|
||||||
|
(`mi_url` config still wins when set — `self.config.get("mi_url") or discover_csv_url()` is unchanged.)
|
||||||
|
|
||||||
|
- [ ] **Step 3: Parse and guard the date in staging**
|
||||||
|
|
||||||
|
In `stg_ofsted_inspections.sql`, inside the `renamed` CTE after the `rc_sixth_form` line, add:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
-- Start date of the latest FULL inspection (the report-card
|
||||||
|
-- inspection in the renewed framework). Guarded below: only kept
|
||||||
|
-- when the row actually carries report-card grades, because in
|
||||||
|
-- legacy-format files this column is the legacy inspection date.
|
||||||
|
to_date(nullif(trim(rc_inspection_date), 'NULL'), 'DD/MM/YYYY') as rc_inspection_date_raw,
|
||||||
|
```
|
||||||
|
|
||||||
|
and replace the final select:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
select
|
||||||
|
*,
|
||||||
|
case
|
||||||
|
when rc_safeguarding_met is not null
|
||||||
|
or rc_inclusion is not null
|
||||||
|
or rc_curriculum_teaching is not null
|
||||||
|
or rc_achievement is not null
|
||||||
|
or rc_attendance_behaviour is not null
|
||||||
|
or rc_personal_development is not null
|
||||||
|
or rc_leadership_governance is not null
|
||||||
|
then rc_inspection_date_raw
|
||||||
|
end as rc_inspection_date
|
||||||
|
from renamed
|
||||||
|
where inspection_date is not null
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 4: Propagate through int + mart**
|
||||||
|
|
||||||
|
Add `rc_inspection_date,` to the explicit column lists of `int_ofsted_latest.sql` and `fact_ofsted_inspection.sql` (after `rc_sixth_form`). Do NOT propagate `rc_inspection_date_raw`.
|
||||||
|
|
||||||
|
- [ ] **Step 5: Parse-check dbt**
|
||||||
|
|
||||||
|
Run: `cd pipeline/transform && uv run --with dbt-postgres python -m dbt.cli.main parse --profiles-dir .`
|
||||||
|
Expected: parse OK, no compilation errors.
|
||||||
|
|
||||||
|
- [ ] **Step 6: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add pipeline/plugins/extractors/tap-uk-ofsted pipeline/transform/models
|
||||||
|
git commit -m "feat(pipeline): carry the report-card inspection's own date; pick newest MI file in discovery"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 3: Report-card date in the API and UI
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `backend/models.py` (FactOfstedInspection)
|
||||||
|
- Modify: `backend/data_loader.py` (`_ofsted_block`)
|
||||||
|
- Test: `backend/tests/test_supplementary_enrichment.py` (extend the existing `_ofsted_block` tests)
|
||||||
|
- Modify: `nextjs-app/lib/types.ts` (OfstedInspection)
|
||||||
|
- Modify: `nextjs-app/components/compare/CompareOfsted.tsx` ("Inspected" measure)
|
||||||
|
- Test: `nextjs-app/__tests__/components/CompareOfsted.test.tsx`
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: `marts.fact_ofsted_inspection.rc_inspection_date` (Task 2).
|
||||||
|
- Produces: API `ofsted.rc_inspection_date: string | null` (ISO date). UI rule: report-card displays are dated with `rc_inspection_date` only; when null, show "—" (never the legacy date).
|
||||||
|
|
||||||
|
- [ ] **Step 1: Failing backend test**
|
||||||
|
|
||||||
|
In `backend/tests/test_supplementary_enrichment.py`, alongside the existing `_ofsted_block` tests, add (reuse the file's existing fake-row helper/style):
|
||||||
|
|
||||||
|
```python
|
||||||
|
def test_ofsted_block_carries_rc_inspection_date():
|
||||||
|
o = _fake_ofsted_row( # use this file's existing fake/stub construction
|
||||||
|
overall_effectiveness=None,
|
||||||
|
ungraded_grade=2,
|
||||||
|
rc_achievement=1,
|
||||||
|
rc_inspection_date=date(2026, 2, 3),
|
||||||
|
inspection_date=date(2021, 10, 7),
|
||||||
|
)
|
||||||
|
block = _ofsted_block(o, 138690)
|
||||||
|
assert block["rc_inspection_date"] == "2026-02-03"
|
||||||
|
# The legacy inspection date is still present, unchanged.
|
||||||
|
assert block["inspection_date"] == "2021-10-07"
|
||||||
|
|
||||||
|
|
||||||
|
def test_ofsted_block_rc_inspection_date_none_when_absent():
|
||||||
|
o = _fake_ofsted_row(overall_effectiveness=1, inspection_date=date(2021, 10, 13))
|
||||||
|
block = _ofsted_block(o, 136276)
|
||||||
|
assert block["rc_inspection_date"] is None
|
||||||
|
```
|
||||||
|
|
||||||
|
Run: `uv run --with-requirements requirements.txt --with pytest --with "httpx==0.27.0" python -m pytest backend/tests/test_supplementary_enrichment.py -q`
|
||||||
|
Expected: FAIL (KeyError / AttributeError on `rc_inspection_date`).
|
||||||
|
|
||||||
|
- [ ] **Step 2: Backend implementation**
|
||||||
|
|
||||||
|
`backend/models.py`, in `FactOfstedInspection` after `rc_sixth_form`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# Start date of the report-card inspection itself (renewed framework,
|
||||||
|
# Nov 2025+). Null for rows without report-card grades.
|
||||||
|
rc_inspection_date = Column(Date)
|
||||||
|
```
|
||||||
|
|
||||||
|
`backend/data_loader.py` `_ofsted_block`, after the `"inspection_date"` entry:
|
||||||
|
|
||||||
|
```python
|
||||||
|
"rc_inspection_date": (
|
||||||
|
o.rc_inspection_date.isoformat()
|
||||||
|
if getattr(o, "rc_inspection_date", None)
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
```
|
||||||
|
|
||||||
|
(`getattr` default keeps old test stubs working.) Run the backend suite; expected: PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Failing frontend test**
|
||||||
|
|
||||||
|
`nextjs-app/lib/types.ts`, in `OfstedInspection`, after `inspection_date`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
/** Start date of the report-card inspection itself (Nov 2025+); null otherwise. */
|
||||||
|
rc_inspection_date?: string | null;
|
||||||
|
```
|
||||||
|
|
||||||
|
In `nextjs-app/__tests__/components/CompareOfsted.test.tsx`, add to the existing suite (reusing its fixture style):
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
it('dates a report card with the report-card inspection date, never the legacy date', () => {
|
||||||
|
const ofsted = reportCardOfsted({
|
||||||
|
inspection_date: '2021-10-07',
|
||||||
|
rc_inspection_date: '2026-02-03',
|
||||||
|
});
|
||||||
|
render(<CompareOfsted schools={[schoolFixture]} data={{ [String(schoolFixture.urn)]: { ...dataFixture, ofsted } }} />);
|
||||||
|
expect(screen.getByText(/3 Feb 2026/)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/7 Oct 2021/)).toBeNull();
|
||||||
|
expect(screen.queryByText('4+ years ago')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows an em dash when a report card has no rc_inspection_date yet', () => {
|
||||||
|
const ofsted = reportCardOfsted({ inspection_date: '2021-10-07', rc_inspection_date: null });
|
||||||
|
render(<CompareOfsted schools={[schoolFixture]} data={{ [String(schoolFixture.urn)]: { ...dataFixture, ofsted } }} />);
|
||||||
|
expect(screen.getByText('—')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/7 Oct 2021/)).toBeNull();
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
(`reportCardOfsted` = the file's existing report-card fixture builder, or build inline matching its other tests.) Run just this file; expected: FAIL.
|
||||||
|
|
||||||
|
- [ ] **Step 4: Frontend implementation**
|
||||||
|
|
||||||
|
In `CompareOfsted.tsx`, replace the body of the "Inspected" measure's map:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{schools.map((school, i) => {
|
||||||
|
const ofsted = data[String(school.urn)]?.ofsted;
|
||||||
|
// A report card is dated by its OWN inspection date. The legacy
|
||||||
|
// inspection_date belongs to an older inspection and must never
|
||||||
|
// be shown against a report card (report cards exist only from
|
||||||
|
// Nov 2025).
|
||||||
|
const dateIso =
|
||||||
|
displays[i].kind === 'report_card'
|
||||||
|
? ofsted?.rc_inspection_date ?? null
|
||||||
|
: ofsted?.inspection_date ?? null;
|
||||||
|
const age = yearsSince(dateIso);
|
||||||
|
return (
|
||||||
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
|
{formatInspectionDate(dateIso)}{' '}
|
||||||
|
{age != null && age > 4 && <Chip tone="neutral">4+ years ago</Chip>}
|
||||||
|
</Cell>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 5: Run frontend checks**
|
||||||
|
|
||||||
|
Run: `cd nextjs-app && npx tsc --noEmit && npm test`
|
||||||
|
Expected: PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 6: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add backend/models.py backend/data_loader.py backend/tests nextjs-app/lib/types.ts nextjs-app/components/compare/CompareOfsted.tsx nextjs-app/__tests__/components/CompareOfsted.test.tsx
|
||||||
|
git commit -m "fix(compare): date report cards with their own inspection date, never the legacy one"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 4: Census-based context benchmarks; kill the FSM fallback
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Create: `pipeline/transform/models/marts/fact_census_benchmarks.sql`
|
||||||
|
- Modify: `pipeline/transform/models/marts/_marts_schema.yml`
|
||||||
|
- Modify: `backend/models.py` (new `CensusBenchmark` model)
|
||||||
|
- Modify: `backend/data_loader.py` (`compute_benchmarks`)
|
||||||
|
- Modify: `backend/app.py` (compare endpoint call site, only if the signature change requires it)
|
||||||
|
- Test: `backend/tests/test_benchmarks.py`
|
||||||
|
- Modify: `nextjs-app/components/compare/CompareCommunity.tsx:36`
|
||||||
|
- Test: `nextjs-app/__tests__/lib/compareLogic.test.ts` or the community section's existing test home (add a fallback-removal test where the FSM chip logic is tested today)
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: `marts.fact_pupil_characteristics` (urn, year, phase_type_grouping, total_pupils, fsm_pct, eal_pct).
|
||||||
|
- Produces: `marts.fact_census_benchmarks` — one row per phase (`'primary'`/`'secondary'`), columns `phase, year, fsm_pct, eal_pct, median_pupils`. `fsm_pct`/`eal_pct` are **pupil-weighted means** (so they approximate the national pupil-level rate, answering the expert's objection to school-median anchors). API `benchmarks.{primary,secondary}` keeps its existing keys; `fsm_pct`/`eal_pct`/`median_pupils` now come from this mart; `disadvantaged_pct` becomes primary-only (the KS2-column median was junk for secondary).
|
||||||
|
|
||||||
|
- [ ] **Step 1: dbt mart**
|
||||||
|
|
||||||
|
Create `pipeline/transform/models/marts/fact_census_benchmarks.sql`:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
{{ config(materialized='table') }}
|
||||||
|
|
||||||
|
-- Mart: state-school context benchmarks from the pupil census — one row per
|
||||||
|
-- phase, latest census year. Computed at import time (never per request).
|
||||||
|
-- fsm_pct / eal_pct are pupil-weighted means, i.e. "what % of pupils", not
|
||||||
|
-- "the median school" — this matches how DfE quotes national FSM/EAL rates.
|
||||||
|
-- Consumers must label these "state-school average (computed from our
|
||||||
|
-- dataset)" (spec §8.6), never "England average".
|
||||||
|
|
||||||
|
with latest as (
|
||||||
|
select max(year) as year from {{ ref('fact_pupil_characteristics') }}
|
||||||
|
),
|
||||||
|
|
||||||
|
classified as (
|
||||||
|
select
|
||||||
|
case
|
||||||
|
when p.phase_type_grouping ilike '%primary%' then 'primary'
|
||||||
|
when p.phase_type_grouping ilike '%secondary%' then 'secondary'
|
||||||
|
end as phase,
|
||||||
|
p.total_pupils,
|
||||||
|
p.fsm_pct,
|
||||||
|
p.eal_pct,
|
||||||
|
l.year
|
||||||
|
from {{ ref('fact_pupil_characteristics') }} p
|
||||||
|
join latest l on p.year = l.year
|
||||||
|
where p.total_pupils is not null and p.total_pupils > 0
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
phase,
|
||||||
|
max(year) as year,
|
||||||
|
round((sum(fsm_pct * total_pupils) filter (where fsm_pct is not null)
|
||||||
|
/ nullif(sum(total_pupils) filter (where fsm_pct is not null), 0))::numeric, 1) as fsm_pct,
|
||||||
|
round((sum(eal_pct * total_pupils) filter (where eal_pct is not null)
|
||||||
|
/ nullif(sum(total_pupils) filter (where eal_pct is not null), 0))::numeric, 1) as eal_pct,
|
||||||
|
round(percentile_cont(0.5) within group (order by total_pupils))::integer as median_pupils
|
||||||
|
from classified
|
||||||
|
where phase is not null
|
||||||
|
group by phase
|
||||||
|
```
|
||||||
|
|
||||||
|
Add a `fact_census_benchmarks` entry to `_marts_schema.yml` in the file's existing style (name + description; column tests only if sibling marts have them).
|
||||||
|
|
||||||
|
Run: `cd pipeline/transform && uv run --with dbt-postgres python -m dbt.cli.main parse --profiles-dir .` — expected PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 2: Failing backend test**
|
||||||
|
|
||||||
|
In `backend/tests/test_benchmarks.py` add:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def test_benchmarks_use_census_mart_for_context(monkeypatch):
|
||||||
|
census = {
|
||||||
|
"primary": {"year": 202425, "fsm_pct": 25.3, "eal_pct": 21.8, "median_pupils": 240},
|
||||||
|
"secondary": {"year": 202425, "fsm_pct": 24.1, "eal_pct": 18.9, "median_pupils": 980},
|
||||||
|
}
|
||||||
|
result = compute_benchmarks(_sample_df(), census_benchmarks=census)
|
||||||
|
assert result["primary"]["fsm_pct"] == 25.3
|
||||||
|
assert result["secondary"]["eal_pct"] == 18.9
|
||||||
|
assert result["secondary"]["median_pupils"] == 980
|
||||||
|
# KS2-only columns must not produce a fake secondary disadvantaged anchor.
|
||||||
|
assert result["secondary"]["disadvantaged_pct"] is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_benchmarks_context_none_when_mart_missing():
|
||||||
|
result = compute_benchmarks(_sample_df(), census_benchmarks=None)
|
||||||
|
assert result["primary"]["fsm_pct"] is None # never silently fall back
|
||||||
|
```
|
||||||
|
|
||||||
|
(`_sample_df()` = this file's existing dataframe fixture.) Run the file; expected: FAIL (unexpected keyword `census_benchmarks`).
|
||||||
|
|
||||||
|
- [ ] **Step 3: Backend implementation**
|
||||||
|
|
||||||
|
`backend/models.py` (next to the national-average models):
|
||||||
|
|
||||||
|
```python
|
||||||
|
class CensusBenchmark(Base):
|
||||||
|
"""State-school context benchmarks from the pupil census — one row per phase."""
|
||||||
|
__tablename__ = "fact_census_benchmarks"
|
||||||
|
__table_args__ = MARTS
|
||||||
|
|
||||||
|
phase = Column(String(20), primary_key=True)
|
||||||
|
year = Column(Integer)
|
||||||
|
fsm_pct = Column(Float) # pupil-weighted mean
|
||||||
|
eal_pct = Column(Float) # pupil-weighted mean
|
||||||
|
median_pupils = Column(Integer)
|
||||||
|
```
|
||||||
|
|
||||||
|
`backend/data_loader.py` — change the signature and `_block`:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def compute_benchmarks(df: pd.DataFrame, census_benchmarks: dict | None = None) -> dict:
|
||||||
|
```
|
||||||
|
|
||||||
|
Inside, keep `_median` and `_weighted_disadvantaged` as-is, and replace `_block` with:
|
||||||
|
|
||||||
|
```python
|
||||||
|
def _block(sub, phase, with_disadvantaged):
|
||||||
|
census = (census_benchmarks or {}).get(phase) or {}
|
||||||
|
block = {
|
||||||
|
# Context measures come from the census mart (pupil-weighted):
|
||||||
|
# the performance df has no fsm_pct, and its eal/disadvantaged
|
||||||
|
# columns are KS2-only — medianing them for "secondary" produced
|
||||||
|
# junk anchors from the handful of all-through schools.
|
||||||
|
"eal_pct": census.get("eal_pct"),
|
||||||
|
"sen_support_pct": _median(sub, "sen_support_pct"),
|
||||||
|
"disadvantaged_pct": _median(sub, "disadvantaged_pct") if with_disadvantaged else None,
|
||||||
|
"fsm_pct": census.get("fsm_pct"),
|
||||||
|
"median_pupils": census.get("median_pupils"),
|
||||||
|
}
|
||||||
|
if with_disadvantaged:
|
||||||
|
block["disadvantaged_rwm_expected_pct"] = _weighted_disadvantaged(sub)
|
||||||
|
return block
|
||||||
|
```
|
||||||
|
|
||||||
|
and the return:
|
||||||
|
|
||||||
|
```python
|
||||||
|
return {
|
||||||
|
"source": "state-school average (computed from our dataset)",
|
||||||
|
"year": int(latest_year),
|
||||||
|
"primary": _block(prim, "primary", with_disadvantaged=True),
|
||||||
|
"secondary": _block(sec, "secondary", with_disadvantaged=False),
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
In `backend/app.py`'s compare endpoint, load the mart and pass it (same defensive style as the national-averages queries):
|
||||||
|
|
||||||
|
```python
|
||||||
|
census_benchmarks = None
|
||||||
|
try:
|
||||||
|
rows = db.query(CensusBenchmark).all()
|
||||||
|
if rows:
|
||||||
|
census_benchmarks = {
|
||||||
|
r.phase: {
|
||||||
|
"year": r.year,
|
||||||
|
"fsm_pct": r.fsm_pct,
|
||||||
|
"eal_pct": r.eal_pct,
|
||||||
|
"median_pupils": r.median_pupils,
|
||||||
|
}
|
||||||
|
for r in rows
|
||||||
|
}
|
||||||
|
except Exception:
|
||||||
|
db.rollback()
|
||||||
|
...
|
||||||
|
"benchmarks": compute_benchmarks(df, census_benchmarks=census_benchmarks),
|
||||||
|
```
|
||||||
|
|
||||||
|
(Import `CensusBenchmark`; use the endpoint's existing db session pattern.) Run the backend suite; expected: PASS (update any existing benchmark tests that asserted the old median-sourced fsm/eal values).
|
||||||
|
|
||||||
|
- [ ] **Step 4: Frontend — remove the cross-definition fallback**
|
||||||
|
|
||||||
|
`nextjs-app/components/compare/CompareCommunity.tsx:36`:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
const anchor = bench?.fsm_pct ?? null;
|
||||||
|
```
|
||||||
|
|
||||||
|
If the FSM chip has unit coverage, update/add the case: `anchor` null ⇒ no verdict chip rendered (bare value only). Run `cd nextjs-app && npx tsc --noEmit && npm test` — expected PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add pipeline/transform/models/marts backend/models.py backend/data_loader.py backend/app.py backend/tests/test_benchmarks.py nextjs-app/components/compare/CompareCommunity.tsx nextjs-app/__tests__
|
||||||
|
git commit -m "fix(compare): census-sourced FSM/EAL benchmarks; never fall back across measure definitions"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 5: Official KS4 national averages
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `pipeline/plugins/extractors/tap-uk-ees/tap_uk_ees/tap.py` (new stream, registered in `discover_streams`)
|
||||||
|
- Create: `pipeline/transform/models/staging/stg_ees_ks4_national.sql`
|
||||||
|
- Modify: `pipeline/transform/models/staging/_stg_sources.yml` (add raw table `ees_ks4_national`)
|
||||||
|
- Modify: `pipeline/transform/models/marts/fact_ks4_national_averages.sql` (rewrite)
|
||||||
|
- Modify: `backend/models.py` (Ks4NationalAverage docstring), `backend/app.py` (`_national_averages_payload` — remove the computed fallback)
|
||||||
|
- Test: `backend/tests/test_national_averages_marts.py`
|
||||||
|
|
||||||
|
**Interfaces:**
|
||||||
|
- Consumes: EES data-catalogue CSV `https://explore-education-statistics.service.gov.uk/data-catalogue/data-set/1b649e16-01e8-435b-a814-56be2faf9054/csv` (columns verified: `time_period, geographic_level, establishment_type_group, breakdown_topic, breakdown, attainment8_average, progress8_average, engmath_95_percent, engmath_94_percent, ebacc_entering_percent, ebacc_95_percent, ebacc_94_percent, ebacc_aps_average, …`).
|
||||||
|
- Produces: `marts.fact_ks4_national_averages` with the SAME columns as today (so `Ks4NationalAverage` needs no schema change), now holding official DfE figures; `gcse_grade_91_pct` is NULL (not in the official series — the England anchor for that measure disappears, which is correct: it was noise).
|
||||||
|
|
||||||
|
- [ ] **Step 1: Tap stream**
|
||||||
|
|
||||||
|
In `tap.py`, after the KS2 national stream, add:
|
||||||
|
|
||||||
|
```python
|
||||||
|
# ── KS4 National Headlines (national level only — one row per year) ──────────
|
||||||
|
# Dataset: "National characteristics summary data" (Key stage 4 performance).
|
||||||
|
# Official England state-funded headline measures, 2018/19 → latest.
|
||||||
|
# Suppressed values ('z', 'x') → NULL downstream. Progress 8 is legitimately
|
||||||
|
# absent in years with no KS2 baseline (e.g. 2024/25) — that is DfE policy,
|
||||||
|
# not missing data.
|
||||||
|
|
||||||
|
_KS4_NATIONAL_CSV_URL = (
|
||||||
|
"https://explore-education-statistics.service.gov.uk/data-catalogue/"
|
||||||
|
"data-set/1b649e16-01e8-435b-a814-56be2faf9054/csv"
|
||||||
|
)
|
||||||
|
|
||||||
|
_KS4_NATIONAL_COL_MAP = {
|
||||||
|
"attainment8_average": "attainment_8_score",
|
||||||
|
"progress8_average": "progress_8_score",
|
||||||
|
"engmath_94_percent": "english_maths_standard_pass_pct",
|
||||||
|
"engmath_95_percent": "english_maths_strong_pass_pct",
|
||||||
|
"ebacc_entering_percent": "ebacc_entry_pct",
|
||||||
|
"ebacc_94_percent": "ebacc_standard_pass_pct",
|
||||||
|
"ebacc_95_percent": "ebacc_strong_pass_pct",
|
||||||
|
"ebacc_aps_average": "ebacc_avg_score",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EESKs4NationalStream(Stream):
|
||||||
|
"""National KS4 headline averages — one row per academic year.
|
||||||
|
|
||||||
|
Filters to geographic_level == 'National', establishment_type_group ==
|
||||||
|
'All state-funded', breakdown_topic == 'Total', breakdown == 'Total'
|
||||||
|
so only the England-wide all-pupils row per year is emitted.
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "ees_ks4_national"
|
||||||
|
primary_keys = ["time_period"]
|
||||||
|
replication_key = None
|
||||||
|
|
||||||
|
schema = th.PropertiesList(
|
||||||
|
th.Property("time_period", th.StringType, required=True),
|
||||||
|
*[th.Property(out, th.StringType) for out in _KS4_NATIONAL_COL_MAP.values()],
|
||||||
|
).to_dict()
|
||||||
|
|
||||||
|
def get_records(self, context):
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
self.logger.info("Downloading KS4 national headlines: %s", _KS4_NATIONAL_CSV_URL)
|
||||||
|
resp = requests.get(_KS4_NATIONAL_CSV_URL, timeout=60)
|
||||||
|
resp.raise_for_status()
|
||||||
|
|
||||||
|
df = pd.read_csv(io.BytesIO(resp.content), dtype=str, keep_default_na=False)
|
||||||
|
df.columns = [c.strip().lower() for c in df.columns]
|
||||||
|
|
||||||
|
for col, want in [
|
||||||
|
("geographic_level", "national"),
|
||||||
|
("establishment_type_group", "all state-funded"),
|
||||||
|
("breakdown_topic", "total"),
|
||||||
|
("breakdown", "total"),
|
||||||
|
]:
|
||||||
|
if col in df.columns:
|
||||||
|
df = df[df[col].str.strip().str.lower() == want]
|
||||||
|
|
||||||
|
self.logger.info("Emitting %d national KS4 rows", len(df))
|
||||||
|
for _, row in df.iterrows():
|
||||||
|
record = {"time_period": row.get("time_period", "").strip()}
|
||||||
|
for src, out in _KS4_NATIONAL_COL_MAP.items():
|
||||||
|
record[out] = row.get(src, "")
|
||||||
|
yield record
|
||||||
|
```
|
||||||
|
|
||||||
|
Register `EESKs4NationalStream(self)` in `discover_streams` next to the KS2 national stream.
|
||||||
|
|
||||||
|
- [ ] **Step 2: Raw source + staging model**
|
||||||
|
|
||||||
|
Add to `_stg_sources.yml` under the raw source, matching the `ees_ks2_national` entry's style:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- name: ees_ks4_national
|
||||||
|
description: Official DfE KS4 national headline averages (EES data catalogue)
|
||||||
|
```
|
||||||
|
|
||||||
|
Create `pipeline/transform/models/staging/stg_ees_ks4_national.sql`:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
{{ config(materialized='table') }}
|
||||||
|
|
||||||
|
-- Staging model: official DfE KS4 national headline averages — one row per
|
||||||
|
-- academic year (England, all state-funded, all pupils). Source: EES data
|
||||||
|
-- catalogue "National characteristics summary data". Suppressed values
|
||||||
|
-- ('z', 'x') are coerced to NULL by safe_numeric — Progress 8 is 'z' in
|
||||||
|
-- years with no KS2 baseline (e.g. 2024/25): legitimately unpublished.
|
||||||
|
|
||||||
|
select
|
||||||
|
cast(trim(time_period) as integer) as year,
|
||||||
|
{{ safe_numeric('attainment_8_score') }} as attainment_8_score,
|
||||||
|
{{ safe_numeric('progress_8_score') }} as progress_8_score,
|
||||||
|
{{ safe_numeric('english_maths_standard_pass_pct') }} as english_maths_standard_pass_pct,
|
||||||
|
{{ safe_numeric('english_maths_strong_pass_pct') }} as english_maths_strong_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_entry_pct') }} as ebacc_entry_pct,
|
||||||
|
{{ safe_numeric('ebacc_standard_pass_pct') }} as ebacc_standard_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_strong_pass_pct') }} as ebacc_strong_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_avg_score') }} as ebacc_avg_score
|
||||||
|
from {{ source('raw', 'ees_ks4_national') }}
|
||||||
|
where time_period ~ '^[0-9]+$'
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 3: Rewrite the mart**
|
||||||
|
|
||||||
|
Replace the entire body of `fact_ks4_national_averages.sql`:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
{{ config(materialized='table') }}
|
||||||
|
|
||||||
|
-- Mart: OFFICIAL DfE KS4 national headline averages — one row per academic
|
||||||
|
-- year (England, state-funded, all pupils), from the EES national dataset.
|
||||||
|
-- Replaces the previous unweighted school-level means, which were 7–15
|
||||||
|
-- points off every headline measure and produced an arithmetically
|
||||||
|
-- impossible national Progress 8. gcse_grade_91_pct has no official
|
||||||
|
-- national series and is NULL (schema kept for the API model).
|
||||||
|
|
||||||
|
select
|
||||||
|
year,
|
||||||
|
attainment_8_score,
|
||||||
|
progress_8_score,
|
||||||
|
english_maths_standard_pass_pct,
|
||||||
|
english_maths_strong_pass_pct,
|
||||||
|
ebacc_entry_pct,
|
||||||
|
ebacc_standard_pass_pct,
|
||||||
|
ebacc_strong_pass_pct,
|
||||||
|
ebacc_avg_score,
|
||||||
|
cast(null as double precision) as gcse_grade_91_pct
|
||||||
|
from {{ ref('stg_ees_ks4_national') }}
|
||||||
|
order by year
|
||||||
|
```
|
||||||
|
|
||||||
|
Run: `cd pipeline/transform && uv run --with dbt-postgres python -m dbt.cli.main parse --profiles-dir .` — expected PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 4: Backend — official provenance, no computed fallback**
|
||||||
|
|
||||||
|
`backend/models.py`: change the `Ks4NationalAverage` docstring to `"""Official DfE KS4 national headline averages — one row per academic year."""`.
|
||||||
|
|
||||||
|
`backend/app.py` `_national_averages_payload`: delete the entire `if not any(secondary_by_year.values()):` fallback block (it computes dataset means that the UI footnote then labels official). Update the function docstring's KS4 sentence to: `official DfE KS4 figures (fact_ks4_national_averages). If the KS4 mart hasn't been built yet, the secondary series is empty — never a computed stand-in, because the UI labels these figures as official.`
|
||||||
|
|
||||||
|
Update `backend/tests/test_national_averages_marts.py`: the test that exercised the fallback now asserts the opposite —
|
||||||
|
|
||||||
|
```python
|
||||||
|
def test_ks4_secondary_empty_when_mart_missing(...):
|
||||||
|
# No computed stand-in: the UI labels national figures as official DfE
|
||||||
|
# data, so an empty mart must yield an empty secondary series.
|
||||||
|
payload = _national_averages_payload(df)
|
||||||
|
assert all(not e["secondary"] for e in payload["by_year"])
|
||||||
|
```
|
||||||
|
|
||||||
|
(adapt to the file's existing fixtures/monkeypatching). Run the backend suite — expected PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add pipeline/plugins/extractors/tap-uk-ees pipeline/transform backend
|
||||||
|
git commit -m "fix(data): official DfE KS4 national headline averages; drop mislabelled computed means"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 6: Honest 2021/22 footnote
|
||||||
|
|
||||||
|
**Files:**
|
||||||
|
- Modify: `nextjs-app/components/ComparisonChart.tsx:243-247`
|
||||||
|
- Modify: `nextjs-app/lib/compareChartData.ts` (comment lines 7, 53–55 — comments only, no logic)
|
||||||
|
- Modify: `nextjs-app/__tests__/lib/compareChartData.test.ts` (test name/comment wording only)
|
||||||
|
- Modify: `docs/superpowers/specs/2026-07-11-compare-screen-redesign-design.md` §8.1
|
||||||
|
|
||||||
|
**Interfaces:** none — copy and docs only. This is the one place the plan changes reviewed copy, because the reviewed copy is factually wrong (Global Constraints exception).
|
||||||
|
|
||||||
|
- [ ] **Step 1: Fix the user-facing copy**
|
||||||
|
|
||||||
|
In `ComparisonChart.tsx` replace the note:
|
||||||
|
|
||||||
|
```tsx
|
||||||
|
{built.showUnpublished202122Note && (
|
||||||
|
<p className={styles.chartNote}>
|
||||||
|
No national tests were held in 2019/20 and 2020/21 (COVID), and our dataset doesn't
|
||||||
|
yet include school-level figures for 2021/22 — the England average is shown for that
|
||||||
|
year.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
```
|
||||||
|
|
||||||
|
- [ ] **Step 2: Fix the lying comments**
|
||||||
|
|
||||||
|
In `compareChartData.ts`, update the header comment (line 7) and the `showUnpublished202122Note` doc comment (lines 53–55) to say the 2021/22 school-level figures are *absent from our dataset* (DfE published them in Dec 2022; ingesting them is a backlog pipeline task), not "unpublished". Rename nothing (the flag name stays — pure rename churn). In `compareChartData.test.ts`, adjust the test description/comment wording the same way.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Correct spec §8.1**
|
||||||
|
|
||||||
|
In the spec's §8.1, replace any wording that calls 2021/22 school-level KS2 a "permanent DfE gap" with: DfE published school-level KS2 results for 2021/22 in December 2022 (with comparability caveats); they are not yet ingested — loading them remains an open pipeline task, and the chart footnote says "our dataset doesn't yet include" accordingly.
|
||||||
|
|
||||||
|
- [ ] **Step 4: Verify + commit**
|
||||||
|
|
||||||
|
Run: `cd nextjs-app && npx tsc --noEmit && npm test` — expected PASS.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add nextjs-app docs/superpowers/specs/2026-07-11-compare-screen-redesign-design.md
|
||||||
|
git commit -m "fix(compare): stop attributing the missing 2021/22 school-level year to DfE"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Task 7: Full verification, PR, and post-deploy checklist
|
||||||
|
|
||||||
|
**Files:** none new (verification + PR).
|
||||||
|
|
||||||
|
- [ ] **Step 1: Run everything**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
uv run --with-requirements requirements.txt --with pytest --with "httpx==0.27.0" python -m pytest backend/tests -q
|
||||||
|
cd nextjs-app && npx tsc --noEmit && npm test && cd ..
|
||||||
|
cd pipeline/transform && uv run --with dbt-postgres python -m dbt.cli.main parse --profiles-dir . && cd ../..
|
||||||
|
```
|
||||||
|
|
||||||
|
Expected: all PASS.
|
||||||
|
|
||||||
|
- [ ] **Step 2: Open the PR**
|
||||||
|
|
||||||
|
Push `fix/compare-final-review-mustfix`; open a PR via the Gitea API using `git credential fill` basic auth (token-header auth 401s). PR body: summarize the five findings and fixes, link the expert review, end with the standard Claude Code attribution + session URL. Note in the body that findings 2 and 4 also need a **DAG run after the staging deploy** before the UI shows corrected data.
|
||||||
|
|
||||||
|
- [ ] **Step 3: Post-merge staging verification (after the user merges and the daily DAG runs — record results, do not promote)**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Report card dated by its own inspection (Barclay): expect 2026-02-03
|
||||||
|
curl -sk "https://stx.schoolcompare.co.uk/api/compare?urns=138690" | python3 -c "import json,sys; o=json.load(sys.stdin)['comparison']['138690']['ofsted']; print(o['rc_inspection_date'], o['inspection_date'])"
|
||||||
|
# Stale Watford rc grades cleared by the fresh extract: expect report_card == {}
|
||||||
|
curl -sk "https://stx.schoolcompare.co.uk/api/compare?urns=136276" | python3 -c "import json,sys; print(json.load(sys.stdin)['comparison']['136276']['ofsted']['report_card'])"
|
||||||
|
# Official KS4 nationals: expect A8 46.0 for 202425, progress_8_score absent
|
||||||
|
curl -sk "https://stx.schoolcompare.co.uk/api/national-averages" | python3 -c "import json,sys; print(json.load(sys.stdin)['secondary'])"
|
||||||
|
# FSM benchmark real (~24-26), secondary disadvantaged_pct gone
|
||||||
|
curl -sk "https://stx.schoolcompare.co.uk/api/compare?urns=138690,136276" | python3 -c "import json,sys; print(json.load(sys.stdin)['benchmarks'])"
|
||||||
|
```
|
||||||
|
|
||||||
|
Then re-screenshot both phase views (desktop + mobile, "More measures" expanded, Watford Grammar in the secondary set) and hand them to the Ofsted expert agent for the sign-off pass it said it expects. Production promotion remains the human's manual call.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Out of Scope (expert should-fix/minor — separate follow-ups)
|
||||||
|
|
||||||
|
- 137086-style interim state (subgrades without an overall from an RI reinspection) rendering treatment (finding 6).
|
||||||
|
- Disadvantaged cohort sizes on the attainment row (finding 7, spec §8.5).
|
||||||
|
- SEN/EAL "typical school" labelling and secondary SEN benchmark (finding 8) — note Task 4 already upgrades EAL to a pupil-weighted census figure.
|
||||||
|
- Selective-school admissions copy variant (finding 9).
|
||||||
|
- Removing/relabelling `gcse_grade_91_pct` as a compare measure (finding 10) — Task 5 already removes its false England anchor.
|
||||||
|
- Palette deviation (11), trends picker label (12), "More measures" expanded-state verification (13).
|
||||||
|
- Actually ingesting the 2021/22 school-level KS2 release (the copy in Task 6 says "doesn't *yet* include").
|
||||||
@@ -256,7 +256,12 @@ implementation, beyond what the mockups can show:
|
|||||||
DfE stated it would not publish KS2 2021/22 in performance tables
|
DfE stated it would not publish KS2 2021/22 in performance tables
|
||||||
(verified 2026-07-12 against EES, the CSP download service, and
|
(verified 2026-07-12 against EES, the CSP download service, and
|
||||||
DfE release notes; see `# TASK 6 VERIFICATION` in
|
DfE release notes; see `# TASK 6 VERIFICATION` in
|
||||||
`pipeline/scripts/diagnose_compare_gaps.py`). The chart's England-
|
`pipeline/scripts/diagnose_compare_gaps.py`; re-verified 2026-07-16
|
||||||
|
after an expert-review challenge — the GOV.UK statistics announcement
|
||||||
|
"Primary school performance tables: 2022" is marked CANCELLED with
|
||||||
|
"will not be published in key stage 2 performance tables in academic
|
||||||
|
year 2021/22", so the footnote's "DfE didn't publish" claim stands
|
||||||
|
and must not be softened to "not in our dataset"). The chart's England-
|
||||||
only 2021/22 point with broken school lines is therefore the
|
only 2021/22 point with broken school lines is therefore the
|
||||||
correct permanent rendering; copy should say "DfE didn't publish
|
correct permanent rendering; copy should say "DfE didn't publish
|
||||||
school-level figures for 2021/22", not "not in our dataset yet".
|
school-level figures for 2021/22", not "not in our dataset yet".
|
||||||
|
|||||||
+200
-12
@@ -19,6 +19,40 @@ function schoolLinks(page: Page) {
|
|||||||
return page.locator('a[href^="/school/"]');
|
return page.locator('a[href^="/school/"]');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Two URNs guaranteed to be pure-primary (same phase). The compare page's
|
||||||
|
* phase tabs split all-through schools (which carry KS4 data) onto the
|
||||||
|
* secondary tab, so picking two arbitrary "primary" search hits can land
|
||||||
|
* them on different tabs where only the active one renders. Selecting via
|
||||||
|
* the API by exact phase keeps both on the same tab. Data-invariant: uses
|
||||||
|
* whatever primaries the environment holds.
|
||||||
|
*/
|
||||||
|
async function twoPrimaryUrns(page: Page): Promise<[string, string]> {
|
||||||
|
const res = await page.request.get('/api/schools?search=primary&per_page=50');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const body = await res.json();
|
||||||
|
const urns: string[] = (body.schools ?? [])
|
||||||
|
.filter((s: { phase?: string; rwm_expected_pct?: number | null }) =>
|
||||||
|
s.phase === 'Primary' && s.rwm_expected_pct != null,
|
||||||
|
)
|
||||||
|
.map((s: { urn: number }) => String(s.urn));
|
||||||
|
expect(urns.length).toBeGreaterThanOrEqual(2);
|
||||||
|
return [urns[0], urns[1]];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function twoSecondaryUrns(page: Page): Promise<[string, string]> {
|
||||||
|
const res = await page.request.get('/api/schools?search=school&per_page=100');
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const body = await res.json();
|
||||||
|
const urns: string[] = (body.schools ?? [])
|
||||||
|
.filter((s: { phase?: string; attainment_8_score?: number | null }) =>
|
||||||
|
s.phase === 'Secondary' && s.attainment_8_score != null,
|
||||||
|
)
|
||||||
|
.map((s: { urn: number }) => String(s.urn));
|
||||||
|
expect(urns.length).toBeGreaterThanOrEqual(2);
|
||||||
|
return [urns[0], urns[1]];
|
||||||
|
}
|
||||||
|
|
||||||
test('home page loads with hero search', async ({ page }) => {
|
test('home page loads with hero search', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
await expect(page.locator('h1').first()).toBeVisible();
|
await expect(page.locator('h1').first()).toBeVisible();
|
||||||
@@ -46,6 +80,33 @@ test('searching by postcode returns nearby schools', async ({ page }) => {
|
|||||||
await expect(schoolLinks(page).first()).toBeVisible({ timeout: 15_000 });
|
await expect(schoolLinks(page).first()).toBeVisible({ timeout: 15_000 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a report-card school shows a Report Card badge in search results, not its old grade', async ({ page }) => {
|
||||||
|
// List/map badges keyed off ofsted_grade (the carried-forward legacy grade)
|
||||||
|
// and never reached the report-card branch, so report-card schools were
|
||||||
|
// labelled by their old grade (e.g. "Outstanding · 2021"). The list now
|
||||||
|
// carries ofsted_rc_date and the badge treats a report card as winning.
|
||||||
|
const RC_URN = 138690; // Barclay Primary — has a Nov-2025+ report card
|
||||||
|
const res = await page.request.get(`/api/schools?search=Barclay%20Primary&page_size=5`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const barclay = ((await res.json()).schools ?? []).find(
|
||||||
|
(s: { urn: number }) => s.urn === RC_URN,
|
||||||
|
);
|
||||||
|
// Hard assertions, not test.skip: if the backend stops exposing
|
||||||
|
// ofsted_rc_date for this report-card school, that IS the regression this
|
||||||
|
// test exists to catch, so it must fail loudly rather than skip.
|
||||||
|
expect(barclay, 'Barclay must appear in the search results').toBeTruthy();
|
||||||
|
expect(
|
||||||
|
barclay.ofsted_rc_date,
|
||||||
|
'the list must expose ofsted_rc_date for a report-card school',
|
||||||
|
).toBeTruthy();
|
||||||
|
|
||||||
|
await searchByName(page, 'Barclay Primary');
|
||||||
|
// The Barclay row must be present…
|
||||||
|
await expect(page.locator(`a[href*="${RC_URN}"]`).first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
// …badged as a Report Card, not its carried-forward "Outstanding" grade.
|
||||||
|
await expect(page.getByText(/Report Card ·/).first()).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();
|
||||||
@@ -60,6 +121,64 @@ test('school detail page renders name and performance data', async ({ page }) =>
|
|||||||
await expect(page.locator('canvas:visible').first()).toBeVisible({ timeout: 15_000 });
|
await expect(page.locator('canvas:visible').first()).toBeVisible({ timeout: 15_000 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a report-card school shows its report card, dated to the report-card inspection', async ({ page }) => {
|
||||||
|
// Detail views detected report cards via `framework`, which the API never
|
||||||
|
// sets to "ReportCard" — so report-card schools rendered as legacy ratings
|
||||||
|
// dated to a pre-Nov-2025 inspection. Detection now keys off the report_card
|
||||||
|
// object and dates it with rc_inspection_date.
|
||||||
|
const RC_URN = 138690; // Barclay Primary — has a Nov-2025+ report card
|
||||||
|
const res = await page.request.get(`/api/schools/${RC_URN}`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const ofsted = (await res.json()).ofsted;
|
||||||
|
test.skip(
|
||||||
|
!ofsted?.report_card || Object.keys(ofsted.report_card).length === 0,
|
||||||
|
'precondition: chosen URN must currently have a report card',
|
||||||
|
);
|
||||||
|
const rcYear = new Date(ofsted.rc_inspection_date).getFullYear();
|
||||||
|
const legacyYear = new Date(ofsted.inspection_date).getFullYear();
|
||||||
|
|
||||||
|
await page.goto(`/school/${RC_URN}`);
|
||||||
|
const ofstedSection = page.locator('#ofsted');
|
||||||
|
// Detection fixed: rendered as a Report Card, not a legacy "Ofsted Rating".
|
||||||
|
await expect(ofstedSection.getByText('Ofsted Report Card')).toBeVisible({ timeout: 15_000 });
|
||||||
|
// Dating fixed: dated to the report-card inspection, never the legacy one.
|
||||||
|
await expect(ofstedSection.getByText(new RegExp(`Inspected .*${rcYear}`))).toBeVisible();
|
||||||
|
if (legacyYear !== rcYear) {
|
||||||
|
await expect(ofstedSection.getByText(new RegExp(`Inspected .*${legacyYear}`))).toHaveCount(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('an all-through school shows BOTH its KS2 SATs and its GCSE results, not just one phase', async ({ page }) => {
|
||||||
|
// All-through schools carry both KS2 and KS4 data in the same yearly rows.
|
||||||
|
// The detail view used to flip them to isSecondary and render GCSE-only,
|
||||||
|
// hiding the primary phase. It now renders both phases and labels the school
|
||||||
|
// "All-through".
|
||||||
|
const AT_URN = 137306; // Hessle High School and Penshurst Primary — all-through
|
||||||
|
const res = await page.request.get(`/api/schools/${AT_URN}`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
const detail = await res.json();
|
||||||
|
const rows: Array<{ rwm_expected_pct: number | null; attainment_8_score: number | null }> =
|
||||||
|
detail.yearly_data ?? [];
|
||||||
|
const hasKS2 = rows.some((r) => r.rwm_expected_pct != null);
|
||||||
|
const hasKS4 = rows.some((r) => r.attainment_8_score != null);
|
||||||
|
test.skip(
|
||||||
|
(detail.school_info?.phase ?? '').toLowerCase() !== 'all-through' || !hasKS2 || !hasKS4,
|
||||||
|
'precondition: chosen URN must currently be all-through with both KS2 and KS4 results',
|
||||||
|
);
|
||||||
|
|
||||||
|
await page.goto(`/school/${AT_URN}`);
|
||||||
|
await expect(page.locator('h1').first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
|
// Labelled as all-through in the hero meta.
|
||||||
|
await expect(page.getByText(/All-through/i).first()).toBeVisible();
|
||||||
|
|
||||||
|
// The combined results section carries both phases.
|
||||||
|
const results = page.locator('#results');
|
||||||
|
await expect(results.getByText(/SATs & GCSE Results/)).toBeVisible();
|
||||||
|
await expect(results.getByText('Reading, Writing & Maths combined')).toBeVisible(); // KS2
|
||||||
|
await expect(results.getByText('Attainment 8').first()).toBeVisible(); // KS4
|
||||||
|
});
|
||||||
|
|
||||||
test('school with no performance data still gets a working detail page', async ({ page }) => {
|
test('school with no performance data still gets a working detail page', async ({ page }) => {
|
||||||
// Schools without KS2/KS4 results (special post-16 institutions, sixth-form
|
// Schools without KS2/KS4 results (special post-16 institutions, sixth-form
|
||||||
// centres, PRUs) used to 500 in the API — NaN GIAS fields broke JSON
|
// centres, PRUs) used to 500 in the API — NaN GIAS fields broke JSON
|
||||||
@@ -139,19 +258,13 @@ test('results map fullscreen falls back to an overlay on iOS', async ({ page })
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('comparing two schools shows the parent-first sections side by side', async ({ page }) => {
|
test('comparing two schools shows the parent-first sections side by side', async ({ page }) => {
|
||||||
// Collect two school URNs from search results, then load the share URL
|
// Two same-phase (pure primary) schools so both stay on one tab.
|
||||||
await searchByName(page, 'primary');
|
const [urn0, urn1] = await twoPrimaryUrns(page);
|
||||||
await expect(schoolLinks(page).first()).toBeVisible({ timeout: 15_000 });
|
|
||||||
const hrefs = await schoolLinks(page).evaluateAll((links) =>
|
|
||||||
links.map((l) => (l as HTMLAnchorElement).getAttribute('href') || '')
|
|
||||||
);
|
|
||||||
const urns = [...new Set(hrefs.map((h) => h.match(/\/school\/(\d+)/)?.[1]).filter(Boolean))];
|
|
||||||
expect(urns.length).toBeGreaterThanOrEqual(2);
|
|
||||||
|
|
||||||
await page.goto(`/compare?urns=${urns[0]},${urns[1]}`);
|
await page.goto(`/compare?urns=${urn0},${urn1}`);
|
||||||
// Both schools' detail links should render in the comparison view
|
// Both schools' detail links should render in the comparison view
|
||||||
await expect(page.locator(`a[href*="${urns[0]}"]`).first()).toBeVisible({ timeout: 15_000 });
|
await expect(page.locator(`a[href*="${urn0}"]`).first()).toBeVisible({ timeout: 15_000 });
|
||||||
await expect(page.locator(`a[href*="${urns[1]}"]`).first()).toBeVisible();
|
await expect(page.locator(`a[href*="${urn1}"]`).first()).toBeVisible();
|
||||||
|
|
||||||
// The parent-first sections render in order (data-invariant: headings only)
|
// The parent-first sections render in order (data-invariant: headings only)
|
||||||
for (const heading of [
|
for (const heading of [
|
||||||
@@ -169,6 +282,16 @@ test('comparing two schools shows the parent-first sections side by side', async
|
|||||||
// Every number gets an anchor: at least one England-average tick or label
|
// Every number gets an anchor: at least one England-average tick or label
|
||||||
await expect(page.getByText(/England \d+/).first()).toBeVisible();
|
await expect(page.getByText(/England \d+/).first()).toBeVisible();
|
||||||
|
|
||||||
|
// Desktop: the sticky school bar shares the sections' grid template
|
||||||
|
// (200px label rail + one column per school) so chips align with the
|
||||||
|
// columns they label.
|
||||||
|
const barTemplate = await page
|
||||||
|
.locator('[aria-label="Schools in this comparison"]')
|
||||||
|
.evaluate((el) => getComputedStyle(el).gridTemplateColumns);
|
||||||
|
expect(barTemplate).toMatch(/^200px /);
|
||||||
|
// ...and its label rail carries the comparison caption.
|
||||||
|
await expect(page.getByText(/^\d+ (primary|secondary) schools?$/)).toBeVisible();
|
||||||
|
|
||||||
// Ofsted linkout goes to the school's provider page, never a report deep-link
|
// Ofsted linkout goes to the school's provider page, never a report deep-link
|
||||||
const ofstedLink = page.getByRole('link', { name: /Ofsted page/i }).first();
|
const ofstedLink = page.getByRole('link', { name: /Ofsted page/i }).first();
|
||||||
await expect(ofstedLink).toBeVisible();
|
await expect(ofstedLink).toBeVisible();
|
||||||
@@ -184,6 +307,53 @@ test('comparing two schools shows the parent-first sections side by side', async
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('comparing two secondary schools renders the secondary sections', async ({ page }) => {
|
||||||
|
const [urn0, urn1] = await twoSecondaryUrns(page);
|
||||||
|
|
||||||
|
await page.goto(`/compare?urns=${urn0},${urn1}`);
|
||||||
|
await expect(page.locator(`a[href*="${urn0}"]`).first()).toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
|
// The parent-first sections must render — this page was completely blank
|
||||||
|
// for all-secondary baskets (expert review must-fix #1).
|
||||||
|
await expect(page.getByRole('heading', { name: 'At a glance' }).first()).toBeVisible({
|
||||||
|
timeout: 15_000,
|
||||||
|
});
|
||||||
|
await expect(page.getByRole('heading', { name: 'Ofsted inspection' }).first()).toBeVisible();
|
||||||
|
// A KS4 measure proves the secondary academics variant rendered.
|
||||||
|
await expect(page.getByText(/Attainment 8/i).first()).toBeVisible();
|
||||||
|
await expect(page.getByText(/No primary schools in your comparison/)).toHaveCount(0);
|
||||||
|
|
||||||
|
// The admissions template must be phase-aware: the primaries' distance
|
||||||
|
// copy ("non-faith primaries") must never appear on a secondary comparison
|
||||||
|
// (expert sign-off must-fix M3).
|
||||||
|
await expect(page.getByText(/non-faith primaries/)).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('opening a different compare link after a previous comparison still renders', async ({ page }) => {
|
||||||
|
// Regression: the first visit stores a basket in localStorage; opening a
|
||||||
|
// link for a DIFFERENT school set then raced a stale fetch for the stored
|
||||||
|
// basket against the new SSR data, blanking every section (including the
|
||||||
|
// trends chart) until a hard refresh.
|
||||||
|
const [s0, s1] = await twoSecondaryUrns(page);
|
||||||
|
const [p0, p1] = await twoPrimaryUrns(page);
|
||||||
|
|
||||||
|
await page.goto(`/compare?urns=${s0},${s1}`);
|
||||||
|
await expect(page.getByRole('heading', { name: 'At a glance' }).first()).toBeVisible({
|
||||||
|
timeout: 15_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
await page.goto(`/compare?urns=${p0},${p1}`);
|
||||||
|
await expect(page.getByRole('heading', { name: 'At a glance' }).first()).toBeVisible({
|
||||||
|
timeout: 15_000,
|
||||||
|
});
|
||||||
|
// Give any straggling stale response time to land, then confirm the new
|
||||||
|
// comparison is still on screen.
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
await expect(page.getByRole('heading', { name: 'At a glance' }).first()).toBeVisible();
|
||||||
|
await expect(page.getByRole('heading', { name: 'Explore trends' }).first()).toBeVisible();
|
||||||
|
await expect(page.locator(`a[href*="${p0}"]`).first()).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
test('compare chart on mobile shows school chips with tap-to-focus', async ({ page }) => {
|
test('compare chart on mobile shows school chips with tap-to-focus', async ({ page }) => {
|
||||||
await page.setViewportSize({ width: 390, height: 844 });
|
await page.setViewportSize({ width: 390, height: 844 });
|
||||||
|
|
||||||
@@ -212,8 +382,26 @@ test('compare chart on mobile shows school chips with tap-to-focus', async ({ pa
|
|||||||
);
|
);
|
||||||
expect(bodyOverflowsX).toBe(false);
|
expect(bodyOverflowsX).toBe(false);
|
||||||
|
|
||||||
|
// The sticky school bar must pin *below* the sticky site header, not at
|
||||||
|
// top:0 where the header covers it and the selected schools are hidden.
|
||||||
|
// Assert the sticky offset directly (robust — no scroll timing needed).
|
||||||
|
const barTop = await page
|
||||||
|
.locator('[class*="schoolBar"]')
|
||||||
|
.first()
|
||||||
|
.evaluate((el) => parseFloat(getComputedStyle(el).top));
|
||||||
|
const headerHeight = await page
|
||||||
|
.locator('[class*="header"]')
|
||||||
|
.first()
|
||||||
|
.evaluate((el) => el.getBoundingClientRect().height);
|
||||||
|
expect(barTop).toBeGreaterThanOrEqual(headerHeight - 1);
|
||||||
|
|
||||||
// The trends chart still renders (inside the Explore trends section)…
|
// The trends chart still renders (inside the Explore trends section)…
|
||||||
await expect(page.locator('canvas:visible').first()).toBeVisible({ timeout: 15_000 });
|
const chartCanvas = page.locator('canvas:visible').first();
|
||||||
|
await expect(chartCanvas).toBeVisible({ timeout: 15_000 });
|
||||||
|
// …at a real height, not the squashed ~150px Chart.js fallback that
|
||||||
|
// appears when the container lacks a definite height.
|
||||||
|
const chartBox = await chartCanvas.boundingBox();
|
||||||
|
expect(chartBox && chartBox.height).toBeGreaterThan(220);
|
||||||
|
|
||||||
// …with the mobile chart legend chips and tap-to-focus behaviour intact.
|
// …with the mobile chart legend chips and tap-to-focus behaviour intact.
|
||||||
const chipGroup = page.getByRole('group', { name: /highlight a school/i });
|
const chipGroup = page.getByRole('group', { name: /highlight a school/i });
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* Secondary academics: every headline number carries its England anchor and a
|
||||||
|
* verdict chip (expert sign-off SF1 — the grade-5 and EBacc rows previously
|
||||||
|
* rendered as bare numbers, breaking the "anchored against England" promise).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { render, screen, within } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { CompareAcademics } from '@/components/compare/CompareAcademics';
|
||||||
|
import type { ComparisonData, NationalAverages, School } from '@/lib/types';
|
||||||
|
|
||||||
|
function school(urn: number, name: string): School {
|
||||||
|
return { urn, school_name: name, attainment_8_score: 58.7 } as School;
|
||||||
|
}
|
||||||
|
|
||||||
|
function data(urn: number): ComparisonData {
|
||||||
|
return {
|
||||||
|
school_info: school(urn, 'Test High'),
|
||||||
|
yearly_data: [
|
||||||
|
{
|
||||||
|
year: 202425,
|
||||||
|
attainment_8_score: 58.7,
|
||||||
|
english_maths_strong_pass_pct: 30,
|
||||||
|
ebacc_entry_pct: 10,
|
||||||
|
},
|
||||||
|
] as ComparisonData['yearly_data'],
|
||||||
|
ofsted: null,
|
||||||
|
census: null,
|
||||||
|
admissions: null,
|
||||||
|
admissions_history: [],
|
||||||
|
deprivation: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const NATIONAL: NationalAverages = {
|
||||||
|
year: 202425,
|
||||||
|
primary: {},
|
||||||
|
secondary: {
|
||||||
|
attainment_8_score: 46.0,
|
||||||
|
english_maths_strong_pass_pct: 45.4,
|
||||||
|
ebacc_entry_pct: 40.5,
|
||||||
|
},
|
||||||
|
by_year: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
test('grade-5 and EBacc rows show the England anchor and a Below chip when under it', () => {
|
||||||
|
const s = school(137086, 'Bishop Stopford School');
|
||||||
|
render(
|
||||||
|
<CompareAcademics
|
||||||
|
schools={[s]}
|
||||||
|
data={{ '137086': data(137086) }}
|
||||||
|
nationalAverages={NATIONAL}
|
||||||
|
isSecondary
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// The official anchors appear (45.4% and 40.5%), not just the school numbers.
|
||||||
|
expect(screen.getByText(/England average 45%/)).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/England average 41%/)).toBeInTheDocument();
|
||||||
|
|
||||||
|
// 30% grade-5 and 10% EBacc are both well below their anchors → Below chips.
|
||||||
|
// Attainment 8 (58.7 vs 46.0) is above → at least one "Above" chip too.
|
||||||
|
expect(screen.getAllByText(/Below England average/).length).toBeGreaterThanOrEqual(2);
|
||||||
|
expect(screen.getAllByText(/Above England average/).length).toBeGreaterThanOrEqual(1);
|
||||||
|
});
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/**
|
||||||
|
* Getting a place — phase and school-type correctness (expert sign-off
|
||||||
|
* must-fixes M1/M3):
|
||||||
|
* - an all-through school's Year 7 round must never render on the primary
|
||||||
|
* tab as if it were Reception odds;
|
||||||
|
* - selective schools get entrance-test framing, and the secondary tab
|
||||||
|
* never shows the primaries' distance template.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { CompareAdmissions } from '@/components/compare/CompareAdmissions';
|
||||||
|
import type { ComparisonData, School, SchoolAdmissions } from '@/lib/types';
|
||||||
|
|
||||||
|
function school(urn: number, name: string, extra: Partial<School> = {}): School {
|
||||||
|
return { urn, school_name: name, ...extra } as School;
|
||||||
|
}
|
||||||
|
|
||||||
|
function admissions(partial: Partial<SchoolAdmissions>): SchoolAdmissions {
|
||||||
|
return {
|
||||||
|
year: 202627,
|
||||||
|
school_phase: 'Secondary',
|
||||||
|
places_offered: 173,
|
||||||
|
total_applications: 433,
|
||||||
|
first_preference_offer_pct: 83,
|
||||||
|
oversubscribed: true,
|
||||||
|
...partial,
|
||||||
|
} as SchoolAdmissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function entry(info: School, a: SchoolAdmissions | null): ComparisonData {
|
||||||
|
return {
|
||||||
|
school_info: info,
|
||||||
|
yearly_data: [],
|
||||||
|
ofsted: null,
|
||||||
|
census: null,
|
||||||
|
admissions: a,
|
||||||
|
admissions_history: a ? [a] : [],
|
||||||
|
deprivation: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('CompareAdmissions', () => {
|
||||||
|
it("does not show an all-through school's Year 7 round on the primary tab", () => {
|
||||||
|
// The real M1 scenario: an all-through school (Year 7 round only) beside
|
||||||
|
// a primary with a Reception round.
|
||||||
|
const allThrough = school(137306, 'Hessle High and Penshurst Primary');
|
||||||
|
const primary = school(138690, 'Barclay Primary School');
|
||||||
|
const data = {
|
||||||
|
'137306': entry(allThrough, admissions({ school_phase: 'Secondary' })),
|
||||||
|
'138690': entry(
|
||||||
|
primary,
|
||||||
|
admissions({
|
||||||
|
school_phase: 'Primary',
|
||||||
|
total_applications: 300,
|
||||||
|
places_offered: 120,
|
||||||
|
first_preference_offer_pct: 96,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<CompareAdmissions schools={[allThrough, primary]} data={data} isSecondary={false} />);
|
||||||
|
|
||||||
|
// Hessle's Year 7 figures must not appear…
|
||||||
|
expect(screen.queryByText('433')).toBeNull();
|
||||||
|
expect(
|
||||||
|
screen.getByText(/We don't hold Reception admissions data for this school/),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
// …while Barclay's Reception round renders normally.
|
||||||
|
expect(screen.getByText('300')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('phase-labels the section empty state when no matching round exists at all', () => {
|
||||||
|
const allThrough = school(137306, 'Hessle High and Penshurst Primary');
|
||||||
|
const data = { '137306': entry(allThrough, admissions({ school_phase: 'Secondary' })) };
|
||||||
|
|
||||||
|
render(<CompareAdmissions schools={[allThrough]} data={data} isSecondary={false} />);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.getByText(/No Reception admissions data is available for these schools yet/),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText('433')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows the Year 7 round on the secondary tab', () => {
|
||||||
|
const allThrough = school(137306, 'Hessle High and Penshurst Primary');
|
||||||
|
const data = { '137306': entry(allThrough, admissions({ school_phase: 'Secondary' })) };
|
||||||
|
|
||||||
|
render(<CompareAdmissions schools={[allThrough]} data={data} isSecondary={true} />);
|
||||||
|
|
||||||
|
expect(screen.getByText('433')).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('173')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives selective schools entrance-test framing, never the distance template', () => {
|
||||||
|
const grammar = school(136276, 'Watford Grammar School for Boys', {
|
||||||
|
admissions_policy: 'Selective',
|
||||||
|
religious_denomination: 'Church of England',
|
||||||
|
});
|
||||||
|
const data = {
|
||||||
|
'136276': entry(grammar, admissions({ first_preference_offer_pct: 43.7 })),
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<CompareAdmissions schools={[grammar]} data={data} isSecondary={true} />);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
screen.getByText(/Entry is by entrance test — the school is selective/),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/non-faith primaries/)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('secondary faith school gets faith-aware copy, not the primaries template', () => {
|
||||||
|
const faithSchool = school(102052, "Bishop Stopford's School", {
|
||||||
|
admissions_policy: 'Non-selective',
|
||||||
|
religious_denomination: 'Church of England',
|
||||||
|
});
|
||||||
|
const data = {
|
||||||
|
'102052': entry(faithSchool, admissions({ first_preference_offer_pct: 68 })),
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<CompareAdmissions schools={[faithSchool]} data={data} isSecondary={true} />);
|
||||||
|
|
||||||
|
expect(screen.getByText(/faith-based criteria may apply/)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/non-faith primaries/)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the reviewed distance copy for oversubscribed non-faith primaries', () => {
|
||||||
|
const primary = school(100140, 'Plumcroft Primary School');
|
||||||
|
const data = {
|
||||||
|
'100140': entry(
|
||||||
|
primary,
|
||||||
|
admissions({ school_phase: 'Primary', first_preference_offer_pct: 73.4 }),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<CompareAdmissions schools={[primary]} data={data} isSecondary={false} />);
|
||||||
|
|
||||||
|
expect(screen.getByText(/for most non-faith primaries, distance decides/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -95,4 +95,76 @@ describe('CompareOfsted', () => {
|
|||||||
expect(links).toHaveLength(3);
|
expect(links).toHaveLength(3);
|
||||||
expect(links[0]).toHaveAttribute('href', 'https://reports.ofsted.gov.uk/provider/21/1');
|
expect(links[0]).toHaveAttribute('href', 'https://reports.ofsted.gov.uk/provider/21/1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('never renders Ofsted sentinel codes (9 = not applicable) as judgement chips', () => {
|
||||||
|
const sentinelSchool = school(6, 'Sentinel School');
|
||||||
|
const sentinelData: Record<string, ComparisonData> = {
|
||||||
|
'6': {
|
||||||
|
school_info: sentinelSchool,
|
||||||
|
yearly_data: [],
|
||||||
|
ofsted: ofsted({
|
||||||
|
overall_effectiveness: 2,
|
||||||
|
grade_source: 'graded',
|
||||||
|
quality_of_education: 1,
|
||||||
|
early_years_provision: 9,
|
||||||
|
sixth_form_provision: 2,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
render(<CompareOfsted schools={[sentinelSchool]} data={sentinelData} />);
|
||||||
|
// Real grades render…
|
||||||
|
expect(screen.getByText('Quality of education')).toBeInTheDocument();
|
||||||
|
// …the applicable sixth-form judgement renders (was previously dropped)…
|
||||||
|
expect(screen.getByText('Sixth form provision')).toBeInTheDocument();
|
||||||
|
// …and the not-applicable sentinel never appears, neither as area nor code.
|
||||||
|
expect(screen.queryByText('Early years provision')).toBeNull();
|
||||||
|
expect(screen.queryByText('9')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('dates a report card with the report-card inspection date, never the legacy date', () => {
|
||||||
|
const cardSchool = school(4, 'Dated Card School');
|
||||||
|
const cardData: Record<string, ComparisonData> = {
|
||||||
|
'4': {
|
||||||
|
school_info: cardSchool,
|
||||||
|
yearly_data: [],
|
||||||
|
ofsted: ofsted({
|
||||||
|
inspection_date: '2021-10-07',
|
||||||
|
rc_inspection_date: '2026-02-03',
|
||||||
|
rc_safeguarding_met: true,
|
||||||
|
report_card: { rc_achievement: { code: 1, label: 'Exceptional' } },
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
render(<CompareOfsted schools={[cardSchool]} data={cardData} />);
|
||||||
|
expect(screen.getByText(/3 Feb 2026/)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/7 Oct 2021/)).toBeNull();
|
||||||
|
expect(screen.queryByText('4+ years ago')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows an em dash when a report card has no rc_inspection_date yet', () => {
|
||||||
|
const cardSchool = school(5, 'Undated Card School');
|
||||||
|
const cardData: Record<string, ComparisonData> = {
|
||||||
|
'5': {
|
||||||
|
school_info: cardSchool,
|
||||||
|
yearly_data: [],
|
||||||
|
ofsted: ofsted({
|
||||||
|
inspection_date: '2021-10-07',
|
||||||
|
rc_inspection_date: null,
|
||||||
|
rc_safeguarding_met: true,
|
||||||
|
report_card: { rc_achievement: { code: 1, label: 'Exceptional' } },
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
render(<CompareOfsted schools={[cardSchool]} data={cardData} />);
|
||||||
|
expect(screen.getByText('—')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/7 Oct 2021/)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders a per-measure mobile tag with the short school name', () => {
|
||||||
|
render(<CompareOfsted schools={schools} data={data} />);
|
||||||
|
// Each measure repeats the schools, so the short name ("Graded" from
|
||||||
|
// "Graded School") appears once per measure (4) via the cell tag.
|
||||||
|
expect(screen.getAllByText('Graded').length).toBe(4);
|
||||||
|
expect(screen.getAllByText('Card').length).toBe(4);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
* Regression: an all-secondary comparison must render the secondary sections.
|
||||||
|
*
|
||||||
|
* The basket hydrates from the URL a beat after mount, so the auto-phase
|
||||||
|
* effect must re-run once selectedSchools arrives — with deps of only
|
||||||
|
* [comparisonData] it fired once against an empty basket, bailed, and the
|
||||||
|
* page stayed on an empty "primary" tab ("No primary schools in your
|
||||||
|
* comparison") even though all schools were secondary.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { render, screen, waitFor } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { ComparisonView } from '@/components/ComparisonView';
|
||||||
|
import { ComparisonProvider } from '@/context/ComparisonProvider';
|
||||||
|
import type { ComparisonData, School } from '@/lib/types';
|
||||||
|
|
||||||
|
const fetchComparison = jest.fn();
|
||||||
|
jest.mock('@/lib/api', () => ({
|
||||||
|
fetchComparison: (...args: unknown[]) => fetchComparison(...args),
|
||||||
|
}));
|
||||||
|
jest.mock('@/lib/analytics', () => ({ track: jest.fn() }));
|
||||||
|
|
||||||
|
function secondarySchool(urn: number, name: string): School {
|
||||||
|
return {
|
||||||
|
urn,
|
||||||
|
school_name: name,
|
||||||
|
local_authority: 'Testshire',
|
||||||
|
school_type: 'Academy converter',
|
||||||
|
attainment_8_score: 55,
|
||||||
|
phase: 'Secondary',
|
||||||
|
} as School;
|
||||||
|
}
|
||||||
|
|
||||||
|
function data(urn: number, name: string): ComparisonData {
|
||||||
|
return {
|
||||||
|
school_info: secondarySchool(urn, name),
|
||||||
|
yearly_data: [{ year: 202425, attainment_8_score: 55 }] as ComparisonData['yearly_data'],
|
||||||
|
ofsted: null,
|
||||||
|
census: null,
|
||||||
|
admissions: null,
|
||||||
|
admissions_history: [],
|
||||||
|
deprivation: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const INITIAL_DATA = {
|
||||||
|
'300': data(300, 'Gamma High'),
|
||||||
|
'400': data(400, 'Delta Academy'),
|
||||||
|
};
|
||||||
|
|
||||||
|
test('an all-secondary comparison renders the sections, not an empty primary tab', async () => {
|
||||||
|
render(
|
||||||
|
<ComparisonProvider>
|
||||||
|
<ComparisonView
|
||||||
|
initialData={INITIAL_DATA}
|
||||||
|
initialNationalAverages={{
|
||||||
|
year: 202425,
|
||||||
|
primary: {},
|
||||||
|
secondary: { attainment_8_score: 46 },
|
||||||
|
by_year: [],
|
||||||
|
}}
|
||||||
|
initialBenchmarks={undefined}
|
||||||
|
initialUrns={[300, 400]}
|
||||||
|
metrics={[]}
|
||||||
|
selectedMetric="attainment_8_score"
|
||||||
|
/>
|
||||||
|
</ComparisonProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByRole('heading', { name: 'At a glance' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
expect(screen.getAllByText('Gamma High').length).toBeGreaterThan(0);
|
||||||
|
expect(screen.queryByText(/No primary schools in your comparison/)).toBeNull();
|
||||||
|
// The sticky bar's rail caption reflects the active phase and count.
|
||||||
|
expect(screen.getByText('2 secondary schools')).toBeInTheDocument();
|
||||||
|
expect(fetchComparison).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
* Regression: opening a compare link while a DIFFERENT basket is stored must
|
||||||
|
* not blank the page.
|
||||||
|
*
|
||||||
|
* The basket hydrates from localStorage first, which can fire a fetch for the
|
||||||
|
* OLD school set; the URL-seed effect then replaces the basket with the URL's
|
||||||
|
* schools (already covered by SSR data, so no new fetch). When the stale
|
||||||
|
* response for the old set finally lands, it must not clobber the fresh SSR
|
||||||
|
* data — that left every section (including the trends chart) empty until a
|
||||||
|
* hard refresh.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { act, render, screen, waitFor } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { ComparisonView } from '@/components/ComparisonView';
|
||||||
|
import { ComparisonProvider } from '@/context/ComparisonProvider';
|
||||||
|
import type { ComparisonData, School } from '@/lib/types';
|
||||||
|
|
||||||
|
const fetchComparison = jest.fn();
|
||||||
|
jest.mock('@/lib/api', () => ({
|
||||||
|
fetchComparison: (...args: unknown[]) => fetchComparison(...args),
|
||||||
|
}));
|
||||||
|
jest.mock('@/lib/analytics', () => ({ track: jest.fn() }));
|
||||||
|
|
||||||
|
function school(urn: number, name: string): School {
|
||||||
|
return {
|
||||||
|
urn,
|
||||||
|
school_name: name,
|
||||||
|
local_authority: 'Testshire',
|
||||||
|
school_type: 'Community school',
|
||||||
|
rwm_expected_pct: 80,
|
||||||
|
phase: 'Primary',
|
||||||
|
} as School;
|
||||||
|
}
|
||||||
|
|
||||||
|
function data(urn: number, name: string): ComparisonData {
|
||||||
|
return {
|
||||||
|
school_info: school(urn, name),
|
||||||
|
yearly_data: [{ year: 202425, rwm_expected_pct: 80 }] as ComparisonData['yearly_data'],
|
||||||
|
ofsted: null,
|
||||||
|
census: null,
|
||||||
|
admissions: null,
|
||||||
|
admissions_history: [],
|
||||||
|
deprivation: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// The visitor's previously stored basket (a different school entirely).
|
||||||
|
const STORED_SCHOOL = school(900, 'Old Stored School');
|
||||||
|
|
||||||
|
// The comparison the URL (and SSR) actually asked for.
|
||||||
|
const URL_DATA = {
|
||||||
|
'100': data(100, 'Alpha Primary'),
|
||||||
|
'200': data(200, 'Beta Primary'),
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fetchComparison.mockReset();
|
||||||
|
localStorage.clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('a stale fetch for the previously stored basket does not clobber the URL comparison', async () => {
|
||||||
|
localStorage.setItem('selectedSchools', JSON.stringify([STORED_SCHOOL]));
|
||||||
|
|
||||||
|
const pending: Array<(v: unknown) => void> = [];
|
||||||
|
fetchComparison.mockImplementation(() => new Promise((resolve) => pending.push(resolve)));
|
||||||
|
|
||||||
|
render(
|
||||||
|
<ComparisonProvider>
|
||||||
|
<ComparisonView
|
||||||
|
initialData={URL_DATA}
|
||||||
|
initialNationalAverages={{
|
||||||
|
year: 202425,
|
||||||
|
primary: { rwm_expected_pct: 62 },
|
||||||
|
secondary: {},
|
||||||
|
by_year: [],
|
||||||
|
}}
|
||||||
|
initialBenchmarks={undefined}
|
||||||
|
initialUrns={[100, 200]}
|
||||||
|
metrics={[]}
|
||||||
|
selectedMetric="rwm_expected_pct"
|
||||||
|
/>
|
||||||
|
</ComparisonProvider>,
|
||||||
|
);
|
||||||
|
|
||||||
|
// The URL's schools render from SSR data once the basket is reseeded.
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByRole('heading', { name: 'At a glance' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
expect(screen.getAllByText('Alpha Primary').length).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
// The transient stored-basket fetch (for school 900) resolves LATE, after
|
||||||
|
// the basket has moved on to the URL's schools.
|
||||||
|
await act(async () => {
|
||||||
|
for (const resolve of pending) {
|
||||||
|
resolve({
|
||||||
|
comparison: { '900': data(900, 'Old Stored School') },
|
||||||
|
national_averages: { year: 202425, primary: {}, secondary: {}, by_year: [] },
|
||||||
|
benchmarks: undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// The page must still show the URL comparison — not go blank.
|
||||||
|
expect(screen.getByRole('heading', { name: 'At a glance' })).toBeInTheDocument();
|
||||||
|
expect(screen.getAllByText('Alpha Primary').length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
@@ -73,6 +73,15 @@ describe('buildCompareChart', () => {
|
|||||||
expect(eng.data[chart.years.indexOf(202122)]).toBe(58.7);
|
expect(eng.data[chart.years.indexOf(202122)]).toBe(58.7);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('lists England-only years so the component can caption dashed-only stretches', () => {
|
||||||
|
const chart = buildCompareChart(THREE_SCHOOLS, SCHOOL_LIST, 'rwm_expected_pct', {
|
||||||
|
202122: 58.7,
|
||||||
|
});
|
||||||
|
expect(chart.englandOnlyYears).toEqual([202122]);
|
||||||
|
const none = buildCompareChart(THREE_SCHOOLS, SCHOOL_LIST, 'rwm_expected_pct');
|
||||||
|
expect(none.englandOnlyYears).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
it('flags the unpublished 2021/22 school-level year when England has data but schools do not', () => {
|
it('flags the unpublished 2021/22 school-level year when England has data but schools do not', () => {
|
||||||
const withNational = buildCompareChart(THREE_SCHOOLS, SCHOOL_LIST, 'rwm_expected_pct', {
|
const withNational = buildCompareChart(THREE_SCHOOLS, SCHOOL_LIST, 'rwm_expected_pct', {
|
||||||
202122: 58.7,
|
202122: 58.7,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
OFSTED_LEGACY_GRADES,
|
OFSTED_LEGACY_GRADES,
|
||||||
|
admissionsForPhase,
|
||||||
ofstedDisplay,
|
ofstedDisplay,
|
||||||
progressBand,
|
progressBand,
|
||||||
rcAreaLabel,
|
rcAreaLabel,
|
||||||
@@ -126,6 +127,13 @@ describe('ofstedDisplay', () => {
|
|||||||
expect(ofstedDisplay(ofsted({})).kind).toBe('none');
|
expect(ofstedDisplay(ofsted({})).kind).toBe('none');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('identifies transitional inspections without overall grades', () => {
|
||||||
|
const transitional = ofstedDisplay(
|
||||||
|
ofsted({ overall_effectiveness: null, inspection_date: '2024-11-05' }),
|
||||||
|
);
|
||||||
|
expect(transitional.kind).toBe('transitional');
|
||||||
|
});
|
||||||
|
|
||||||
it('uses the four legacy grade words', () => {
|
it('uses the four legacy grade words', () => {
|
||||||
expect(OFSTED_LEGACY_GRADES).toEqual({
|
expect(OFSTED_LEGACY_GRADES).toEqual({
|
||||||
1: 'Outstanding',
|
1: 'Outstanding',
|
||||||
@@ -169,6 +177,16 @@ describe('summariseAdmissions', () => {
|
|||||||
expect(s.chip).toEqual({ tone: 'warn', text: 'Over 1 in 4 first choices missed out' });
|
expect(s.chip).toEqual({ tone: 'warn', text: 'Over 1 in 4 first choices missed out' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('60% → "About 1 in 3 first choices missed out"', () => {
|
||||||
|
const s = summariseAdmissions(admissions({ first_preference_offer_pct: 60 }));
|
||||||
|
expect(s.chip).toEqual({ tone: 'warn', text: 'About 1 in 3 first choices missed out' });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('44% (selective-scale demand) → "More than half of first choices missed out"', () => {
|
||||||
|
const s = summariseAdmissions(admissions({ first_preference_offer_pct: 43.69 }));
|
||||||
|
expect(s.chip).toEqual({ tone: 'warn', text: 'More than half of first choices missed out' });
|
||||||
|
});
|
||||||
|
|
||||||
it('100% → "All first choices offered"', () => {
|
it('100% → "All first choices offered"', () => {
|
||||||
const s = summariseAdmissions(admissions({ first_preference_offer_pct: 100 }));
|
const s = summariseAdmissions(admissions({ first_preference_offer_pct: 100 }));
|
||||||
expect(s.chip).toEqual({ tone: 'good', text: 'All first choices offered' });
|
expect(s.chip).toEqual({ tone: 'good', text: 'All first choices offered' });
|
||||||
@@ -181,6 +199,44 @@ describe('summariseAdmissions', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('admissionsForPhase', () => {
|
||||||
|
const row = (year: number, school_phase: string | null): SchoolAdmissions =>
|
||||||
|
({ year, school_phase, places_offered: 100, total_applications: 200, first_preference_offer_pct: 80 }) as SchoolAdmissions;
|
||||||
|
|
||||||
|
it('returns the latest round matching the active phase', () => {
|
||||||
|
const data = {
|
||||||
|
admissions: row(202627, 'Secondary'),
|
||||||
|
admissions_history: [row(202526, 'Secondary'), row(202526, 'Primary'), row(202425, 'Primary')],
|
||||||
|
};
|
||||||
|
expect(admissionsForPhase(data, true)?.year).toBe(202627);
|
||||||
|
expect(admissionsForPhase(data, false)?.year).toBe(202526);
|
||||||
|
expect(admissionsForPhase(data, false)?.school_phase).toBe('Primary');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("never substitutes the other phase's round (all-through with Year 7 data only)", () => {
|
||||||
|
const data = {
|
||||||
|
admissions: row(202627, 'Secondary'),
|
||||||
|
admissions_history: [row(202526, 'Secondary')],
|
||||||
|
};
|
||||||
|
expect(admissionsForPhase(data, false)).toBeNull();
|
||||||
|
expect(admissionsForPhase(data, true)?.year).toBe(202627);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses untagged legacy rows only when no row carries a phase', () => {
|
||||||
|
const untagged = { admissions: row(202627, null), admissions_history: [row(202526, null)] };
|
||||||
|
expect(admissionsForPhase(untagged, false)?.year).toBe(202627);
|
||||||
|
expect(admissionsForPhase(untagged, true)?.year).toBe(202627);
|
||||||
|
|
||||||
|
const mixed = { admissions: row(202627, 'Secondary'), admissions_history: [row(202526, null)] };
|
||||||
|
expect(admissionsForPhase(mixed, false)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles missing data', () => {
|
||||||
|
expect(admissionsForPhase(null, false)).toBeNull();
|
||||||
|
expect(admissionsForPhase({ admissions: null, admissions_history: [] }, true)).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('progressBand', () => {
|
describe('progressBand', () => {
|
||||||
it('CI entirely above zero → above', () => {
|
it('CI entirely above zero → above', () => {
|
||||||
expect(progressBand(1.2, 0.4, 2.0)).toBe('above');
|
expect(progressBand(1.2, 0.4, 2.0)).toBe('above');
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import {
|
|||||||
isValidPostcode,
|
isValidPostcode,
|
||||||
debounce,
|
debounce,
|
||||||
buildOfstedListBadge,
|
buildOfstedListBadge,
|
||||||
|
ofstedLegacyAreas,
|
||||||
metricKind,
|
metricKind,
|
||||||
|
shortName,
|
||||||
computeYBounds,
|
computeYBounds,
|
||||||
} from '@/lib/utils';
|
} from '@/lib/utils';
|
||||||
|
|
||||||
@@ -110,6 +112,35 @@ describe('debounce', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ofstedLegacyAreas', () => {
|
||||||
|
it('returns only real grades (1-4) and drops sentinel/null values', () => {
|
||||||
|
const areas = ofstedLegacyAreas({
|
||||||
|
quality_of_education: 1,
|
||||||
|
behaviour_attitudes: 2,
|
||||||
|
personal_development: null,
|
||||||
|
leadership_management: 9, // sentinel "not applicable" — must be dropped
|
||||||
|
early_years_provision: 9, // secondary school — not applicable
|
||||||
|
sixth_form_provision: 2,
|
||||||
|
});
|
||||||
|
expect(areas.map((a) => a.label)).toEqual([
|
||||||
|
'Quality of Teaching',
|
||||||
|
'Behaviour in School',
|
||||||
|
'Sixth Form',
|
||||||
|
]);
|
||||||
|
expect(areas.every((a) => a.value >= 1 && a.value <= 4)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes the sixth-form judgement where present (was previously dropped)', () => {
|
||||||
|
const areas = ofstedLegacyAreas({ sixth_form_provision: 1 });
|
||||||
|
expect(areas).toEqual([{ label: 'Sixth Form', value: 1 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('includes Early Years for a primary school', () => {
|
||||||
|
const areas = ofstedLegacyAreas({ quality_of_education: 2, early_years_provision: 1 });
|
||||||
|
expect(areas.map((a) => a.label)).toContain('Early Years (Reception)');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
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_date: '2023-11-15', ofsted_framework: 'OEIF' });
|
||||||
@@ -129,9 +160,23 @@ describe('buildOfstedListBadge', () => {
|
|||||||
expect(badge.cssClass).toBe('ofsted2');
|
expect(badge.cssClass).toBe('ofsted2');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns Report Card badge when framework is ReportCard', () => {
|
it('returns a Report Card badge when ofsted_rc_date is present', () => {
|
||||||
const badge = buildOfstedListBadge({ ofsted_grade: null, ofsted_date: '2025-11-01', ofsted_framework: 'ReportCard' });
|
const badge = buildOfstedListBadge({ ofsted_grade: null, ofsted_rc_date: '2026-02-03' });
|
||||||
expect(badge.label).toBe('Report Card · 2025');
|
expect(badge.label).toBe('Report Card · 2026');
|
||||||
|
expect(badge.cssClass).toBe('ofstedRc');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('a report card wins over a carried-forward legacy grade', () => {
|
||||||
|
// The production bug: a report-card school (e.g. Barclay) also carries a
|
||||||
|
// carried-forward legacy grade (ofsted_grade), which used to win and label
|
||||||
|
// the pin "Outstanding · 2021" instead of "Report Card · 2026".
|
||||||
|
const badge = buildOfstedListBadge({
|
||||||
|
ofsted_grade: 1,
|
||||||
|
ofsted_date: '2021-10-07',
|
||||||
|
ofsted_framework: 'Schools - S5',
|
||||||
|
ofsted_rc_date: '2026-02-03',
|
||||||
|
});
|
||||||
|
expect(badge.label).toBe('Report Card · 2026');
|
||||||
expect(badge.cssClass).toBe('ofstedRc');
|
expect(badge.cssClass).toBe('ofstedRc');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -223,3 +268,17 @@ describe('isProposedToClose', () => {
|
|||||||
expect(isProposedToClose({})).toBe(false);
|
expect(isProposedToClose({})).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('shortName', () => {
|
||||||
|
it('drops the trailing establishment-type words', () => {
|
||||||
|
expect(shortName('Barclay Primary School')).toBe('Barclay');
|
||||||
|
expect(shortName('Elmhurst Primary School')).toBe('Elmhurst');
|
||||||
|
expect(shortName("St Mary's Catholic Primary School")).toBe("St Mary's");
|
||||||
|
expect(shortName('Riverside Community Junior School')).toBe('Riverside');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps a name that carries no type suffix, capping very long ones', () => {
|
||||||
|
expect(shortName('Beaver Road')).toBe('Beaver Road');
|
||||||
|
expect(shortName('A'.repeat(30), 10)).toBe('AAAAAAAAA…');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -183,10 +183,15 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Secondary: teal outline — supporting actions (+ Compare) */
|
/* Secondary: teal outline — supporting actions (+ Compare) */
|
||||||
|
/* NOTE: a duplicate `.btn` block further down this file sets `border: none`,
|
||||||
|
which wins over the base `.btn`'s `1px solid transparent`. The outline
|
||||||
|
variants below therefore declare the full `border` shorthand explicitly so
|
||||||
|
they don't depend on the base border-width — otherwise `border-color` alone
|
||||||
|
has no width and the outline never renders (buttons read as plain text). */
|
||||||
.btn-secondary {
|
.btn-secondary {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: var(--accent-teal);
|
color: var(--accent-teal);
|
||||||
border-color: var(--accent-teal);
|
border: 1px solid var(--accent-teal);
|
||||||
}
|
}
|
||||||
.btn-secondary:hover:not(:disabled) {
|
.btn-secondary:hover:not(:disabled) {
|
||||||
background: var(--accent-teal-bg);
|
background: var(--accent-teal-bg);
|
||||||
@@ -196,7 +201,7 @@ body {
|
|||||||
.btn-tertiary {
|
.btn-tertiary {
|
||||||
background: var(--bg-secondary);
|
background: var(--bg-secondary);
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
border-color: var(--border-color);
|
border: 1px solid var(--border-color);
|
||||||
}
|
}
|
||||||
.btn-tertiary:hover:not(:disabled) {
|
.btn-tertiary:hover:not(:disabled) {
|
||||||
background: var(--border-color);
|
background: var(--border-color);
|
||||||
@@ -207,7 +212,7 @@ body {
|
|||||||
.btn-active {
|
.btn-active {
|
||||||
background: var(--accent-teal-bg);
|
background: var(--accent-teal-bg);
|
||||||
color: var(--accent-teal);
|
color: var(--accent-teal);
|
||||||
border-color: var(--accent-teal);
|
border: 1px solid var(--accent-teal);
|
||||||
}
|
}
|
||||||
.btn-active:hover:not(:disabled) {
|
.btn-active:hover:not(:disabled) {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Line } from 'react-chartjs-2';
|
|||||||
import { ChartOptions } from 'chart.js';
|
import { ChartOptions } from 'chart.js';
|
||||||
import '@/lib/chartSetup';
|
import '@/lib/chartSetup';
|
||||||
import { formatAcademicYear } from '@/lib/utils';
|
import { formatAcademicYear } from '@/lib/utils';
|
||||||
|
import { fillAcademicYears } from '@/lib/compareChartData';
|
||||||
import type { SchoolAdmissions } from '@/lib/types';
|
import type { SchoolAdmissions } from '@/lib/types';
|
||||||
import styles from './AdmissionsTrendChart.module.css';
|
import styles from './AdmissionsTrendChart.module.css';
|
||||||
|
|
||||||
@@ -17,13 +18,22 @@ export default function AdmissionsTrendChart({ history }: { history: SchoolAdmis
|
|||||||
const pts = history.filter((h) => h.first_preference_offer_pct != null);
|
const pts = history.filter((h) => h.first_preference_offer_pct != null);
|
||||||
if (pts.length < 2) return null;
|
if (pts.length < 2) return null;
|
||||||
|
|
||||||
const labels = pts.map((p) => formatAcademicYear(p.year));
|
// Gap-honest axis: every academic year between the first and last data point
|
||||||
const values = pts.map((p) => p.first_preference_offer_pct as number);
|
// appears, so a missing admissions year renders as a real gap (spanGaps:false)
|
||||||
const lastIdx = pts.length - 1;
|
// rather than compressing time between distant years.
|
||||||
|
const axisYears = fillAcademicYears(pts.map((p) => p.year));
|
||||||
|
const byYear = new Map(pts.map((p) => [p.year, p.first_preference_offer_pct as number]));
|
||||||
|
const labels = axisYears.map(formatAcademicYear);
|
||||||
|
const values: (number | null)[] = axisYears.map((y) => byYear.get(y) ?? null);
|
||||||
|
const present = values
|
||||||
|
.map((v, i) => (v != null ? i : -1))
|
||||||
|
.filter((i) => i >= 0);
|
||||||
|
const lastIdx = present[present.length - 1];
|
||||||
|
|
||||||
// Auto-scale with headroom so variation is visible, clamped to 0–100.
|
// Auto-scale with headroom so variation is visible, clamped to 0–100.
|
||||||
const lo = Math.min(...values);
|
const numeric = values.filter((v): v is number => v != null);
|
||||||
const hi = Math.max(...values);
|
const lo = Math.min(...numeric);
|
||||||
|
const hi = Math.max(...numeric);
|
||||||
const padded = Math.max(5, Math.round((hi - lo) * 0.25));
|
const padded = Math.max(5, Math.round((hi - lo) * 0.25));
|
||||||
const yMin = Math.max(0, Math.floor((lo - padded) / 5) * 5);
|
const yMin = Math.max(0, Math.floor((lo - padded) / 5) * 5);
|
||||||
const yMax = Math.min(100, Math.ceil((hi + padded) / 5) * 5);
|
const yMax = Math.min(100, Math.ceil((hi + padded) / 5) * 5);
|
||||||
@@ -69,15 +79,16 @@ export default function AdmissionsTrendChart({ history }: { history: SchoolAdmis
|
|||||||
label: 'First-choice offer rate',
|
label: 'First-choice offer rate',
|
||||||
data: values,
|
data: values,
|
||||||
clip: false as const,
|
clip: false as const,
|
||||||
|
spanGaps: false,
|
||||||
borderColor: '#e07256',
|
borderColor: '#e07256',
|
||||||
backgroundColor: 'rgba(224,114,86,0.10)',
|
backgroundColor: 'rgba(224,114,86,0.10)',
|
||||||
borderWidth: 2.5,
|
borderWidth: 2.5,
|
||||||
tension: 0.3,
|
tension: 0.3,
|
||||||
fill: true,
|
fill: true,
|
||||||
pointRadius: pts.map((_, i) => (i === lastIdx ? 5 : 3)),
|
pointRadius: values.map((_, i) => (i === lastIdx ? 5 : 3)),
|
||||||
pointBackgroundColor: '#e07256',
|
pointBackgroundColor: '#e07256',
|
||||||
pointBorderColor: '#fff',
|
pointBorderColor: '#fff',
|
||||||
pointBorderWidth: pts.map((_, i) => (i === lastIdx ? 2 : 0)),
|
pointBorderWidth: values.map((_, i) => (i === lastIdx ? 2 : 0)),
|
||||||
pointHoverRadius: 6,
|
pointHoverRadius: 6,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
/* Chart wrapper: chips (mobile) above, canvas filling the rest of the
|
/* Chart wrapper: chips (mobile) above, then the canvas, then the gap note.
|
||||||
parent .chartContainer, whose fixed height drives Chart.js sizing via
|
The canvas has its OWN definite height (Chart.js needs one for
|
||||||
maintainAspectRatio: false. */
|
maintainAspectRatio: false); the chips and the note flow at their natural
|
||||||
|
size around it rather than competing with it for a fixed outer height —
|
||||||
|
so a longer note (e.g. the KS4 gap caption) or a two-row chip legend can
|
||||||
|
never squash the chart. */
|
||||||
.wrapper {
|
.wrapper {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
height: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.canvasBox {
|
.canvasBox {
|
||||||
position: relative;
|
position: relative;
|
||||||
flex: 1 1 auto;
|
height: 380px;
|
||||||
min-height: 0;
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.canvasBox {
|
||||||
|
height: 280px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* School chips: mobile-only legend + tap-to-focus control. Desktop keeps
|
/* School chips: mobile-only legend + tap-to-focus control. Desktop keeps
|
||||||
|
|||||||
@@ -38,13 +38,15 @@ interface ComparisonChartProps {
|
|||||||
/** Official England figure per academic year for this metric — renders a
|
/** Official England figure per academic year for this metric — renders a
|
||||||
* dashed grey reference line when provided. */
|
* dashed grey reference line when provided. */
|
||||||
nationalByYear?: Record<number, number | null | undefined>;
|
nationalByYear?: Record<number, number | null | undefined>;
|
||||||
|
/** KS4 metrics get a different (honest) gap caption than KS2. */
|
||||||
|
isSecondary?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// One shape per basket slot (MAX_SCHOOLS = 5) — secondary encoding so
|
// One shape per basket slot (MAX_SCHOOLS = 5) — secondary encoding so
|
||||||
// converging lines stay tellable apart without relying on hue alone.
|
// converging lines stay tellable apart without relying on hue alone.
|
||||||
const POINT_STYLES: PointStyle[] = ['circle', 'triangle', 'rect', 'rectRot', 'star'];
|
const POINT_STYLES: PointStyle[] = ['circle', 'triangle', 'rect', 'rectRot', 'star'];
|
||||||
|
|
||||||
export function ComparisonChart({ comparisonData, schools, metric, metricLabel, nationalByYear }: ComparisonChartProps) {
|
export function ComparisonChart({ comparisonData, schools, metric, metricLabel, nationalByYear, isSecondary = false }: ComparisonChartProps) {
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
const [focusedUrn, setFocusedUrn] = useState<number | null>(null);
|
const [focusedUrn, setFocusedUrn] = useState<number | null>(null);
|
||||||
|
|
||||||
@@ -168,7 +170,7 @@ export function ComparisonChart({ comparisonData, schools, metric, metricLabel,
|
|||||||
display: true,
|
display: true,
|
||||||
title: {
|
title: {
|
||||||
display: !isMobile,
|
display: !isMobile,
|
||||||
text: kind === 'percentage' ? 'Percentage (%)' : kind === 'progress' ? 'Progress Score' : 'Value',
|
text: kind === 'percentage' ? 'Percentage (%)' : kind === 'progress' ? 'Progress Score' : 'Score',
|
||||||
font: {
|
font: {
|
||||||
size: 12,
|
size: 12,
|
||||||
weight: 'bold',
|
weight: 'bold',
|
||||||
@@ -240,11 +242,23 @@ export function ComparisonChart({ comparisonData, schools, metric, metricLabel,
|
|||||||
<div className={styles.canvasBox}>
|
<div className={styles.canvasBox}>
|
||||||
<Line data={chartData} options={options} aria-label={`${metricLabel} comparison chart`} />
|
<Line data={chartData} options={options} aria-label={`${metricLabel} comparison chart`} />
|
||||||
</div>
|
</div>
|
||||||
{built.showUnpublished202122Note && (
|
{isSecondary && built.englandOnlyYears.length > 0 ? (
|
||||||
|
// KS4's honest story differs from KS2's: 2019/20–2020/21 school-level
|
||||||
|
// GCSE results weren't published (COVID grading); later years WERE
|
||||||
|
// published by DfE but aren't in our dataset yet.
|
||||||
<p className={styles.chartNote}>
|
<p className={styles.chartNote}>
|
||||||
No national tests were held in 2019/20 and 2020/21 (COVID), and DfE didn't publish
|
School-level GCSE figures for 2019/20 and 2020/21 weren't published (COVID
|
||||||
school-level figures for 2021/22 — the England average is shown for that year.
|
grading), and more recent years aren't in our dataset yet where lines break — the
|
||||||
|
England average is shown where available.
|
||||||
</p>
|
</p>
|
||||||
|
) : (
|
||||||
|
!isSecondary &&
|
||||||
|
built.showUnpublished202122Note && (
|
||||||
|
<p className={styles.chartNote}>
|
||||||
|
No national tests were held in 2019/20 and 2020/21 (COVID), and DfE didn't publish
|
||||||
|
school-level figures for 2021/22 — the England average is shown for that year.
|
||||||
|
</p>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -80,10 +80,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Sticky school bar — column identity while scrolling; horizontal scroll on
|
/* Sticky school bar — column identity while scrolling; horizontal scroll on
|
||||||
narrow screens */
|
narrow screens. Offset by the sticky site header's height (Navigation is
|
||||||
|
position: sticky, top: 0) so this bar pins just below it instead of
|
||||||
|
sliding underneath and being hidden. Header ≈ 65px desktop / 57px mobile. */
|
||||||
.schoolBar {
|
.schoolBar {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 65px;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
background: var(--bg-primary, #faf7f2);
|
background: var(--bg-primary, #faf7f2);
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -132,6 +134,11 @@
|
|||||||
color: var(--accent-coral-dark, #b04a2e);
|
color: var(--accent-coral-dark, #b04a2e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Full name on desktop, short name on the compact mobile pills. */
|
||||||
|
.chipNameShort {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.chipMeta {
|
.chipMeta {
|
||||||
display: block;
|
display: block;
|
||||||
font-size: 0.78rem;
|
font-size: 0.78rem;
|
||||||
@@ -141,6 +148,54 @@
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Caption filling the label rail on desktop ("Comparing / 3 primary
|
||||||
|
schools"). Hidden on mobile, where the bar is a row of compact pills. */
|
||||||
|
.barCaption {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Desktop (matches the sections' 761px breakpoint): the bar adopts the same
|
||||||
|
grid template as compareSections' .grid — a 200px row-label rail plus one
|
||||||
|
column per school — so each chip sits exactly over the column it labels.
|
||||||
|
The caption occupies the rail; chips flow into the school columns. */
|
||||||
|
@media (min-width: 761px) {
|
||||||
|
.schoolBar {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 200px repeat(var(--school-count, 3), 1fr);
|
||||||
|
gap: 0 0.75rem;
|
||||||
|
overflow-x: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.schoolChip {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.barCaption {
|
||||||
|
grid-column: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.1rem;
|
||||||
|
padding-right: 0.5rem;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.barCaptionEyebrow {
|
||||||
|
font-size: 0.72rem;
|
||||||
|
font-weight: 600;
|
||||||
|
letter-spacing: 0.06em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
color: var(--text-muted, #6d685f);
|
||||||
|
}
|
||||||
|
|
||||||
|
.barCaptionCount {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.3;
|
||||||
|
color: var(--text-primary, #1a1612);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.chipRemove {
|
.chipRemove {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
border: none;
|
border: none;
|
||||||
@@ -163,3 +218,45 @@
|
|||||||
padding-top: 1rem;
|
padding-top: 1rem;
|
||||||
max-width: 75ch;
|
max-width: 75ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Mobile: the sticky school bar becomes compact, horizontally-scrollable
|
||||||
|
pills with short names (matching the mobile mockup) instead of full-width
|
||||||
|
cards whose names wrap to several lines. */
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
/* The mobile Navigation header is shorter (≈57px). */
|
||||||
|
.schoolBar {
|
||||||
|
top: 57px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.schoolChip {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
min-width: 0;
|
||||||
|
border-top-width: 2px;
|
||||||
|
border-radius: 999px;
|
||||||
|
padding: 0.35rem 0.7rem;
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chipName {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chipNameFull {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chipNameShort {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chipMeta {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chipRemove {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState, type CSSProperties } from 'react';
|
||||||
import { useRouter, usePathname, useSearchParams } from 'next/navigation';
|
import { useRouter, usePathname, useSearchParams } from 'next/navigation';
|
||||||
import { useComparison } from '@/hooks/useComparison';
|
import { useComparison } from '@/hooks/useComparison';
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ import type {
|
|||||||
NationalAverages,
|
NationalAverages,
|
||||||
School,
|
School,
|
||||||
} from '@/lib/types';
|
} from '@/lib/types';
|
||||||
import { CHART_COLORS, schoolUrl } from '@/lib/utils';
|
import { CHART_COLORS, schoolUrl, shortName } from '@/lib/utils';
|
||||||
import { fetchComparison } from '@/lib/api';
|
import { fetchComparison } from '@/lib/api';
|
||||||
import { track } from '@/lib/analytics';
|
import { track } from '@/lib/analytics';
|
||||||
import styles from './ComparisonView.module.css';
|
import styles from './ComparisonView.module.css';
|
||||||
@@ -85,7 +85,9 @@ export function ComparisonView({
|
|||||||
replaceSchools(urlSchools);
|
replaceSchools(urlSchools);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [isInitialized]); // eslint-disable-line react-hooks/exhaustive-deps
|
// Re-seed when a client-side navigation lands on a different ?urns= set
|
||||||
|
// (initialUrns/initialData are new props on the same component instance).
|
||||||
|
}, [isInitialized, initialUrns.join(',')]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const urnKey = selectedSchools.map((s) => s.urn).join(',');
|
const urnKey = selectedSchools.map((s) => s.urn).join(',');
|
||||||
|
|
||||||
@@ -128,8 +130,18 @@ export function ComparisonView({
|
|||||||
const covered = urnKey.split(',').every((urn) => have[urn] != null);
|
const covered = urnKey.split(',').every((urn) => have[urn] != null);
|
||||||
if (covered) return;
|
if (covered) return;
|
||||||
|
|
||||||
|
// Guard against out-of-order responses: while the basket hydrates from
|
||||||
|
// localStorage it can transiently hold a DIFFERENT school set than the
|
||||||
|
// URL, firing a fetch for schools the user is no longer comparing. That
|
||||||
|
// stale response must not replace data for the current set — it blanked
|
||||||
|
// every section until a hard refresh. Cleanup marks the run cancelled
|
||||||
|
// when urnKey moves on, so only the current selection's response is
|
||||||
|
// applied (replacing the map keeps it bounded and guarantees a re-added
|
||||||
|
// school is refetched fresh rather than served a lingering old entry).
|
||||||
|
let cancelled = false;
|
||||||
fetchComparison(urnKey, { cache: 'no-store' })
|
fetchComparison(urnKey, { cache: 'no-store' })
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
if (cancelled) return;
|
||||||
setComparisonData(data.comparison);
|
setComparisonData(data.comparison);
|
||||||
setNationalAverages(data.national_averages);
|
setNationalAverages(data.national_averages);
|
||||||
setBenchmarks(data.benchmarks);
|
setBenchmarks(data.benchmarks);
|
||||||
@@ -140,21 +152,28 @@ export function ComparisonView({
|
|||||||
// destroy a working comparison the user is looking at.
|
// destroy a working comparison the user is looking at.
|
||||||
console.error('Failed to fetch comparison:', err);
|
console.error('Failed to fetch comparison:', err);
|
||||||
});
|
});
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
}, [urnKey, isInitialized]);
|
}, [urnKey, isInitialized]);
|
||||||
|
|
||||||
// Classify schools by phase using comparison data
|
const primarySchools = selectedSchools.filter((school) => {
|
||||||
const classifySchool = (school: School): 'primary' | 'secondary' => {
|
|
||||||
const info = comparisonData?.[school.urn]?.school_info;
|
const info = comparisonData?.[school.urn]?.school_info;
|
||||||
if (info?.attainment_8_score != null) return 'secondary';
|
const hasPrimaryData =
|
||||||
if (info?.rwm_expected_pct != null) return 'primary';
|
info?.rwm_expected_pct != null ||
|
||||||
// Fallback: check yearly data
|
comparisonData?.[school.urn]?.yearly_data?.some((d) => d.rwm_expected_pct != null);
|
||||||
const yearlyData = comparisonData?.[school.urn]?.yearly_data;
|
if (hasPrimaryData) return true;
|
||||||
if (yearlyData?.some((d) => d.attainment_8_score != null)) return 'secondary';
|
return school.phase?.toLowerCase().includes('primary') || false;
|
||||||
return 'primary';
|
});
|
||||||
};
|
|
||||||
|
|
||||||
const primarySchools = selectedSchools.filter((s) => classifySchool(s) === 'primary');
|
const secondarySchools = selectedSchools.filter((school) => {
|
||||||
const secondarySchools = selectedSchools.filter((s) => classifySchool(s) === 'secondary');
|
const info = comparisonData?.[school.urn]?.school_info;
|
||||||
|
const hasSecondaryData =
|
||||||
|
info?.attainment_8_score != null ||
|
||||||
|
comparisonData?.[school.urn]?.yearly_data?.some((d) => d.attainment_8_score != null);
|
||||||
|
if (hasSecondaryData) return true;
|
||||||
|
return school.phase?.toLowerCase().includes('secondary') || false;
|
||||||
|
});
|
||||||
|
|
||||||
// Auto-select tab with more schools and sync the metric to match the phase.
|
// Auto-select tab with more schools and sync the metric to match the phase.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -169,7 +188,11 @@ export function ComparisonView({
|
|||||||
if (!metricFitsPhase) {
|
if (!metricFitsPhase) {
|
||||||
setSelectedMetric(newPhase === 'secondary' ? 'attainment_8_score' : 'rwm_expected_pct');
|
setSelectedMetric(newPhase === 'secondary' ? 'attainment_8_score' : 'rwm_expected_pct');
|
||||||
}
|
}
|
||||||
}, [comparisonData]); // eslint-disable-line react-hooks/exhaustive-deps
|
// selectedSchools is a dep because the basket hydrates after mount: the
|
||||||
|
// first run sees an empty basket and bails, so it must re-fire when the
|
||||||
|
// schools arrive. primarySchools/secondarySchools/metrics/selectedMetric
|
||||||
|
// are intentionally omitted (derived or would cause loops).
|
||||||
|
}, [comparisonData, selectedSchools]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const handlePhaseChange = (phase: 'primary' | 'secondary') => {
|
const handlePhaseChange = (phase: 'primary' | 'secondary') => {
|
||||||
phaseLockedByUser.current = true;
|
phaseLockedByUser.current = true;
|
||||||
@@ -334,8 +357,28 @@ export function ComparisonView({
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{/* Sticky school bar — column identity while scrolling */}
|
{/* Sticky school bar — column identity while scrolling. On desktop
|
||||||
<div className={styles.schoolBar} aria-label="Schools in this comparison">
|
it shares the sections' grid template (via --school-count) so
|
||||||
|
each chip sits exactly over the column it labels. */}
|
||||||
|
<div
|
||||||
|
className={styles.schoolBar}
|
||||||
|
style={{ '--school-count': activeSchools.length } as CSSProperties}
|
||||||
|
aria-label="Schools in this comparison"
|
||||||
|
>
|
||||||
|
{/* Fills the 200px label rail on desktop (hidden on mobile).
|
||||||
|
All-through schools must not be miscounted as "primary
|
||||||
|
schools"/"secondary schools" — mixed baskets get "· primary
|
||||||
|
view" phrasing instead. */}
|
||||||
|
<div className={styles.barCaption}>
|
||||||
|
<span className={styles.barCaptionEyebrow}>Comparing</span>
|
||||||
|
<span className={styles.barCaptionCount}>
|
||||||
|
{activeSchools.every((sch) =>
|
||||||
|
sch.phase?.toLowerCase().includes(comparePhase),
|
||||||
|
)
|
||||||
|
? `${activeSchools.length} ${comparePhase} school${activeSchools.length === 1 ? '' : 's'}`
|
||||||
|
: `${activeSchools.length} schools · ${comparePhase} view`}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
{activeSchools.map((school, index) => (
|
{activeSchools.map((school, index) => (
|
||||||
<div
|
<div
|
||||||
key={school.urn}
|
key={school.urn}
|
||||||
@@ -349,10 +392,17 @@ export function ComparisonView({
|
|||||||
/>
|
/>
|
||||||
<span className={styles.chipText}>
|
<span className={styles.chipText}>
|
||||||
<a className={styles.chipName} href={schoolUrl(school.urn, school.school_name)}>
|
<a className={styles.chipName} href={schoolUrl(school.urn, school.school_name)}>
|
||||||
{school.school_name}
|
<span className={styles.chipNameFull}>{school.school_name}</span>
|
||||||
|
<span className={styles.chipNameShort}>{shortName(school.school_name)}</span>
|
||||||
</a>
|
</a>
|
||||||
<span className={styles.chipMeta}>
|
<span className={styles.chipMeta}>
|
||||||
{[school.local_authority, school.school_type].filter(Boolean).join(' · ')}
|
{[
|
||||||
|
/all.?through/i.test(school.phase ?? '') ? 'All-through' : null,
|
||||||
|
school.local_authority,
|
||||||
|
school.school_type,
|
||||||
|
]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' · ')}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<button
|
<button
|
||||||
@@ -374,6 +424,7 @@ export function ComparisonView({
|
|||||||
data={activeComparisonData}
|
data={activeComparisonData}
|
||||||
nationalAverages={nationalAverages}
|
nationalAverages={nationalAverages}
|
||||||
benchmarks={benchmarks}
|
benchmarks={benchmarks}
|
||||||
|
isSecondary={!isPrimary}
|
||||||
/>
|
/>
|
||||||
<CompareOfsted schools={activeSchools} data={activeComparisonData} />
|
<CompareOfsted schools={activeSchools} data={activeComparisonData} />
|
||||||
<CompareAcademics
|
<CompareAcademics
|
||||||
@@ -381,12 +432,18 @@ export function ComparisonView({
|
|||||||
data={activeComparisonData}
|
data={activeComparisonData}
|
||||||
nationalAverages={nationalAverages}
|
nationalAverages={nationalAverages}
|
||||||
benchmarks={benchmarks}
|
benchmarks={benchmarks}
|
||||||
|
isSecondary={!isPrimary}
|
||||||
|
/>
|
||||||
|
<CompareAdmissions
|
||||||
|
schools={activeSchools}
|
||||||
|
data={activeComparisonData}
|
||||||
|
isSecondary={!isPrimary}
|
||||||
/>
|
/>
|
||||||
<CompareAdmissions schools={activeSchools} data={activeComparisonData} />
|
|
||||||
<CompareCommunity
|
<CompareCommunity
|
||||||
schools={activeSchools}
|
schools={activeSchools}
|
||||||
data={activeComparisonData}
|
data={activeComparisonData}
|
||||||
benchmarks={benchmarks}
|
benchmarks={benchmarks}
|
||||||
|
isSecondary={!isPrimary}
|
||||||
/>
|
/>
|
||||||
<TrendsExplorer
|
<TrendsExplorer
|
||||||
schools={activeSchools}
|
schools={activeSchools}
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ interface PopupBadge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildPopupBadge(school: School): PopupBadge {
|
function buildPopupBadge(school: School): PopupBadge {
|
||||||
|
// A report card wins over any carried-forward legacy grade — its presence is
|
||||||
|
// signalled by ofsted_rc_date (the list has no full report_card object, and
|
||||||
|
// ofsted_framework is the raw event grouping, never "ReportCard").
|
||||||
|
if (school.ofsted_rc_date) {
|
||||||
|
const rcYear = new Date(school.ofsted_rc_date).getFullYear();
|
||||||
|
return { label: `Report Card · ${rcYear}`, style: 'background:#5a3a6e;color:#fff' };
|
||||||
|
}
|
||||||
const year = school.ofsted_date ? new Date(school.ofsted_date).getFullYear() : null;
|
const year = school.ofsted_date ? new Date(school.ofsted_date).getFullYear() : null;
|
||||||
const yearStr = year ? ` · ${year}` : '';
|
const yearStr = year ? ` · ${year}` : '';
|
||||||
if (school.ofsted_grade) {
|
if (school.ofsted_grade) {
|
||||||
@@ -55,9 +62,6 @@ function buildPopupBadge(school: School): PopupBadge {
|
|||||||
};
|
};
|
||||||
return { label: `${labels[school.ofsted_grade]}${yearStr}`, style: colours[school.ofsted_grade] };
|
return { label: `${labels[school.ofsted_grade]}${yearStr}`, style: colours[school.ofsted_grade] };
|
||||||
}
|
}
|
||||||
if (school.ofsted_framework === 'ReportCard') {
|
|
||||||
return { label: `Report Card${yearStr}`, style: 'background:#5a3a6e;color:#fff' };
|
|
||||||
}
|
|
||||||
return { label: 'Not yet inspected', style: 'background:#e0e0e0;color:#666' };
|
return { label: 'Not yet inspected', style: 'background:#e0e0e0;color:#666' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,13 @@
|
|||||||
.modal {
|
.modal {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
max-height: 95vh;
|
/* Bottom sheet sized against the overlay (which tracks the visual
|
||||||
|
viewport), NOT vh: when the keyboard is open the overlay is short, so
|
||||||
|
max-height:100% keeps the whole sheet — input and results — above the
|
||||||
|
keyboard. min-height gives a comfortable default without a tiny stub,
|
||||||
|
but is capped at 100% so it never exceeds the visible area. */
|
||||||
|
min-height: min(55vh, 100%);
|
||||||
|
max-height: 100%;
|
||||||
border-bottom-left-radius: 0;
|
border-bottom-left-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
animation: slideUp 0.3s ease;
|
animation: slideUp 0.3s ease;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useCallback } from 'react';
|
import { useEffect, useCallback, useRef } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
import styles from './Modal.module.css';
|
import styles from './Modal.module.css';
|
||||||
|
|
||||||
@@ -18,6 +18,8 @@ interface ModalProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Modal({ isOpen, onClose, children, title, size = 'medium' }: ModalProps) {
|
export function Modal({ isOpen, onClose, children, title, size = 'medium' }: ModalProps) {
|
||||||
|
const overlayRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const handleEscape = useCallback((e: KeyboardEvent) => {
|
const handleEscape = useCallback((e: KeyboardEvent) => {
|
||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
onClose();
|
onClose();
|
||||||
@@ -39,6 +41,32 @@ export function Modal({ isOpen, onClose, children, title, size = 'medium' }: Mod
|
|||||||
};
|
};
|
||||||
}, [isOpen, handleEscape]);
|
}, [isOpen, handleEscape]);
|
||||||
|
|
||||||
|
// Pin the overlay to the VISUAL viewport, not the layout viewport. On mobile
|
||||||
|
// the on-screen keyboard shrinks the visual viewport but not the layout one,
|
||||||
|
// so a `position: fixed; inset: 0` overlay keeps full height — leaving the
|
||||||
|
// bottom-anchored sheet (and the dim backdrop's lower half) hidden behind
|
||||||
|
// the keyboard. Tracking visualViewport.height/offsetTop keeps the whole
|
||||||
|
// overlay — backdrop and sheet — inside the visible area, above the keyboard.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isOpen) return;
|
||||||
|
const vv = typeof window !== 'undefined' ? window.visualViewport : null;
|
||||||
|
const el = overlayRef.current;
|
||||||
|
if (!vv || !el) return;
|
||||||
|
|
||||||
|
const sync = () => {
|
||||||
|
el.style.top = `${vv.offsetTop}px`;
|
||||||
|
el.style.height = `${vv.height}px`;
|
||||||
|
el.style.bottom = 'auto';
|
||||||
|
};
|
||||||
|
sync();
|
||||||
|
vv.addEventListener('resize', sync);
|
||||||
|
vv.addEventListener('scroll', sync);
|
||||||
|
return () => {
|
||||||
|
vv.removeEventListener('resize', sync);
|
||||||
|
vv.removeEventListener('scroll', sync);
|
||||||
|
};
|
||||||
|
}, [isOpen]);
|
||||||
|
|
||||||
if (!isOpen || typeof window === 'undefined') return null;
|
if (!isOpen || typeof window === 'undefined') return null;
|
||||||
|
|
||||||
const handleOverlayClick = (e: React.MouseEvent) => {
|
const handleOverlayClick = (e: React.MouseEvent) => {
|
||||||
@@ -48,7 +76,7 @@ export function Modal({ isOpen, onClose, children, title, size = 'medium' }: Mod
|
|||||||
};
|
};
|
||||||
|
|
||||||
return createPortal(
|
return createPortal(
|
||||||
<div className={styles.overlay} onClick={handleOverlayClick}>
|
<div ref={overlayRef} className={styles.overlay} onClick={handleOverlayClick}>
|
||||||
<div className={`${styles.modal} ${styles[size]}`}>
|
<div className={`${styles.modal} ${styles[size]}`}>
|
||||||
<div className={styles.header}>
|
<div className={styles.header}>
|
||||||
{title && <h2 className={styles.title}>{title}</h2>}
|
{title && <h2 className={styles.title}>{title}</h2>}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { ChartOptions, ChartDataset } from 'chart.js';
|
|||||||
import '@/lib/chartSetup';
|
import '@/lib/chartSetup';
|
||||||
import type { SchoolResult } from '@/lib/types';
|
import type { SchoolResult } from '@/lib/types';
|
||||||
import { formatAcademicYear } from '@/lib/utils';
|
import { formatAcademicYear } from '@/lib/utils';
|
||||||
|
import { fillAcademicYears } from '@/lib/compareChartData';
|
||||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||||
import { track } from '@/lib/analytics';
|
import { track } from '@/lib/analytics';
|
||||||
import styles from './PerformanceChart.module.css';
|
import styles from './PerformanceChart.module.css';
|
||||||
@@ -35,8 +36,6 @@ interface PerformanceChartProps {
|
|||||||
nationalByYear?: NationalByYear[];
|
nationalByYear?: NationalByYear[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const COVID_YEARS = new Set([201920, 202021]);
|
|
||||||
|
|
||||||
// Mobile chip definitions: which datasets render when each chip is active.
|
// Mobile chip definitions: which datasets render when each chip is active.
|
||||||
// `series` keys reference the dataset labels so we can filter cleanly.
|
// `series` keys reference the dataset labels so we can filter cleanly.
|
||||||
type ChipId = 'expected' | 'higher' | 'progress' | 'attainment8' | 'em_pass' | 'progress8';
|
type ChipId = 'expected' | 'higher' | 'progress' | 'attainment8' | 'em_pass' | 'progress8';
|
||||||
@@ -67,21 +66,33 @@ export function PerformanceChart({
|
|||||||
nationalByYear,
|
nationalByYear,
|
||||||
}: PerformanceChartProps) {
|
}: PerformanceChartProps) {
|
||||||
const sortedData = [...data].sort((a, b) => a.year - b.year);
|
const sortedData = [...data].sort((a, b) => a.year - b.year);
|
||||||
const years = sortedData.map(d => formatAcademicYear(d.year));
|
|
||||||
|
// Gap-honest year axis: every academic year between the first and last data
|
||||||
|
// point appears, so cancelled/unpublished years (2019/20, 2020/21, and — for
|
||||||
|
// KS2 — 2021/22) render as real gaps rather than compressed time. School
|
||||||
|
// lines never bridge these gaps (spanGaps:false below).
|
||||||
|
const axisYears = fillAcademicYears(sortedData.map(d => d.year));
|
||||||
|
const byYear = new Map(sortedData.map(d => [d.year, d]));
|
||||||
|
const col = (key: keyof SchoolResult): (number | null)[] =>
|
||||||
|
axisYears.map(y => {
|
||||||
|
const v = byYear.get(y)?.[key];
|
||||||
|
return typeof v === 'number' ? v : null;
|
||||||
|
});
|
||||||
|
const years = axisYears.map(formatAcademicYear);
|
||||||
|
|
||||||
const isMobile = useIsMobile();
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
// ── Build per-year national averages ─────────────────────────────────
|
// ── Build per-year national averages (aligned to the filled axis) ────
|
||||||
const natRefRwm: (number | null)[] = sortedData.map(d => {
|
const natRefRwm: (number | null)[] = axisYears.map(y => {
|
||||||
if (nationalByYear) {
|
if (nationalByYear) {
|
||||||
const match = nationalByYear.find(n => n.year === d.year);
|
const match = nationalByYear.find(n => n.year === y);
|
||||||
return match?.primary?.rwm_expected_pct ?? null;
|
return match?.primary?.rwm_expected_pct ?? null;
|
||||||
}
|
}
|
||||||
return nationalRwmAvg ?? null;
|
return nationalRwmAvg ?? null;
|
||||||
});
|
});
|
||||||
const natRefAtt8: (number | null)[] = sortedData.map(d => {
|
const natRefAtt8: (number | null)[] = axisYears.map(y => {
|
||||||
if (nationalByYear) {
|
if (nationalByYear) {
|
||||||
const match = nationalByYear.find(n => n.year === d.year);
|
const match = nationalByYear.find(n => n.year === y);
|
||||||
return match?.secondary?.attainment_8_score ?? null;
|
return match?.secondary?.attainment_8_score ?? null;
|
||||||
}
|
}
|
||||||
return nationalAtt8Avg ?? null;
|
return nationalAtt8Avg ?? null;
|
||||||
@@ -107,10 +118,11 @@ export function PerformanceChart({
|
|||||||
return `${arrow} Reading, Writing & Maths peaked at ${bestPct}% (${formatAcademicYear(best.year)}), currently ${latestPct}%`;
|
return `${arrow} Reading, Writing & Maths peaked at ${bestPct}% (${formatAcademicYear(best.year)}), currently ${latestPct}%`;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const hasCovidGap = isSecondary
|
// A gap year is any filled axis year the school has no results row for —
|
||||||
? false
|
// exactly the cancelled/unpublished years the fill introduced. Drives the
|
||||||
: COVID_YEARS.size > 0 &&
|
// honest note below (KS2 and KS4 have different gap stories).
|
||||||
[...COVID_YEARS].some(y => !sortedData.find(d => d.year === y));
|
const gapYears = axisYears.filter(y => !byYear.has(y));
|
||||||
|
const hasGap = gapYears.length > 0;
|
||||||
|
|
||||||
// ── Datasets (full set; mobile filters them via the active chip) ─────
|
// ── Datasets (full set; mobile filters them via the active chip) ─────
|
||||||
const refLineStyle = {
|
const refLineStyle = {
|
||||||
@@ -120,13 +132,14 @@ export function PerformanceChart({
|
|||||||
borderDash: [6, 4] as number[],
|
borderDash: [6, 4] as number[],
|
||||||
pointRadius: 0,
|
pointRadius: 0,
|
||||||
tension: 0,
|
tension: 0,
|
||||||
|
spanGaps: false as const,
|
||||||
order: 10,
|
order: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
const allDatasets: ChartDataset<'line'>[] = isSecondary ? [
|
const allDatasets: ChartDataset<'line'>[] = isSecondary ? [
|
||||||
{
|
{
|
||||||
label: 'Attainment 8',
|
label: 'Attainment 8',
|
||||||
data: sortedData.map(d => d.attainment_8_score),
|
data: col('attainment_8_score'),
|
||||||
borderColor: '#2d7d7d',
|
borderColor: '#2d7d7d',
|
||||||
backgroundColor: 'rgba(45,125,125,0.08)',
|
backgroundColor: 'rgba(45,125,125,0.08)',
|
||||||
borderWidth: 2.5,
|
borderWidth: 2.5,
|
||||||
@@ -137,7 +150,7 @@ export function PerformanceChart({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'English & Maths Grade 4+',
|
label: 'English & Maths Grade 4+',
|
||||||
data: sortedData.map(d => d.english_maths_standard_pass_pct),
|
data: col('english_maths_standard_pass_pct'),
|
||||||
borderColor: '#c9a227',
|
borderColor: '#c9a227',
|
||||||
backgroundColor: 'rgba(201,162,39,0.08)',
|
backgroundColor: 'rgba(201,162,39,0.08)',
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
@@ -147,7 +160,7 @@ export function PerformanceChart({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Progress 8',
|
label: 'Progress 8',
|
||||||
data: sortedData.map(d => d.progress_8_score),
|
data: col('progress_8_score'),
|
||||||
borderColor: 'rgb(139,92,246)',
|
borderColor: 'rgb(139,92,246)',
|
||||||
backgroundColor: 'rgba(139,92,246,0.08)',
|
backgroundColor: 'rgba(139,92,246,0.08)',
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
@@ -165,7 +178,7 @@ export function PerformanceChart({
|
|||||||
] : [
|
] : [
|
||||||
{
|
{
|
||||||
label: 'Reading, Writing & Maths expected %',
|
label: 'Reading, Writing & Maths expected %',
|
||||||
data: sortedData.map(d => d.rwm_expected_pct),
|
data: col('rwm_expected_pct'),
|
||||||
borderColor: '#2d7d7d',
|
borderColor: '#2d7d7d',
|
||||||
backgroundColor: 'rgba(45,125,125,0.08)',
|
backgroundColor: 'rgba(45,125,125,0.08)',
|
||||||
borderWidth: 2.5,
|
borderWidth: 2.5,
|
||||||
@@ -176,7 +189,7 @@ export function PerformanceChart({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Exceeding expected level',
|
label: 'Exceeding expected level',
|
||||||
data: sortedData.map(d => d.rwm_high_pct),
|
data: col('rwm_high_pct'),
|
||||||
borderColor: '#c9a227',
|
borderColor: '#c9a227',
|
||||||
backgroundColor: 'rgba(201,162,39,0.08)',
|
backgroundColor: 'rgba(201,162,39,0.08)',
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
@@ -192,7 +205,7 @@ export function PerformanceChart({
|
|||||||
} as ChartDataset<'line'>] : []),
|
} as ChartDataset<'line'>] : []),
|
||||||
{
|
{
|
||||||
label: 'Reading progress',
|
label: 'Reading progress',
|
||||||
data: sortedData.map(d => d.reading_progress),
|
data: col('reading_progress'),
|
||||||
borderColor: 'rgb(59,130,246)',
|
borderColor: 'rgb(59,130,246)',
|
||||||
backgroundColor: 'rgba(59,130,246,0.08)',
|
backgroundColor: 'rgba(59,130,246,0.08)',
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
@@ -203,7 +216,7 @@ export function PerformanceChart({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Writing progress',
|
label: 'Writing progress',
|
||||||
data: sortedData.map(d => d.writing_progress),
|
data: col('writing_progress'),
|
||||||
borderColor: 'rgb(139,92,246)',
|
borderColor: 'rgb(139,92,246)',
|
||||||
backgroundColor: 'rgba(139,92,246,0.08)',
|
backgroundColor: 'rgba(139,92,246,0.08)',
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
@@ -214,7 +227,7 @@ export function PerformanceChart({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Maths progress',
|
label: 'Maths progress',
|
||||||
data: sortedData.map(d => d.maths_progress),
|
data: col('maths_progress'),
|
||||||
borderColor: 'rgb(236,72,153)',
|
borderColor: 'rgb(236,72,153)',
|
||||||
backgroundColor: 'rgba(236,72,153,0.08)',
|
backgroundColor: 'rgba(236,72,153,0.08)',
|
||||||
borderWidth: 1.5,
|
borderWidth: 1.5,
|
||||||
@@ -275,6 +288,8 @@ export function PerformanceChart({
|
|||||||
responsive: true,
|
responsive: true,
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
interaction: { mode: 'index', intersect: false },
|
interaction: { mode: 'index', intersect: false },
|
||||||
|
// Never bridge missing years — cancelled/unpublished years are real gaps.
|
||||||
|
datasets: { line: { spanGaps: false } },
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: {
|
legend: {
|
||||||
position: 'top',
|
position: 'top',
|
||||||
@@ -326,6 +341,7 @@ export function PerformanceChart({
|
|||||||
responsive: true,
|
responsive: true,
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
interaction: { mode: 'index', intersect: false },
|
interaction: { mode: 'index', intersect: false },
|
||||||
|
datasets: { line: { spanGaps: false } },
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: { display: false },
|
legend: { display: false },
|
||||||
title: { display: false },
|
title: { display: false },
|
||||||
@@ -353,7 +369,10 @@ export function PerformanceChart({
|
|||||||
},
|
},
|
||||||
x: {
|
x: {
|
||||||
grid: { display: false },
|
grid: { display: false },
|
||||||
ticks: { font: { size: 10 }, autoSkip: false },
|
// With the gap-honest axis (more year labels) autoSkip keeps the
|
||||||
|
// phone axis readable; the broken line still shows where a year is
|
||||||
|
// missing even when its tick label is skipped.
|
||||||
|
ticks: { font: { size: 10 }, autoSkip: true, maxTicksLimit: 5, maxRotation: 0 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -416,9 +435,11 @@ export function PerformanceChart({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{hasCovidGap && (
|
{hasGap && (
|
||||||
<p className={styles.covidNote}>
|
<p className={styles.covidNote}>
|
||||||
* No data for 2019/20 or 2020/21 — national assessments were cancelled due to COVID-19.
|
{isSecondary
|
||||||
|
? "School-level GCSE figures for 2019/20 and 2020/21 weren't published (COVID grading) where the line breaks — the England average is shown where available."
|
||||||
|
: "No national tests were held in 2019/20 and 2020/21 (COVID), and DfE didn't publish school-level figures for 2021/22 — the England average is shown for those years where available."}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -1040,6 +1040,41 @@
|
|||||||
color: var(--accent-coral-dark, #b04a2e);
|
color: var(--accent-coral-dark, #b04a2e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Ofsted grade grids (Report Card + OEIF) ──
|
||||||
|
Uniform, vertically-aligned grade chips. Labels reserve two lines so
|
||||||
|
single- and double-line labels put their chips on the same baseline;
|
||||||
|
every chip (Met, Strong, Expected standard, …) shares one font size,
|
||||||
|
padding and min-height regardless of how many lines its text wraps to. */
|
||||||
|
.gradeGrid .metricCard {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.85rem 0.75rem;
|
||||||
|
}
|
||||||
|
.gradeGrid .metricLabel {
|
||||||
|
min-height: 2.6em;
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.gradeGrid .metricValue {
|
||||||
|
margin-top: auto;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
max-width: 100%;
|
||||||
|
min-height: 2.6em;
|
||||||
|
padding: 0.3rem 0.7rem;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
line-height: 1.25;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.ofstedDisclaimer {
|
.ofstedDisclaimer {
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
color: var(--text-muted, #8a847a);
|
color: var(--text-muted, #8a847a);
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ import type {
|
|||||||
SchoolDeprivation, SchoolFinance, NationalAverages,
|
SchoolDeprivation, SchoolFinance, NationalAverages,
|
||||||
} from '@/lib/types';
|
} from '@/lib/types';
|
||||||
import {
|
import {
|
||||||
formatPercentage, formatProgress, formatAcademicYear, isProposedToClose,
|
formatPercentage, formatProgress, formatAcademicYear, isProposedToClose, ofstedLegacyAreas,
|
||||||
} from '@/lib/utils';
|
} from '@/lib/utils';
|
||||||
import { DeltaChip } from './DeltaChip';
|
import { DeltaChip } from './DeltaChip';
|
||||||
|
import { summariseAdmissions } from '@/lib/compareLogic';
|
||||||
|
|
||||||
const PerformanceChart = dynamic(
|
const PerformanceChart = dynamic(
|
||||||
() => import('./PerformanceChart').then((m) => m.PerformanceChart),
|
() => import('./PerformanceChart').then((m) => m.PerformanceChart),
|
||||||
@@ -85,6 +86,10 @@ export function SchoolDetailView({
|
|||||||
// Trend toggle only appears with ≥2 years carrying an offer rate.
|
// Trend toggle only appears with ≥2 years carrying an offer rate.
|
||||||
const admissionsOfferYears = admissionsHistory.filter((h) => h.first_preference_offer_pct != null).length;
|
const admissionsOfferYears = admissionsHistory.filter((h) => h.first_preference_offer_pct != null).length;
|
||||||
const showAdmissionsTrend = admissionsOfferYears >= 2;
|
const showAdmissionsTrend = admissionsOfferYears >= 2;
|
||||||
|
// Banded interpretation of the first-choice offer rate ("More than half of
|
||||||
|
// first choices missed out" etc.) — the same banding the compare screen
|
||||||
|
// uses, so a low offer rate reads as how severe it actually is.
|
||||||
|
const admissionsSummary = summariseAdmissions(admissions);
|
||||||
// Only the section links scroll horizontally; Back and "All" stay pinned.
|
// Only the section links scroll horizontally; Back and "All" stay pinned.
|
||||||
const sectionLinksRef = useRef<HTMLDivElement | null>(null);
|
const sectionLinksRef = useRef<HTMLDivElement | null>(null);
|
||||||
const [sectionNavAtEnd, setSectionNavAtEnd] = useState(false);
|
const [sectionNavAtEnd, setSectionNavAtEnd] = useState(false);
|
||||||
@@ -153,10 +158,16 @@ export function SchoolDetailView({
|
|||||||
|
|
||||||
const latestResults = yearlyData.length > 0 ? yearlyData[yearlyData.length - 1] : null;
|
const latestResults = yearlyData.length > 0 ? yearlyData[yearlyData.length - 1] : null;
|
||||||
|
|
||||||
// Phase detection
|
// Phase detection. All-through schools cover BOTH key stages, so they are
|
||||||
|
// neither "pure primary" nor "pure secondary": isSecondary stays true (they
|
||||||
|
// have KS4 data) but isAllThrough gates the primary-only content (phonics,
|
||||||
|
// KS2 trend) back on and switches phase-specific copy to an all-ages framing.
|
||||||
const phase = schoolInfo.phase ?? '';
|
const phase = schoolInfo.phase ?? '';
|
||||||
const isSecondary = phase.toLowerCase().includes('secondary') || phase.toLowerCase() === 'all-through';
|
const isAllThrough = phase.toLowerCase() === 'all-through';
|
||||||
|
const isSecondary = phase.toLowerCase().includes('secondary') || isAllThrough;
|
||||||
const isPrimary = !isSecondary;
|
const isPrimary = !isSecondary;
|
||||||
|
// Primary-stage content shows for pure-primary AND all-through schools.
|
||||||
|
const showPrimaryContent = isPrimary || isAllThrough;
|
||||||
|
|
||||||
// National averages (fetched dynamically so they stay current)
|
// National averages (fetched dynamically so they stay current)
|
||||||
const [nationalAvg, setNationalAvg] = useState<NationalAverages | null>(null);
|
const [nationalAvg, setNationalAvg] = useState<NationalAverages | null>(null);
|
||||||
@@ -228,11 +239,11 @@ export function SchoolDetailView({
|
|||||||
// after the recognised Ofsted badge; low-demand context sections stay last.
|
// after the recognised Ofsted badge; low-demand context sections stay last.
|
||||||
const navItems: { id: string; label: string }[] = [];
|
const navItems: { id: string; label: string }[] = [];
|
||||||
if (ofsted) navItems.push({ id: 'ofsted', label: 'Ofsted' });
|
if (ofsted) navItems.push({ id: 'ofsted', label: 'Ofsted' });
|
||||||
if (hasAnyResults) navItems.push({ id: 'results', label: isSecondary ? 'GCSEs' : 'SATs' });
|
if (hasAnyResults) navItems.push({ id: 'results', label: isAllThrough ? 'Results' : isSecondary ? 'GCSEs' : 'SATs' });
|
||||||
if (admissions) navItems.push({ id: 'admissions', label: 'Admissions' });
|
if (admissions) navItems.push({ id: 'admissions', label: 'Admissions' });
|
||||||
if (hasInclusionData) navItems.push({ id: 'inclusion', label: 'Pupils' });
|
if (hasInclusionData) navItems.push({ id: 'inclusion', label: 'Pupils' });
|
||||||
if (yearlyData.length > 0) navItems.push({ id: 'history', label: 'History' });
|
if (yearlyData.length > 0) navItems.push({ id: 'history', label: 'History' });
|
||||||
if (hasPhonics && isPrimary) navItems.push({ id: 'phonics', label: 'Phonics' });
|
if (hasPhonics && showPrimaryContent) navItems.push({ id: 'phonics', label: 'Phonics' });
|
||||||
if (hasSchoolLife) navItems.push({ id: 'school-life', label: 'School Life' });
|
if (hasSchoolLife) navItems.push({ id: 'school-life', label: 'School Life' });
|
||||||
if (hasDeprivation) navItems.push({ id: 'local-area', label: 'Local Area' });
|
if (hasDeprivation) navItems.push({ id: 'local-area', label: 'Local Area' });
|
||||||
if (hasFinance) navItems.push({ id: 'finances', label: 'Finances' });
|
if (hasFinance) navItems.push({ id: 'finances', label: 'Finances' });
|
||||||
@@ -269,18 +280,28 @@ export function SchoolDetailView({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [navItems.map(n => n.id).join(',')]);
|
}, [navItems.map(n => n.id).join(',')]);
|
||||||
|
|
||||||
|
// A report card is identified by the presence of report-card area
|
||||||
|
// judgements, NOT by `framework` — the API sets `framework` to the raw
|
||||||
|
// event grouping (e.g. "Schools - S5") even for report-card schools, so
|
||||||
|
// the old `framework === 'ReportCard'` test never matched and report cards
|
||||||
|
// were rendered as legacy ratings dated to a pre-Nov-2025 inspection.
|
||||||
|
const isReportCard = !!(
|
||||||
|
ofsted?.report_card && Object.keys(ofsted.report_card).length > 0
|
||||||
|
);
|
||||||
|
// A report card is dated by its own inspection (rc_inspection_date); the
|
||||||
|
// legacy inspection_date belongs to an older inspection and must never
|
||||||
|
// date a report card (report cards exist only from Nov 2025).
|
||||||
|
const ofstedInspectedDate = isReportCard
|
||||||
|
? ofsted?.rc_inspection_date ?? null
|
||||||
|
: ofsted?.inspection_date ?? null;
|
||||||
|
|
||||||
// ── Ofsted: detect if all OEIF sub-grades match the overall ───────────
|
// ── Ofsted: detect if all OEIF sub-grades match the overall ───────────
|
||||||
const oeifAllSameGrade = (() => {
|
const oeifAreas = ofsted ? ofstedLegacyAreas(ofsted) : [];
|
||||||
if (!ofsted || ofsted.framework === 'ReportCard') return false;
|
const oeifAllSameGrade =
|
||||||
const subs = [
|
!!ofsted &&
|
||||||
ofsted.quality_of_education,
|
!isReportCard &&
|
||||||
ofsted.behaviour_attitudes,
|
oeifAreas.length >= 3 &&
|
||||||
ofsted.personal_development,
|
oeifAreas.every((a) => a.value === ofsted.overall_effectiveness);
|
||||||
ofsted.leadership_management,
|
|
||||||
...(ofsted.early_years_provision != null ? [ofsted.early_years_provision] : []),
|
|
||||||
].filter((v): v is number => v != null);
|
|
||||||
return subs.length >= 3 && subs.every(v => v === ofsted.overall_effectiveness);
|
|
||||||
})();
|
|
||||||
|
|
||||||
// Label shown in the mobile "section" menu button — the section in view.
|
// Label shown in the mobile "section" menu button — the section in view.
|
||||||
const activeNavLabel = (navItems.find((n) => n.id === activeSection) ?? navItems[0])?.label ?? '';
|
const activeNavLabel = (navItems.find((n) => n.id === activeSection) ?? navItems[0])?.label ?? '';
|
||||||
@@ -309,6 +330,9 @@ export function SchoolDetailView({
|
|||||||
{schoolInfo.school_type && (
|
{schoolInfo.school_type && (
|
||||||
<span className={styles.metaItem}>{schoolInfo.school_type}</span>
|
<span className={styles.metaItem}>{schoolInfo.school_type}</span>
|
||||||
)}
|
)}
|
||||||
|
{isAllThrough && (
|
||||||
|
<span className={styles.metaItem}>All-through (primary & secondary)</span>
|
||||||
|
)}
|
||||||
{schoolInfo.gender && schoolInfo.gender !== 'Mixed' && (
|
{schoolInfo.gender && schoolInfo.gender !== 'Mixed' && (
|
||||||
<span className={styles.metaItem}>{schoolInfo.gender}'s school</span>
|
<span className={styles.metaItem}>{schoolInfo.gender}'s school</span>
|
||||||
)}
|
)}
|
||||||
@@ -507,10 +531,10 @@ export function SchoolDetailView({
|
|||||||
{ofsted && (
|
{ofsted && (
|
||||||
<section id="ofsted" className={styles.card}>
|
<section id="ofsted" className={styles.card}>
|
||||||
<h2 className={styles.sectionTitle}>
|
<h2 className={styles.sectionTitle}>
|
||||||
{ofsted.framework === 'ReportCard' ? 'Ofsted Report Card' : 'Ofsted Rating'}
|
{isReportCard ? 'Ofsted Report Card' : 'Ofsted Rating'}
|
||||||
{ofsted.inspection_date && (
|
{ofstedInspectedDate && (
|
||||||
<span className={styles.ofstedDate}>
|
<span className={styles.ofstedDate}>
|
||||||
Inspected {new Date(ofsted.inspection_date).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
|
||||||
@@ -525,13 +549,13 @@ export function SchoolDetailView({
|
|||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
{ofsted.framework === 'ReportCard' ? (
|
{isReportCard ? (
|
||||||
/* ── New Report Card layout ── */
|
/* ── New Report Card layout ── */
|
||||||
<>
|
<>
|
||||||
<p className={styles.ofstedDisclaimer}>
|
<p className={styles.ofstedDisclaimer}>
|
||||||
From November 2025, Ofsted replaced single overall grades with Report Cards rating schools across several areas.
|
From November 2025, Ofsted replaced single overall grades with Report Cards rating schools across several areas.
|
||||||
</p>
|
</p>
|
||||||
<div className={styles.metricsGrid}>
|
<div className={`${styles.metricsGrid} ${styles.gradeGrid}`}>
|
||||||
{ofsted.rc_safeguarding_met != null && (
|
{ofsted.rc_safeguarding_met != null && (
|
||||||
<div className={styles.metricCard}>
|
<div className={styles.metricCard}>
|
||||||
<div className={styles.metricLabel}>Safeguarding</div>
|
<div className={styles.metricLabel}>Safeguarding</div>
|
||||||
@@ -568,23 +592,17 @@ export function SchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className={styles.ofstedDisclaimer}>
|
<p className={styles.ofstedDisclaimer}>
|
||||||
From September 2024, Ofsted no longer makes an overall effectiveness judgement in inspections of state-funded schools.
|
{ofsted.grade_source === 'ungraded_carried_forward'
|
||||||
|
? '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.'
|
||||||
|
: 'From September 2024, Ofsted no longer makes an overall effectiveness judgement in inspections of state-funded schools.'}
|
||||||
</p>
|
</p>
|
||||||
{oeifAllSameGrade ? (
|
{oeifAllSameGrade ? (
|
||||||
<p className={styles.ofstedAllSame}>
|
<p className={styles.ofstedAllSame}>
|
||||||
Rated <strong>{OFSTED_LABELS[ofsted.overall_effectiveness!]}</strong> across all inspected areas — Quality of Teaching, Behaviour, Pupils' Development and Leadership.
|
Rated <strong>{OFSTED_LABELS[ofsted.overall_effectiveness!]}</strong> across all inspected areas — Quality of Teaching, Behaviour, Pupils' Development and Leadership.
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<div className={styles.metricsGrid}>
|
<div className={`${styles.metricsGrid} ${styles.gradeGrid}`}>
|
||||||
{[
|
{oeifAreas.map(({ label, value }) => (
|
||||||
{ label: 'Quality of Teaching', value: ofsted.quality_of_education },
|
|
||||||
{ label: 'Behaviour in School', value: ofsted.behaviour_attitudes },
|
|
||||||
{ label: 'Pupils\' Wider Development', value: ofsted.personal_development },
|
|
||||||
{ label: 'School Leadership', value: ofsted.leadership_management },
|
|
||||||
...(ofsted.early_years_provision != null
|
|
||||||
? [{ label: 'Early Years (Reception)', value: ofsted.early_years_provision }]
|
|
||||||
: []),
|
|
||||||
].map(({ label, value }) => value != null && (
|
|
||||||
<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}`]}`}>
|
||||||
@@ -603,17 +621,22 @@ export function SchoolDetailView({
|
|||||||
{hasAnyResults && latestResults && (
|
{hasAnyResults && latestResults && (
|
||||||
<section id="results" className={styles.card}>
|
<section id="results" className={styles.card}>
|
||||||
<h2 className={styles.sectionTitle}>
|
<h2 className={styles.sectionTitle}>
|
||||||
{isSecondary ? 'GCSE Results' : 'SATs Results'} ({formatAcademicYear(latestResults.year)})
|
{isAllThrough ? 'SATs & GCSE Results' : isSecondary ? 'GCSE Results' : 'SATs Results'} ({formatAcademicYear(latestResults.year)})
|
||||||
</h2>
|
</h2>
|
||||||
<p className={styles.sectionSubtitle}>
|
<p className={styles.sectionSubtitle}>
|
||||||
{isSecondary
|
{isAllThrough
|
||||||
? 'GCSE results for Year 11 pupils. National averages shown for comparison.'
|
? 'KS2 SATs (end of Year 6) and GCSE results (Year 11) — this school covers both. England averages shown for comparison.'
|
||||||
: 'End-of-primary-school tests taken by Year 6 pupils. National averages shown for comparison.'}
|
: isSecondary
|
||||||
|
? 'GCSE results for Year 11 pupils. England averages shown for comparison.'
|
||||||
|
: 'End-of-primary-school tests taken by Year 6 pupils. England averages shown for comparison.'}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{/* ── Primary / KS2 content ── */}
|
{/* ── Primary / KS2 content ── */}
|
||||||
{hasKS2Results && (
|
{hasKS2Results && (
|
||||||
<>
|
<>
|
||||||
|
{isAllThrough && (
|
||||||
|
<h3 className={styles.subSectionTitle}>Primary — KS2 SATs (Year 6)</h3>
|
||||||
|
)}
|
||||||
<div className={styles.heroStatGrid}>
|
<div className={styles.heroStatGrid}>
|
||||||
{latestResults.rwm_expected_pct !== null && (
|
{latestResults.rwm_expected_pct !== null && (
|
||||||
<div className={styles.heroStatCard}>
|
<div className={styles.heroStatCard}>
|
||||||
@@ -633,7 +656,7 @@ export function SchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{primaryAvg.rwm_expected_pct != null && (
|
{primaryAvg.rwm_expected_pct != null && (
|
||||||
<div className={styles.heroStatHint}>National avg: {primaryAvg.rwm_expected_pct.toFixed(0)}%</div>
|
<div className={styles.heroStatHint}>England avg: {primaryAvg.rwm_expected_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -655,7 +678,7 @@ export function SchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{primaryAvg.rwm_high_pct != null && (
|
{primaryAvg.rwm_high_pct != null && (
|
||||||
<div className={styles.heroStatHint}>National avg: {primaryAvg.rwm_high_pct.toFixed(0)}%</div>
|
<div className={styles.heroStatHint}>England avg: {primaryAvg.rwm_high_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -752,6 +775,9 @@ export function SchoolDetailView({
|
|||||||
{/* ── Secondary / KS4 content ── */}
|
{/* ── Secondary / KS4 content ── */}
|
||||||
{hasKS4Results && (
|
{hasKS4Results && (
|
||||||
<>
|
<>
|
||||||
|
{isAllThrough && (
|
||||||
|
<h3 className={styles.subSectionTitle} style={{ marginTop: '1.5rem' }}>Secondary — GCSEs (Year 11)</h3>
|
||||||
|
)}
|
||||||
<div className={styles.metricsGrid}>
|
<div className={styles.metricsGrid}>
|
||||||
{latestResults.attainment_8_score !== null && (
|
{latestResults.attainment_8_score !== null && (
|
||||||
<div className={styles.metricCard}>
|
<div className={styles.metricCard}>
|
||||||
@@ -761,7 +787,7 @@ export function SchoolDetailView({
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.metricValue}>{latestResults.attainment_8_score.toFixed(1)}</div>
|
<div className={styles.metricValue}>{latestResults.attainment_8_score.toFixed(1)}</div>
|
||||||
{secondaryAvg.attainment_8_score != null && (
|
{secondaryAvg.attainment_8_score != null && (
|
||||||
<div className={styles.metricHint}>National avg: {secondaryAvg.attainment_8_score.toFixed(1)}</div>
|
<div className={styles.metricHint}>England avg: {secondaryAvg.attainment_8_score.toFixed(1)}</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -785,7 +811,7 @@ export function SchoolDetailView({
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.metricValue}>{formatPercentage(latestResults.english_maths_standard_pass_pct)}</div>
|
<div className={styles.metricValue}>{formatPercentage(latestResults.english_maths_standard_pass_pct)}</div>
|
||||||
{secondaryAvg.english_maths_standard_pass_pct != null && (
|
{secondaryAvg.english_maths_standard_pass_pct != null && (
|
||||||
<div className={styles.metricHint}>National avg: {secondaryAvg.english_maths_standard_pass_pct.toFixed(0)}%</div>
|
<div className={styles.metricHint}>England avg: {secondaryAvg.english_maths_standard_pass_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -797,7 +823,7 @@ export function SchoolDetailView({
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.metricValue}>{formatPercentage(latestResults.english_maths_strong_pass_pct)}</div>
|
<div className={styles.metricValue}>{formatPercentage(latestResults.english_maths_strong_pass_pct)}</div>
|
||||||
{secondaryAvg.english_maths_strong_pass_pct != null && (
|
{secondaryAvg.english_maths_strong_pass_pct != null && (
|
||||||
<div className={styles.metricHint}>National avg: {secondaryAvg.english_maths_strong_pass_pct.toFixed(0)}%</div>
|
<div className={styles.metricHint}>England avg: {secondaryAvg.english_maths_strong_pass_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -902,6 +928,9 @@ export function SchoolDetailView({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</dl>
|
</dl>
|
||||||
|
{admissionsSummary.chip && (
|
||||||
|
<p className={styles.admissionsTrendSummary}>{admissionsSummary.chip.text}</p>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Multi-year trend */}
|
{/* Multi-year trend */}
|
||||||
@@ -937,7 +966,7 @@ export function SchoolDetailView({
|
|||||||
<DeltaChip value={latestResults.disadvantaged_pct} baseline={primaryAvg.disadvantaged_pct} unit="pts" size="sm" />
|
<DeltaChip value={latestResults.disadvantaged_pct} baseline={primaryAvg.disadvantaged_pct} unit="pts" size="sm" />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.heroStatHint}>Pupils from disadvantaged backgrounds{primaryAvg.disadvantaged_pct != null ? ` · national avg: ${primaryAvg.disadvantaged_pct.toFixed(0)}%` : ''}</div>
|
<div className={styles.heroStatHint}>Pupils from disadvantaged backgrounds{primaryAvg.disadvantaged_pct != null ? ` · England avg: ${primaryAvg.disadvantaged_pct.toFixed(0)}%` : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{latestResults?.eal_pct != null && (
|
{latestResults?.eal_pct != null && (
|
||||||
@@ -953,7 +982,7 @@ export function SchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{primaryAvg.eal_pct != null && (
|
{primaryAvg.eal_pct != null && (
|
||||||
<div className={styles.heroStatHint}>National avg: {primaryAvg.eal_pct.toFixed(0)}%</div>
|
<div className={styles.heroStatHint}>England avg: {primaryAvg.eal_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -970,7 +999,7 @@ export function SchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{primaryAvg.sen_support_pct != null && (
|
{primaryAvg.sen_support_pct != null && (
|
||||||
<div className={styles.heroStatHint}>National avg: {primaryAvg.sen_support_pct.toFixed(0)}%</div>
|
<div className={styles.heroStatHint}>England avg: {primaryAvg.sen_support_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -1034,16 +1063,52 @@ export function SchoolDetailView({
|
|||||||
{yearlyData.length > 0 && (
|
{yearlyData.length > 0 && (
|
||||||
<section id="history" className={styles.card}>
|
<section id="history" className={styles.card}>
|
||||||
<h2 className={styles.sectionTitle}>Results Over Time</h2>
|
<h2 className={styles.sectionTitle}>Results Over Time</h2>
|
||||||
<div className={styles.chartContainer}>
|
{isAllThrough ? (
|
||||||
<PerformanceChart
|
// All-through: KS2 and KS4 trends are on different scales and have
|
||||||
data={yearlyData}
|
// different gap stories, so render them as two stacked charts
|
||||||
schoolName={schoolInfo.school_name}
|
// rather than crowding 8+ series onto one axis.
|
||||||
isSecondary={isSecondary}
|
<>
|
||||||
nationalRwmAvg={isPrimary ? (primaryAvg.rwm_expected_pct ?? null) : null}
|
{hasKS2Results && (
|
||||||
nationalAtt8Avg={isSecondary ? (secondaryAvg.attainment_8_score ?? null) : null}
|
<>
|
||||||
nationalByYear={nationalAvg?.by_year}
|
<h3 className={styles.subSectionTitle}>Primary — KS2 SATs</h3>
|
||||||
/>
|
<div className={styles.chartContainer}>
|
||||||
</div>
|
<PerformanceChart
|
||||||
|
data={yearlyData}
|
||||||
|
schoolName={schoolInfo.school_name}
|
||||||
|
isSecondary={false}
|
||||||
|
nationalRwmAvg={primaryAvg.rwm_expected_pct ?? null}
|
||||||
|
nationalByYear={nationalAvg?.by_year}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{hasKS4Results && (
|
||||||
|
<>
|
||||||
|
<h3 className={styles.subSectionTitle} style={{ marginTop: '1.5rem' }}>Secondary — GCSEs</h3>
|
||||||
|
<div className={styles.chartContainer}>
|
||||||
|
<PerformanceChart
|
||||||
|
data={yearlyData}
|
||||||
|
schoolName={schoolInfo.school_name}
|
||||||
|
isSecondary={true}
|
||||||
|
nationalAtt8Avg={secondaryAvg.attainment_8_score ?? null}
|
||||||
|
nationalByYear={nationalAvg?.by_year}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<div className={styles.chartContainer}>
|
||||||
|
<PerformanceChart
|
||||||
|
data={yearlyData}
|
||||||
|
schoolName={schoolInfo.school_name}
|
||||||
|
isSecondary={isSecondary}
|
||||||
|
nationalRwmAvg={isPrimary ? (primaryAvg.rwm_expected_pct ?? null) : null}
|
||||||
|
nationalAtt8Avg={isSecondary ? (secondaryAvg.attainment_8_score ?? null) : null}
|
||||||
|
nationalByYear={nationalAvg?.by_year}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{yearlyData.length > 1 && (
|
{yearlyData.length > 1 && (
|
||||||
<details className={styles.historyDisclosure}>
|
<details className={styles.historyDisclosure}>
|
||||||
<summary className={styles.historyToggle}>View raw year-by-year data</summary>
|
<summary className={styles.historyToggle}>View raw year-by-year data</summary>
|
||||||
@@ -1052,7 +1117,15 @@ export function SchoolDetailView({
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Year</th>
|
<th>Year</th>
|
||||||
{isSecondary ? (
|
{isAllThrough ? (
|
||||||
|
<>
|
||||||
|
<th>RWM (expected %)</th>
|
||||||
|
<th>Exceeding (%)</th>
|
||||||
|
<th>Attainment 8</th>
|
||||||
|
<th>Progress 8</th>
|
||||||
|
<th>English & Maths Grade 4+</th>
|
||||||
|
</>
|
||||||
|
) : isSecondary ? (
|
||||||
<>
|
<>
|
||||||
<th>Attainment 8</th>
|
<th>Attainment 8</th>
|
||||||
<th>Progress 8</th>
|
<th>Progress 8</th>
|
||||||
@@ -1074,7 +1147,15 @@ export function SchoolDetailView({
|
|||||||
{yearlyData.map((result) => (
|
{yearlyData.map((result) => (
|
||||||
<tr key={result.year}>
|
<tr key={result.year}>
|
||||||
<td className={styles.yearCell}>{formatAcademicYear(result.year)}</td>
|
<td className={styles.yearCell}>{formatAcademicYear(result.year)}</td>
|
||||||
{isSecondary ? (
|
{isAllThrough ? (
|
||||||
|
<>
|
||||||
|
<td>{result.rwm_expected_pct !== null ? formatPercentage(result.rwm_expected_pct) : '-'}</td>
|
||||||
|
<td>{result.rwm_high_pct !== null ? formatPercentage(result.rwm_high_pct) : '-'}</td>
|
||||||
|
<td>{result.attainment_8_score !== null ? result.attainment_8_score.toFixed(1) : '-'}</td>
|
||||||
|
<td>{result.progress_8_score !== null ? formatProgress(result.progress_8_score) : '-'}</td>
|
||||||
|
<td>{result.english_maths_standard_pass_pct !== null ? formatPercentage(result.english_maths_standard_pass_pct) : '-'}</td>
|
||||||
|
</>
|
||||||
|
) : isSecondary ? (
|
||||||
<>
|
<>
|
||||||
<td>{result.attainment_8_score !== null ? result.attainment_8_score.toFixed(1) : '-'}</td>
|
<td>{result.attainment_8_score !== null ? result.attainment_8_score.toFixed(1) : '-'}</td>
|
||||||
<td>{result.progress_8_score !== null ? formatProgress(result.progress_8_score) : '-'}</td>
|
<td>{result.progress_8_score !== null ? formatProgress(result.progress_8_score) : '-'}</td>
|
||||||
@@ -1099,8 +1180,8 @@ export function SchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
{/* Year 1 Phonics — primary only */}
|
{/* Year 1 Phonics — primary-stage metric (pure primary + all-through) */}
|
||||||
{hasPhonics && isPrimary && phonics && (
|
{hasPhonics && showPrimaryContent && phonics && (
|
||||||
<section id="phonics" className={styles.card}>
|
<section id="phonics" className={styles.card}>
|
||||||
<h2 className={styles.sectionTitle}>Year 1 Phonics ({formatAcademicYear(phonics.year)})</h2>
|
<h2 className={styles.sectionTitle}>Year 1 Phonics ({formatAcademicYear(phonics.year)})</h2>
|
||||||
<p className={styles.sectionSubtitle}>
|
<p className={styles.sectionSubtitle}>
|
||||||
@@ -1142,7 +1223,7 @@ export function SchoolDetailView({
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.metricValue}>{formatPercentage(absenceData.overall_absence_rate)}</div>
|
<div className={styles.metricValue}>{formatPercentage(absenceData.overall_absence_rate)}</div>
|
||||||
{primaryAvg.overall_absence_pct != null && (
|
{primaryAvg.overall_absence_pct != null && (
|
||||||
<div className={styles.metricHint}>National avg: ~{primaryAvg.overall_absence_pct.toFixed(1)}%</div>
|
<div className={styles.metricHint}>England avg: ~{primaryAvg.overall_absence_pct.toFixed(1)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -1154,7 +1235,7 @@ export function SchoolDetailView({
|
|||||||
</div>
|
</div>
|
||||||
<div className={styles.metricValue}>{formatPercentage(absenceData.persistent_absence_rate)}</div>
|
<div className={styles.metricValue}>{formatPercentage(absenceData.persistent_absence_rate)}</div>
|
||||||
{primaryAvg.persistent_absence_pct != null && (
|
{primaryAvg.persistent_absence_pct != null && (
|
||||||
<div className={styles.metricHint}>National avg: ~{primaryAvg.persistent_absence_pct.toFixed(0)}%</div>
|
<div className={styles.metricHint}>England avg: ~{primaryAvg.persistent_absence_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -2,14 +2,6 @@
|
|||||||
padding: 1.5rem;
|
padding: 1.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--text-primary, #1a1612);
|
|
||||||
margin-bottom: 1.5rem;
|
|
||||||
font-family: var(--font-playfair), 'Playfair Display', serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
.warning {
|
.warning {
|
||||||
background: var(--accent-gold-bg);
|
background: var(--accent-gold-bg);
|
||||||
border: 1px solid var(--accent-gold, #c9a227);
|
border: 1px solid var(--accent-gold, #c9a227);
|
||||||
@@ -119,12 +111,16 @@
|
|||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--text-primary, #1a1612);
|
color: var(--text-primary, #1a1612);
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.25rem;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.resultButton {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
.schoolMeta {
|
.schoolMeta {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
@@ -159,21 +155,30 @@
|
|||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title {
|
/* One scroll container on mobile: the modal content itself scrolls, so the
|
||||||
font-size: 1.25rem;
|
results list must not add its own inner scroll (double scrollbars, and
|
||||||
|
the input would be trapped above a short 400px window when the keyboard
|
||||||
|
shrinks the sheet). */
|
||||||
|
.results {
|
||||||
|
max-height: none;
|
||||||
|
overflow: visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Compact stacked card: name + meta, then a full-width action so the tap
|
||||||
|
target is obvious and the card doesn't waste vertical space. */
|
||||||
.resultItem {
|
.resultItem {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: stretch;
|
align-items: stretch;
|
||||||
|
gap: 0.625rem;
|
||||||
|
padding: 0.875rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.addButton {
|
.resultButton {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.schoolMeta {
|
.schoolMeta {
|
||||||
flex-direction: column;
|
flex-wrap: wrap;
|
||||||
gap: 0.25rem;
|
gap: 0.25rem 1rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,10 +81,8 @@ export function SchoolSearchModal({ isOpen, onClose }: SchoolSearchModalProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={isOpen} onClose={handleClose}>
|
<Modal isOpen={isOpen} onClose={handleClose} title="Add School to Comparison">
|
||||||
<div className={styles.modalContent}>
|
<div className={styles.modalContent}>
|
||||||
<h2 className={styles.title}>Add School to Comparison</h2>
|
|
||||||
|
|
||||||
{!canAddMore && (
|
{!canAddMore && (
|
||||||
<div className={styles.warning}>
|
<div className={styles.warning}>
|
||||||
Maximum 5 schools can be compared. Remove a school to add another.
|
Maximum 5 schools can be compared. Remove a school to add another.
|
||||||
@@ -129,9 +127,9 @@ export function SchoolSearchModal({ isOpen, onClose }: SchoolSearchModalProps) {
|
|||||||
<button
|
<button
|
||||||
onClick={() => handleAddSchool(school)}
|
onClick={() => handleAddSchool(school)}
|
||||||
disabled={alreadySelected || !canAddMore}
|
disabled={alreadySelected || !canAddMore}
|
||||||
className={
|
className={`${styles.resultButton} ${
|
||||||
alreadySelected ? "btn btn-active" : "btn btn-secondary"
|
alreadySelected ? "btn btn-active" : "btn btn-secondary"
|
||||||
}
|
}`}
|
||||||
>
|
>
|
||||||
{alreadySelected ? "✓ Comparing" : "+ Compare"}
|
{alreadySelected ? "✓ Comparing" : "+ Compare"}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -623,6 +623,41 @@
|
|||||||
color: var(--accent-coral-dark, #b04a2e);
|
color: var(--accent-coral-dark, #b04a2e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Ofsted grade grids (Report Card + OEIF) ──
|
||||||
|
Uniform, vertically-aligned grade chips. Labels reserve two lines so
|
||||||
|
single- and double-line labels put their chips on the same baseline;
|
||||||
|
every chip (Met, Strong, Expected standard, …) shares one font size,
|
||||||
|
padding and min-height regardless of how many lines its text wraps to. */
|
||||||
|
.gradeGrid .metricCard {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.85rem 0.75rem;
|
||||||
|
}
|
||||||
|
.gradeGrid .metricLabel {
|
||||||
|
min-height: 2.6em;
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.gradeGrid .metricValue {
|
||||||
|
margin-top: auto;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
max-width: 100%;
|
||||||
|
min-height: 2.6em;
|
||||||
|
padding: 0.3rem 0.7rem;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-size: 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
line-height: 1.25;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
.ofstedDisclaimer {
|
.ofstedDisclaimer {
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
color: var(--text-muted, #8a847a);
|
color: var(--text-muted, #8a847a);
|
||||||
@@ -1049,8 +1084,12 @@
|
|||||||
font-size: 1.85rem;
|
font-size: 1.85rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* On mobile let the chart container flow naturally — PerformanceChart's
|
||||||
|
own .chartWrapper carries the definite canvas height (220px) plus the
|
||||||
|
chip strip above it. A fixed 220px here double-constrained the two and
|
||||||
|
clipped the chips onto the plot area. */
|
||||||
.chartContainer {
|
.chartContainer {
|
||||||
height: 220px;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dataTable {
|
.dataTable {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import type {
|
|||||||
SchoolAdmissions, SenDetail, Phonics,
|
SchoolAdmissions, SenDetail, Phonics,
|
||||||
SchoolDeprivation, SchoolFinance, NationalAverages,
|
SchoolDeprivation, SchoolFinance, NationalAverages,
|
||||||
} from '@/lib/types';
|
} from '@/lib/types';
|
||||||
import { formatPercentage, formatProgress, formatAcademicYear, formatAgeRange, isProposedToClose } from '@/lib/utils';
|
import { formatPercentage, formatProgress, formatAcademicYear, formatAgeRange, isProposedToClose, ofstedLegacyAreas } from '@/lib/utils';
|
||||||
import { DeltaChip } from './DeltaChip';
|
import { DeltaChip } from './DeltaChip';
|
||||||
import { track, getNavigationSource } from '@/lib/analytics';
|
import { track, getNavigationSource } from '@/lib/analytics';
|
||||||
import styles from './SecondarySchoolDetailView.module.css';
|
import styles from './SecondarySchoolDetailView.module.css';
|
||||||
@@ -186,18 +186,27 @@ export function SecondarySchoolDetailView({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [navItems.map(n => n.id).join(',')]);
|
}, [navItems.map(n => n.id).join(',')]);
|
||||||
|
|
||||||
|
// A report card is identified by the presence of report-card area
|
||||||
|
// judgements, NOT by `framework` — the API sets `framework` to the raw
|
||||||
|
// event grouping (e.g. "Schools - S5") even for report-card schools, so
|
||||||
|
// the old `framework === 'ReportCard'` test never matched and report cards
|
||||||
|
// were rendered as legacy ratings dated to a pre-Nov-2025 inspection.
|
||||||
|
const isReportCard = !!(
|
||||||
|
ofsted?.report_card && Object.keys(ofsted.report_card).length > 0
|
||||||
|
);
|
||||||
|
// Report cards are dated by their own inspection (rc_inspection_date), never
|
||||||
|
// the legacy inspection_date (report cards exist only from Nov 2025).
|
||||||
|
const ofstedInspectedDate = isReportCard
|
||||||
|
? ofsted?.rc_inspection_date ?? null
|
||||||
|
: ofsted?.inspection_date ?? null;
|
||||||
|
|
||||||
// ── Ofsted: detect if all OEIF sub-grades match the overall ───────────
|
// ── Ofsted: detect if all OEIF sub-grades match the overall ───────────
|
||||||
const oeifAllSameGrade = (() => {
|
const oeifAreas = ofsted ? ofstedLegacyAreas(ofsted) : [];
|
||||||
if (!ofsted || ofsted.framework === 'ReportCard') return false;
|
const oeifAllSameGrade =
|
||||||
const subs = [
|
!!ofsted &&
|
||||||
ofsted.quality_of_education,
|
!isReportCard &&
|
||||||
ofsted.behaviour_attitudes,
|
oeifAreas.length >= 3 &&
|
||||||
ofsted.personal_development,
|
oeifAreas.every((a) => a.value === ofsted.overall_effectiveness);
|
||||||
ofsted.leadership_management,
|
|
||||||
...(ofsted.early_years_provision != null ? [ofsted.early_years_provision] : []),
|
|
||||||
].filter((v): v is number => v != null);
|
|
||||||
return subs.length >= 3 && subs.every(v => v === ofsted.overall_effectiveness);
|
|
||||||
})();
|
|
||||||
|
|
||||||
// National Attainment 8 baseline for the "Results Over Time" chart.
|
// National Attainment 8 baseline for the "Results Over Time" chart.
|
||||||
const heroAtt8Nat = secondaryAvg.attainment_8_score ?? null;
|
const heroAtt8Nat = secondaryAvg.attainment_8_score ?? null;
|
||||||
@@ -332,10 +341,10 @@ export function SecondarySchoolDetailView({
|
|||||||
{ofsted && (
|
{ofsted && (
|
||||||
<section id="ofsted" className={styles.card}>
|
<section id="ofsted" className={styles.card}>
|
||||||
<h2 className={styles.sectionTitle}>
|
<h2 className={styles.sectionTitle}>
|
||||||
{ofsted.framework === 'ReportCard' ? 'Ofsted Report Card' : 'Ofsted Rating'}
|
{isReportCard ? 'Ofsted Report Card' : 'Ofsted Rating'}
|
||||||
{ofsted.inspection_date && (
|
{ofstedInspectedDate && (
|
||||||
<span className={styles.ofstedDate}>
|
<span className={styles.ofstedDate}>
|
||||||
{' '}Inspected {new Date(ofsted.inspection_date).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
|
||||||
@@ -349,12 +358,12 @@ export function SecondarySchoolDetailView({
|
|||||||
Ofsted reports ↗
|
Ofsted reports ↗
|
||||||
</a>
|
</a>
|
||||||
</h2>
|
</h2>
|
||||||
{ofsted.framework === 'ReportCard' ? (
|
{isReportCard ? (
|
||||||
<>
|
<>
|
||||||
<p className={styles.ofstedDisclaimer}>
|
<p className={styles.ofstedDisclaimer}>
|
||||||
From November 2025, Ofsted replaced single overall grades with Report Cards rating schools across several areas.
|
From November 2025, Ofsted replaced single overall grades with Report Cards rating schools across several areas.
|
||||||
</p>
|
</p>
|
||||||
<div className={styles.metricsGrid}>
|
<div className={`${styles.metricsGrid} ${styles.gradeGrid}`}>
|
||||||
{ofsted.rc_safeguarding_met != null && (
|
{ofsted.rc_safeguarding_met != null && (
|
||||||
<div className={styles.metricCard}>
|
<div className={styles.metricCard}>
|
||||||
<div className={styles.metricLabel}>Safeguarding</div>
|
<div className={styles.metricLabel}>Safeguarding</div>
|
||||||
@@ -390,23 +399,17 @@ export function SecondarySchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className={styles.ofstedDisclaimer}>
|
<p className={styles.ofstedDisclaimer}>
|
||||||
From September 2024, Ofsted no longer makes an overall effectiveness judgement in inspections.
|
{ofsted.grade_source === 'ungraded_carried_forward'
|
||||||
|
? '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.'
|
||||||
|
: 'From September 2024, Ofsted no longer makes an overall effectiveness judgement in inspections.'}
|
||||||
</p>
|
</p>
|
||||||
{oeifAllSameGrade ? (
|
{oeifAllSameGrade ? (
|
||||||
<p className={styles.ofstedAllSame}>
|
<p className={styles.ofstedAllSame}>
|
||||||
Rated <strong>{OFSTED_LABELS[ofsted.overall_effectiveness]}</strong> across all inspected areas — Quality of Teaching, Behaviour, Pupils' Development and Leadership.
|
Rated <strong>{OFSTED_LABELS[ofsted.overall_effectiveness]}</strong> across all inspected areas — Quality of Teaching, Behaviour, Pupils' Development and Leadership.
|
||||||
</p>
|
</p>
|
||||||
) : (
|
) : (
|
||||||
<div className={styles.metricsGrid}>
|
<div className={`${styles.metricsGrid} ${styles.gradeGrid}`}>
|
||||||
{[
|
{oeifAreas.map(({ label, value }) => (
|
||||||
{ label: 'Quality of Teaching', value: ofsted.quality_of_education },
|
|
||||||
{ label: 'Behaviour in School', value: ofsted.behaviour_attitudes },
|
|
||||||
{ label: 'Pupils\' Wider Development', value: ofsted.personal_development },
|
|
||||||
{ label: 'School Leadership', value: ofsted.leadership_management },
|
|
||||||
...(ofsted.early_years_provision != null
|
|
||||||
? [{ label: 'Early Years (Reception)', value: ofsted.early_years_provision }]
|
|
||||||
: []),
|
|
||||||
].map(({ label, value }) => value != null && (
|
|
||||||
<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}`]}`}>
|
||||||
@@ -422,7 +425,7 @@ export function SecondarySchoolDetailView({
|
|||||||
<p className={styles.sectionSubtitle}>
|
<p className={styles.sectionSubtitle}>
|
||||||
From September 2024, Ofsted no longer gives a single overall grade.
|
From September 2024, Ofsted no longer gives a single overall grade.
|
||||||
</p>
|
</p>
|
||||||
<div className={styles.metricsGrid}>
|
<div className={`${styles.metricsGrid} ${styles.gradeGrid}`}>
|
||||||
{[
|
{[
|
||||||
{ label: 'Quality of Education', value: ofsted.quality_of_education },
|
{ label: 'Quality of Education', value: ofsted.quality_of_education },
|
||||||
{ label: 'Behaviour & Attitudes', value: ofsted.behaviour_attitudes },
|
{ label: 'Behaviour & Attitudes', value: ofsted.behaviour_attitudes },
|
||||||
@@ -449,12 +452,13 @@ export function SecondarySchoolDetailView({
|
|||||||
GCSE Results ({formatAcademicYear(latestResults.year)})
|
GCSE Results ({formatAcademicYear(latestResults.year)})
|
||||||
</h2>
|
</h2>
|
||||||
<p className={styles.sectionSubtitle}>
|
<p className={styles.sectionSubtitle}>
|
||||||
GCSE results for Year 11 pupils. National averages shown for comparison.
|
GCSE results for Year 11 pupils. England averages shown for comparison.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{p8Suspended && (
|
{p8Suspended && (
|
||||||
<div className={styles.p8Banner}>
|
<div className={styles.p8Banner}>
|
||||||
Progress 8 scores for 2024/25 are not used for accountability purposes following the KS2 assessment disruption. Treat with caution.
|
Progress 8 isn't published for 2024/25: this GCSE year group sat no KS2 tests
|
||||||
|
(COVID), so DfE has no starting point to measure their progress from.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -478,7 +482,7 @@ export function SecondarySchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{secondaryAvg.attainment_8_score != null && (
|
{secondaryAvg.attainment_8_score != null && (
|
||||||
<div className={styles.heroStatHint}>National avg: {secondaryAvg.attainment_8_score.toFixed(1)}</div>
|
<div className={styles.heroStatHint}>England avg: {secondaryAvg.attainment_8_score.toFixed(1)}</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -518,7 +522,7 @@ export function SecondarySchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{secondaryAvg.english_maths_strong_pass_pct != null && (
|
{secondaryAvg.english_maths_strong_pass_pct != null && (
|
||||||
<div className={styles.heroStatHint}>National avg: {secondaryAvg.english_maths_strong_pass_pct.toFixed(0)}%</div>
|
<div className={styles.heroStatHint}>England avg: {secondaryAvg.english_maths_strong_pass_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -540,7 +544,7 @@ export function SecondarySchoolDetailView({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{secondaryAvg.english_maths_standard_pass_pct != null && (
|
{secondaryAvg.english_maths_standard_pass_pct != null && (
|
||||||
<div className={styles.heroStatHint}>National avg: {secondaryAvg.english_maths_standard_pass_pct.toFixed(0)}%</div>
|
<div className={styles.heroStatHint}>England avg: {secondaryAvg.english_maths_standard_pass_pct.toFixed(0)}%</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -125,15 +125,17 @@ export function CompareAcademics({
|
|||||||
data,
|
data,
|
||||||
nationalAverages,
|
nationalAverages,
|
||||||
benchmarks,
|
benchmarks,
|
||||||
|
isSecondary: propIsSecondary,
|
||||||
}: {
|
}: {
|
||||||
schools: School[];
|
schools: School[];
|
||||||
data: Record<string, ComparisonData>;
|
data: Record<string, ComparisonData>;
|
||||||
nationalAverages?: NationalAverages;
|
nationalAverages?: NationalAverages;
|
||||||
benchmarks?: Benchmarks;
|
benchmarks?: Benchmarks;
|
||||||
|
isSecondary?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const urns = schools.map((school) => school.urn);
|
const urns = schools.map((school) => school.urn);
|
||||||
const schoolNames = schools.map((school) => school.school_name);
|
const schoolNames = schools.map((school) => school.school_name);
|
||||||
const isSecondary = schools.some(
|
const isSecondary = propIsSecondary !== undefined ? propIsSecondary : schools.some(
|
||||||
(school) => data[String(school.urn)]?.school_info?.attainment_8_score != null,
|
(school) => data[String(school.urn)]?.school_info?.attainment_8_score != null,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -146,9 +148,35 @@ export function CompareAcademics({
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
// DfE stopped publishing Progress 8 from 2024/25: those GCSE year groups
|
||||||
|
// sat no KS2 tests (COVID), so there is no baseline to measure progress
|
||||||
|
// from. A bare "No data" reads as a gap on our side — say why. Judged
|
||||||
|
// PER SCHOOL on its own latest data year: a school whose data simply
|
||||||
|
// stops earlier (an unrelated gap) must not borrow the COVID explanation
|
||||||
|
// from a neighbour that does have 2024/25 data.
|
||||||
|
const p8NotPublished = urns.map((urn) => {
|
||||||
|
const rows = data[String(urn)]?.yearly_data ?? [];
|
||||||
|
const y = rows.length ? Math.trunc(rows[rows.length - 1].year) : 0;
|
||||||
|
return y >= 202425;
|
||||||
|
});
|
||||||
const grade5 = latestValues(data, urns, 'english_maths_strong_pass_pct');
|
const grade5 = latestValues(data, urns, 'english_maths_strong_pass_pct');
|
||||||
const ebacc = latestValues(data, urns, 'ebacc_entry_pct');
|
const ebacc = latestValues(data, urns, 'ebacc_entry_pct');
|
||||||
const att8Anchor = nationalAverages?.secondary?.attainment_8_score;
|
const att8Anchor = nationalAverages?.secondary?.attainment_8_score;
|
||||||
|
const grade5Anchor = nationalAverages?.secondary?.english_maths_strong_pass_pct;
|
||||||
|
const ebaccAnchor = nationalAverages?.secondary?.ebacc_entry_pct;
|
||||||
|
|
||||||
|
// Every headline number gets its England anchor + verdict chip, so the
|
||||||
|
// "anchored against the England average" promise holds for the grade-5
|
||||||
|
// and EBacc rows too, not just Attainment 8.
|
||||||
|
const anchorChip = (value: number | null, anchor: number | null | undefined, tol: number) => {
|
||||||
|
if (value == null || anchor == null) return null;
|
||||||
|
const v = verdict(value, anchor, tol);
|
||||||
|
return (
|
||||||
|
<Chip tone={v === 'above' ? 'good' : v === 'below' ? 'warn' : 'neutral'}>
|
||||||
|
{v === 'above' ? 'Above' : v === 'below' ? 'Below' : 'Close to'} England average
|
||||||
|
</Chip>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section
|
<Section
|
||||||
@@ -161,7 +189,8 @@ export function CompareAcademics({
|
|||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
{att8[i] != null ? (
|
{att8[i] != null ? (
|
||||||
<>
|
<>
|
||||||
<span className={s.big}>{(att8[i] as number).toFixed(1)}</span>
|
<span className={s.big}>{(att8[i] as number).toFixed(1)}</span>{' '}
|
||||||
|
{anchorChip(att8[i], att8Anchor, 2)}
|
||||||
{att8Anchor != null && (
|
{att8Anchor != null && (
|
||||||
<span className={s.small}>England average {att8Anchor.toFixed(1)}</span>
|
<span className={s.small}>England average {att8Anchor.toFixed(1)}</span>
|
||||||
)}
|
)}
|
||||||
@@ -187,6 +216,11 @@ export function CompareAcademics({
|
|||||||
>
|
>
|
||||||
{banding[i]}
|
{banding[i]}
|
||||||
</Chip>
|
</Chip>
|
||||||
|
) : p8NotPublished[i] ? (
|
||||||
|
<span className={s.small}>
|
||||||
|
Not published — this GCSE year group sat no KS2 tests (COVID), so DfE has no
|
||||||
|
baseline to measure progress from
|
||||||
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className={s.small}>No data</span>
|
<span className={s.small}>No data</span>
|
||||||
)}
|
)}
|
||||||
@@ -198,14 +232,38 @@ export function CompareAcademics({
|
|||||||
</RowLabel>
|
</RowLabel>
|
||||||
{schools.map((school, i) => (
|
{schools.map((school, i) => (
|
||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
{grade5[i] != null ? `${Math.round(grade5[i] as number)}%` : <span className={s.small}>No data</span>}
|
{grade5[i] != null ? (
|
||||||
|
<>
|
||||||
|
<span className={s.big} style={{ fontSize: '1.1rem' }}>
|
||||||
|
{Math.round(grade5[i] as number)}%
|
||||||
|
</span>{' '}
|
||||||
|
{anchorChip(grade5[i], grade5Anchor, 3)}
|
||||||
|
{grade5Anchor != null && (
|
||||||
|
<span className={s.small}>England average {Math.round(grade5Anchor)}%</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className={s.small}>No data</span>
|
||||||
|
)}
|
||||||
</Cell>
|
</Cell>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
<RowLabel tip="% entering the English Baccalaureate subject combination.">EBacc entry</RowLabel>
|
<RowLabel tip="% entering the English Baccalaureate subject combination.">EBacc entry</RowLabel>
|
||||||
{schools.map((school, i) => (
|
{schools.map((school, i) => (
|
||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
{ebacc[i] != null ? `${Math.round(ebacc[i] as number)}%` : <span className={s.small}>No data</span>}
|
{ebacc[i] != null ? (
|
||||||
|
<>
|
||||||
|
<span className={s.big} style={{ fontSize: '1.1rem' }}>
|
||||||
|
{Math.round(ebacc[i] as number)}%
|
||||||
|
</span>{' '}
|
||||||
|
{anchorChip(ebacc[i], ebaccAnchor, 3)}
|
||||||
|
{ebaccAnchor != null && (
|
||||||
|
<span className={s.small}>England average {Math.round(ebaccAnchor)}%</span>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<span className={s.small}>No data</span>
|
||||||
|
)}
|
||||||
</Cell>
|
</Cell>
|
||||||
))}
|
))}
|
||||||
</SectionGrid>
|
</SectionGrid>
|
||||||
@@ -216,6 +274,24 @@ export function CompareAcademics({
|
|||||||
const national = nationalAverages?.primary;
|
const national = nationalAverages?.primary;
|
||||||
const disadvantaged = latestValues(data, urns, 'rwm_expected_disadvantaged_pct');
|
const disadvantaged = latestValues(data, urns, 'rwm_expected_disadvantaged_pct');
|
||||||
const disadvantagedAnchor = benchmarks?.primary?.disadvantaged_rwm_expected_pct ?? null;
|
const disadvantagedAnchor = benchmarks?.primary?.disadvantaged_rwm_expected_pct ?? null;
|
||||||
|
// Cohort size behind the disadvantaged figure (spec §8.5): these are small
|
||||||
|
// groups where single pupils move the percentage — show roughly how many
|
||||||
|
// pupils the figure rests on. Taken from the SAME yearly row that supplies
|
||||||
|
// the displayed percentage: resolving eligible_pupils and the
|
||||||
|
// disadvantaged share independently could mix years and misstate the
|
||||||
|
// cohort behind the figure.
|
||||||
|
const cohorts = urns.map((urn) => {
|
||||||
|
const rows = data[String(urn)]?.yearly_data ?? [];
|
||||||
|
for (let i = rows.length - 1; i >= 0; i--) {
|
||||||
|
const row = rows[i];
|
||||||
|
if (row.rwm_expected_disadvantaged_pct != null) {
|
||||||
|
if (row.eligible_pupils == null || row.disadvantaged_pct == null) return null;
|
||||||
|
const cohort = Math.round((row.eligible_pupils * row.disadvantaged_pct) / 100);
|
||||||
|
return cohort > 0 ? cohort : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section
|
<Section
|
||||||
@@ -268,6 +344,9 @@ export function CompareAcademics({
|
|||||||
<span className={s.big} style={{ fontSize: '1.1rem' }}>
|
<span className={s.big} style={{ fontSize: '1.1rem' }}>
|
||||||
{Math.round(value)}%
|
{Math.round(value)}%
|
||||||
</span>{' '}
|
</span>{' '}
|
||||||
|
{cohorts[i] != null && (
|
||||||
|
<span className={s.small}>of ~{cohorts[i]} disadvantaged pupils</span>
|
||||||
|
)}{' '}
|
||||||
{disadvantagedAnchor != null && (
|
{disadvantagedAnchor != null && (
|
||||||
<Chip tone={verdict(value, disadvantagedAnchor, 5) === 'below' ? 'warn' : 'good'}>
|
<Chip tone={verdict(value, disadvantagedAnchor, 5) === 'below' ? 'warn' : 'good'}>
|
||||||
{verdict(value, disadvantagedAnchor, 5) === 'above' &&
|
{verdict(value, disadvantagedAnchor, 5) === 'above' &&
|
||||||
|
|||||||
@@ -7,19 +7,25 @@
|
|||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { summariseAdmissions } from '@/lib/compareLogic';
|
import { admissionsForPhase, summariseAdmissions } from '@/lib/compareLogic';
|
||||||
import type { ComparisonData, School } from '@/lib/types';
|
import type { ComparisonData, School } from '@/lib/types';
|
||||||
import { CHART_COLORS } from '@/lib/utils';
|
import { CHART_COLORS } from '@/lib/utils';
|
||||||
import { Cell, Chip, RowLabel, Section, SectionGrid, sectionStyles as s } from './sectionShared';
|
import { Cell, Chip, Measure, Section, SectionGrid, sectionStyles as s } from './sectionShared';
|
||||||
|
|
||||||
export function CompareAdmissions({
|
export function CompareAdmissions({
|
||||||
schools,
|
schools,
|
||||||
data,
|
data,
|
||||||
|
isSecondary = false,
|
||||||
}: {
|
}: {
|
||||||
schools: School[];
|
schools: School[];
|
||||||
data: Record<string, ComparisonData>;
|
data: Record<string, ComparisonData>;
|
||||||
|
isSecondary?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const rows = schools.map((school) => data[String(school.urn)]?.admissions ?? null);
|
// Admissions rounds are phase-specific: an all-through school's Year 7
|
||||||
|
// round must never stand in for Reception on the primary tab (and vice
|
||||||
|
// versa) — beside pure primaries it reads as Reception odds.
|
||||||
|
const rows = schools.map((school) => admissionsForPhase(data[String(school.urn)], isSecondary));
|
||||||
|
const roundLabel = isSecondary ? 'Year 7' : 'Reception';
|
||||||
const anyData = rows.some(Boolean);
|
const anyData = rows.some(Boolean);
|
||||||
const entryYear = rows.find(Boolean)?.year;
|
const entryYear = rows.find(Boolean)?.year;
|
||||||
const entryLabel = entryYear
|
const entryLabel = entryYear
|
||||||
@@ -28,7 +34,10 @@ export function CompareAdmissions({
|
|||||||
|
|
||||||
if (!anyData) {
|
if (!anyData) {
|
||||||
return (
|
return (
|
||||||
<Section title="Getting a place" how="No admissions data is available for these schools yet.">
|
<Section
|
||||||
|
title="Getting a place"
|
||||||
|
how={`No ${roundLabel} admissions data is available for these schools yet.`}
|
||||||
|
>
|
||||||
<></>
|
<></>
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
@@ -49,9 +58,10 @@ export function CompareAdmissions({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SectionGrid schools={schools}>
|
<SectionGrid schools={schools}>
|
||||||
<RowLabel tip="How many application forms named the school at any preference rank — not the number of families competing head-to-head for a place.">
|
<Measure
|
||||||
Interest in the school
|
tip="How many application forms named the school at any preference rank — not the number of families competing head-to-head for a place."
|
||||||
</RowLabel>
|
label="Interest in the school"
|
||||||
|
>
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const a = rows[i];
|
const a = rows[i];
|
||||||
return (
|
return (
|
||||||
@@ -62,13 +72,17 @@ export function CompareAdmissions({
|
|||||||
<strong>{a.places_offered.toLocaleString('en-GB')}</strong> places
|
<strong>{a.places_offered.toLocaleString('en-GB')}</strong> places
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<span className={s.small}>No data</span>
|
<span className={s.small}>
|
||||||
|
We don't hold {roundLabel} admissions data for this school
|
||||||
|
</span>
|
||||||
)}
|
)}
|
||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<RowLabel>First-choice families offered a place</RowLabel>
|
</Measure>
|
||||||
|
|
||||||
|
<Measure label="First-choice families offered a place">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const summary = summariseAdmissions(rows[i]);
|
const summary = summariseAdmissions(rows[i]);
|
||||||
return (
|
return (
|
||||||
@@ -95,19 +109,34 @@ export function CompareAdmissions({
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<RowLabel>What this means</RowLabel>
|
</Measure>
|
||||||
|
|
||||||
|
<Measure label="What this means">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const a = rows[i];
|
const a = rows[i];
|
||||||
const summary = summariseAdmissions(a);
|
const summary = summariseAdmissions(a);
|
||||||
|
const info = data[String(school.urn)]?.school_info;
|
||||||
|
const selective = (info?.admissions_policy ?? '').toLowerCase() === 'selective';
|
||||||
|
const faith =
|
||||||
|
!!info?.religious_denomination &&
|
||||||
|
!/^(none|does not apply|not applicable)$/i.test(info.religious_denomination);
|
||||||
let text: string | null = null;
|
let text: string | null = null;
|
||||||
if (summary.firstPrefPct != null) {
|
if (summary.firstPrefPct != null) {
|
||||||
if (summary.firstPrefPct >= 100) {
|
if (selective) {
|
||||||
|
// Selective schools: the entrance test decides, whatever the
|
||||||
|
// offer percentage looks like — never the distance template.
|
||||||
|
text =
|
||||||
|
'Entry is by entrance test — the school is selective; distance and preference rank don’t decide places.';
|
||||||
|
} else if (summary.firstPrefPct >= 100) {
|
||||||
text = `Every family who put ${school.school_name} first got a place.`;
|
text = `Every family who put ${school.school_name} first got a place.`;
|
||||||
} else if (summary.firstPrefPct >= 90) {
|
} else if (summary.firstPrefPct >= 90) {
|
||||||
text = `Nearly every family who put ${school.school_name} first got a place.`;
|
text = `Nearly every family who put ${school.school_name} first got a place.`;
|
||||||
} else if (a?.oversubscribed) {
|
} else if (a?.oversubscribed) {
|
||||||
text =
|
text = isSecondary
|
||||||
'More first-choice applications than places — check the school’s admission criteria (for most non-faith primaries, distance decides).';
|
? faith
|
||||||
|
? 'More first-choice applications than places — check the school’s admission criteria (faith-based criteria may apply).'
|
||||||
|
: 'More first-choice applications than places — check the school’s admission criteria (catchment or distance often decides, but criteria vary).'
|
||||||
|
: 'More first-choice applications than places — check the school’s admission criteria (for most non-faith primaries, distance decides).';
|
||||||
} else {
|
} else {
|
||||||
text = `${summary.firstPrefPct}% of first-choice families received an offer.`;
|
text = `${summary.firstPrefPct}% of first-choice families received an offer.`;
|
||||||
}
|
}
|
||||||
@@ -118,6 +147,7 @@ export function CompareAdmissions({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
</SectionGrid>
|
</SectionGrid>
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
admissionsForPhase,
|
||||||
latestValues,
|
latestValues,
|
||||||
ofstedDisplay,
|
ofstedDisplay,
|
||||||
summariseAdmissions,
|
summariseAdmissions,
|
||||||
@@ -15,7 +16,7 @@ import {
|
|||||||
type ReportCardSummary,
|
type ReportCardSummary,
|
||||||
} from '@/lib/compareLogic';
|
} from '@/lib/compareLogic';
|
||||||
import type { Benchmarks, ComparisonData, NationalAverages, School } from '@/lib/types';
|
import type { Benchmarks, ComparisonData, NationalAverages, School } from '@/lib/types';
|
||||||
import { Cell, Chip, RowLabel, Section, SectionGrid, sectionStyles as s } from './sectionShared';
|
import { Cell, Chip, Measure, Section, SectionGrid, sectionStyles as s } from './sectionShared';
|
||||||
|
|
||||||
function ReportCardChips({ summary }: { summary: ReportCardSummary }) {
|
function ReportCardChips({ summary }: { summary: ReportCardSummary }) {
|
||||||
return (
|
return (
|
||||||
@@ -47,14 +48,16 @@ export function CompareAtAGlance({
|
|||||||
data,
|
data,
|
||||||
nationalAverages,
|
nationalAverages,
|
||||||
benchmarks,
|
benchmarks,
|
||||||
|
isSecondary: propIsSecondary,
|
||||||
}: {
|
}: {
|
||||||
schools: School[];
|
schools: School[];
|
||||||
data: Record<string, ComparisonData>;
|
data: Record<string, ComparisonData>;
|
||||||
nationalAverages?: NationalAverages;
|
nationalAverages?: NationalAverages;
|
||||||
benchmarks?: Benchmarks;
|
benchmarks?: Benchmarks;
|
||||||
|
isSecondary?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const urns = schools.map((school) => school.urn);
|
const urns = schools.map((school) => school.urn);
|
||||||
const isSecondary = schools.some(
|
const isSecondary = propIsSecondary !== undefined ? propIsSecondary : schools.some(
|
||||||
(school) => data[String(school.urn)]?.school_info?.attainment_8_score != null,
|
(school) => data[String(school.urn)]?.school_info?.attainment_8_score != null,
|
||||||
);
|
);
|
||||||
const headlineKey = isSecondary ? 'attainment_8_score' : 'rwm_expected_pct';
|
const headlineKey = isSecondary ? 'attainment_8_score' : 'rwm_expected_pct';
|
||||||
@@ -69,7 +72,7 @@ export function CompareAtAGlance({
|
|||||||
return (
|
return (
|
||||||
<Section title="At a glance" how="The short version — each row below is explained in its own section further down.">
|
<Section title="At a glance" how="The short version — each row below is explained in its own section further down.">
|
||||||
<SectionGrid schools={schools}>
|
<SectionGrid schools={schools}>
|
||||||
<RowLabel>Latest Ofsted inspection</RowLabel>
|
<Measure label="Latest Ofsted inspection">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const display = ofstedDisplay(data[String(school.urn)]?.ofsted);
|
const display = ofstedDisplay(data[String(school.urn)]?.ofsted);
|
||||||
return (
|
return (
|
||||||
@@ -83,20 +86,28 @@ export function CompareAtAGlance({
|
|||||||
{display.carriedForward && <span className={s.small}>Grade carried forward</span>}
|
{display.carriedForward && <span className={s.small}>Grade carried forward</span>}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{display.kind === 'transitional' && (
|
||||||
|
<>
|
||||||
|
<span className={s.badge} style={{ backgroundColor: '#e2e8f0', color: '#475569' }}>
|
||||||
|
No overall grade
|
||||||
|
</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>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel
|
<Measure
|
||||||
tip={
|
tip={
|
||||||
isSecondary
|
isSecondary
|
||||||
? 'Average Attainment 8 score across GCSE subjects (latest year).'
|
? 'Average Attainment 8 score across GCSE subjects (latest year).'
|
||||||
: '% of Year 6 pupils reaching the expected standard in reading, writing and maths (latest year).'
|
: '% of Year 6 pupils reaching the expected standard in reading, writing and maths (latest year).'
|
||||||
}
|
}
|
||||||
|
label={isSecondary ? 'Attainment 8 score' : 'Children reaching the expected standard'}
|
||||||
>
|
>
|
||||||
{isSecondary ? 'Attainment 8 score' : 'Children reaching the expected standard'}
|
|
||||||
</RowLabel>
|
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const value = headlineValues[i];
|
const value = headlineValues[i];
|
||||||
return (
|
return (
|
||||||
@@ -131,10 +142,15 @@ export function CompareAtAGlance({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel>Getting a place</RowLabel>
|
<Measure label="Getting a place">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const summary = summariseAdmissions(data[String(school.urn)]?.admissions);
|
// Phase-matched round only — an all-through school's Year 7 round
|
||||||
|
// must not masquerade as Reception odds on the primary tab.
|
||||||
|
const summary = summariseAdmissions(
|
||||||
|
admissionsForPhase(data[String(school.urn)], isSecondary),
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
{summary.chip ? (
|
{summary.chip ? (
|
||||||
@@ -148,13 +164,20 @@ export function CompareAtAGlance({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel>Size</RowLabel>
|
<Measure label="Size">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const census = data[String(school.urn)]?.census;
|
const census = data[String(school.urn)]?.census;
|
||||||
const pupils = census?.total_pupils ?? school.total_pupils ?? null;
|
const pupils = census?.total_pupils ?? school.total_pupils ?? null;
|
||||||
|
// An all-through school's roll covers every age group, so judging
|
||||||
|
// it against the single-phase median ("Much larger than average")
|
||||||
|
// is meaningless — label the roll honestly instead.
|
||||||
|
const isAllThrough = /all.?through/i.test(school.phase ?? '');
|
||||||
let sizeNote: string | null = null;
|
let sizeNote: string | null = null;
|
||||||
if (pupils != null && medianPupils != null) {
|
if (isAllThrough) {
|
||||||
|
sizeNote = 'Whole-school roll (all-through, all ages)';
|
||||||
|
} else if (pupils != null && medianPupils != null) {
|
||||||
if (pupils >= medianPupils * 1.5) sizeNote = 'Much larger than average';
|
if (pupils >= medianPupils * 1.5) sizeNote = 'Much larger than average';
|
||||||
else if (pupils >= medianPupils * 1.1) sizeNote = 'Larger than average';
|
else if (pupils >= medianPupils * 1.1) sizeNote = 'Larger than average';
|
||||||
else if (pupils <= medianPupils * 0.66) sizeNote = 'Much smaller than average';
|
else if (pupils <= medianPupils * 0.66) sizeNote = 'Much smaller than average';
|
||||||
@@ -174,6 +197,7 @@ export function CompareAtAGlance({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
</SectionGrid>
|
</SectionGrid>
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
import { verdict } from '@/lib/compareLogic';
|
import { verdict } from '@/lib/compareLogic';
|
||||||
import type { Benchmarks, ComparisonData, School } from '@/lib/types';
|
import type { Benchmarks, ComparisonData, School } from '@/lib/types';
|
||||||
import { Cell, Chip, RowLabel, Section, SectionGrid, sectionStyles as s } from './sectionShared';
|
import { Cell, Chip, Measure, Section, SectionGrid, sectionStyles as s } from './sectionShared';
|
||||||
|
|
||||||
function pctSplit(part: number | null | undefined, total: number | null | undefined): string | null {
|
function pctSplit(part: number | null | undefined, total: number | null | undefined): string | null {
|
||||||
if (part == null || total == null || total === 0) return null;
|
if (part == null || total == null || total === 0) return null;
|
||||||
@@ -20,35 +20,56 @@ export function CompareCommunity({
|
|||||||
schools,
|
schools,
|
||||||
data,
|
data,
|
||||||
benchmarks,
|
benchmarks,
|
||||||
|
isSecondary: propIsSecondary,
|
||||||
}: {
|
}: {
|
||||||
schools: School[];
|
schools: School[];
|
||||||
data: Record<string, ComparisonData>;
|
data: Record<string, ComparisonData>;
|
||||||
benchmarks?: Benchmarks;
|
benchmarks?: Benchmarks;
|
||||||
|
isSecondary?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const isSecondary = schools.some(
|
const isSecondary = propIsSecondary !== undefined ? propIsSecondary : schools.some(
|
||||||
(school) => data[String(school.urn)]?.school_info?.attainment_8_score != null,
|
(school) => data[String(school.urn)]?.school_info?.attainment_8_score != null,
|
||||||
);
|
);
|
||||||
const bench = isSecondary ? benchmarks?.secondary : benchmarks?.primary;
|
const bench = isSecondary ? benchmarks?.secondary : benchmarks?.primary;
|
||||||
|
|
||||||
const fsmChip = (value: number | null) => {
|
const fsmChip = (value: number | null) => {
|
||||||
if (value == null || bench?.disadvantaged_pct == null) return null;
|
// FSM is anchored only against a real FSM benchmark (census-sourced,
|
||||||
const v = verdict(value, bench.disadvantaged_pct, 3);
|
// pupil-weighted). disadvantaged_pct is a different measure (FSM6+CLA)
|
||||||
|
// — never fall back across definitions; no anchor means no chip.
|
||||||
|
const anchor = bench?.fsm_pct ?? null;
|
||||||
|
if (value == null || anchor == null) return null;
|
||||||
|
const v = verdict(value, anchor, 3);
|
||||||
return (
|
return (
|
||||||
<Chip tone="neutral">
|
<Chip tone="neutral">
|
||||||
{v === 'above' && 'Above the state-school average'}
|
{v === 'above' && `Above the state-school average (${Math.round(anchor)}%)`}
|
||||||
{v === 'close' && 'About the state-school average'}
|
{v === 'close' && `About the state-school average (${Math.round(anchor)}%)`}
|
||||||
{v === 'below' && 'Below the state-school average'}
|
{v === 'below' && `Below the state-school average (${Math.round(anchor)}%)`}
|
||||||
</Chip>
|
</Chip>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const anyAllThrough = schools.some((school) => /all.?through/i.test(school.phase ?? ''));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section
|
<Section
|
||||||
title="Who goes there"
|
title="Who goes there"
|
||||||
how="The school's community, from the latest school census. State-school averages are computed from our dataset and shown for context — there's no “right” number here."
|
how={
|
||||||
|
<>
|
||||||
|
The school's community, from the latest school census. State-school averages are
|
||||||
|
computed from our dataset and shown for context — there's no “right”
|
||||||
|
number here.
|
||||||
|
{anyAllThrough && (
|
||||||
|
<>
|
||||||
|
{' '}
|
||||||
|
For all-through schools these figures cover the whole school, all ages — not just
|
||||||
|
the {isSecondary ? 'secondary' : 'primary'} phase.
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<SectionGrid schools={schools}>
|
<SectionGrid schools={schools}>
|
||||||
<RowLabel>Pupils on roll</RowLabel>
|
<Measure label="Pupils on roll">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const info = data[String(school.urn)]?.school_info as (School & { gias_total_pupils?: number | null; capacity?: number | null }) | undefined;
|
const info = data[String(school.urn)]?.school_info as (School & { gias_total_pupils?: number | null; capacity?: number | null }) | undefined;
|
||||||
const census = data[String(school.urn)]?.census;
|
const census = data[String(school.urn)]?.census;
|
||||||
@@ -74,8 +95,9 @@ export function CompareCommunity({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel>Girls / boys</RowLabel>
|
<Measure label="Girls / boys">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const census = data[String(school.urn)]?.census;
|
const census = data[String(school.urn)]?.census;
|
||||||
const girls = pctSplit(census?.female_pupils, census?.total_pupils);
|
const girls = pctSplit(census?.female_pupils, census?.total_pupils);
|
||||||
@@ -86,10 +108,12 @@ export function CompareCommunity({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel tip="% of pupils eligible for free school meals — a common measure of how many pupils come from lower-income families. Benchmark computed across state schools in our dataset.">
|
<Measure
|
||||||
Free school meals
|
tip="% of pupils eligible for free school meals — a common measure of how many pupils come from lower-income families. Benchmark computed across state schools in our dataset."
|
||||||
</RowLabel>
|
label="Free school meals"
|
||||||
|
>
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const fsm = data[String(school.urn)]?.census?.fsm_pct ?? null;
|
const fsm = data[String(school.urn)]?.census?.fsm_pct ?? null;
|
||||||
return (
|
return (
|
||||||
@@ -104,10 +128,12 @@ export function CompareCommunity({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel tip="% of pupils whose first language is known or believed to be other than English. State-school average computed from our dataset.">
|
<Measure
|
||||||
English as an additional language
|
tip="% of pupils whose first language is known or believed to be other than English. State-school average computed from our dataset."
|
||||||
</RowLabel>
|
label="English as an additional language"
|
||||||
|
>
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const eal = data[String(school.urn)]?.census?.eal_pct ?? null;
|
const eal = data[String(school.urn)]?.census?.eal_pct ?? null;
|
||||||
return (
|
return (
|
||||||
@@ -116,10 +142,12 @@ export function CompareCommunity({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel tip="% of pupils receiving SEN support (not including EHC plans). A high figure can mean the school hosts specialist provision — often a strength, not a warning sign. State-school average computed from our dataset.">
|
<Measure
|
||||||
Extra learning support (SEN)
|
tip="% of pupils receiving SEN support (not including EHC plans). A high figure can mean the school hosts specialist provision — often a strength, not a warning sign. State-school average computed from our dataset."
|
||||||
</RowLabel>
|
label="Extra learning support (SEN)"
|
||||||
|
>
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const rows = data[String(school.urn)]?.yearly_data ?? [];
|
const rows = data[String(school.urn)]?.yearly_data ?? [];
|
||||||
let sen: number | null = null;
|
let sen: number | null = null;
|
||||||
@@ -143,8 +171,9 @@ export function CompareCommunity({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel>Faith character</RowLabel>
|
<Measure label="Faith character">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const info = data[String(school.urn)]?.school_info;
|
const info = data[String(school.urn)]?.school_info;
|
||||||
const faith = info?.religious_denomination;
|
const faith = info?.religious_denomination;
|
||||||
@@ -155,8 +184,9 @@ export function CompareCommunity({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel>Ages</RowLabel>
|
<Measure label="Ages">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const info = data[String(school.urn)]?.school_info;
|
const info = data[String(school.urn)]?.school_info;
|
||||||
return (
|
return (
|
||||||
@@ -165,8 +195,9 @@ export function CompareCommunity({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel>Run by</RowLabel>
|
<Measure label="Run by">
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const info = data[String(school.urn)]?.school_info;
|
const info = data[String(school.urn)]?.school_info;
|
||||||
const trust = info?.trust_name;
|
const trust = info?.trust_name;
|
||||||
@@ -177,6 +208,7 @@ export function CompareCommunity({
|
|||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
</SectionGrid>
|
</SectionGrid>
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
type OfstedDisplay,
|
type OfstedDisplay,
|
||||||
} from '@/lib/compareLogic';
|
} from '@/lib/compareLogic';
|
||||||
import type { ComparisonData, OfstedInspection, School } from '@/lib/types';
|
import type { ComparisonData, OfstedInspection, School } from '@/lib/types';
|
||||||
import { Cell, Chip, RowLabel, 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'> = {
|
||||||
1: 'good',
|
1: 'good',
|
||||||
@@ -51,6 +51,18 @@ function ResultCell({ display }: { display: OfstedDisplay }) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (display.kind === 'transitional') {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span className={s.badge} style={{ backgroundColor: '#e2e8f0', color: '#475569' }}>
|
||||||
|
No overall grade
|
||||||
|
</span>
|
||||||
|
<span className={s.small}>
|
||||||
|
Inspected under transitional framework (sub-judgements only)
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<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}`}>
|
||||||
@@ -96,14 +108,21 @@ function JudgementDetailCell({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const legacyAreas: Array<[string, number | null]> = [
|
const legacyAreas: Array<[string, number | null | undefined]> = [
|
||||||
['Quality of education', ofsted.quality_of_education],
|
['Quality of education', ofsted.quality_of_education],
|
||||||
['Behaviour & attitudes', ofsted.behaviour_attitudes],
|
['Behaviour & attitudes', ofsted.behaviour_attitudes],
|
||||||
['Personal development', ofsted.personal_development],
|
['Personal development', ofsted.personal_development],
|
||||||
['Leadership & management', ofsted.leadership_management],
|
['Leadership & management', ofsted.leadership_management],
|
||||||
['Early years provision', ofsted.early_years_provision],
|
['Early years provision', ofsted.early_years_provision],
|
||||||
|
['Sixth form provision', ofsted.sixth_form_provision],
|
||||||
];
|
];
|
||||||
const published = legacyAreas.filter(([, grade]) => grade != null);
|
// Only real Ofsted grades (1–4) are judgements. The MI file uses sentinel
|
||||||
|
// codes for "not applicable / no judgement" (9, and 0/8 variants) — those
|
||||||
|
// must never render as a rating chip.
|
||||||
|
const published = legacyAreas.filter(
|
||||||
|
(entry): entry is [string, number] =>
|
||||||
|
entry[1] != null && entry[1] >= 1 && entry[1] <= 4,
|
||||||
|
);
|
||||||
|
|
||||||
if (published.length === 0) {
|
if (published.length === 0) {
|
||||||
return (
|
return (
|
||||||
@@ -157,28 +176,40 @@ export function CompareOfsted({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<SectionGrid schools={schools}>
|
<SectionGrid schools={schools}>
|
||||||
<RowLabel>Result</RowLabel>
|
<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]} />
|
||||||
</Cell>
|
</Cell>
|
||||||
))}
|
))}
|
||||||
|
</Measure>
|
||||||
|
|
||||||
<RowLabel>Inspected</RowLabel>
|
<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;
|
||||||
const age = yearsSince(ofsted?.inspection_date ?? null);
|
// A report card is dated by its OWN inspection date. The legacy
|
||||||
|
// inspection_date belongs to an older inspection and must never
|
||||||
|
// be shown against a report card (report cards exist only from
|
||||||
|
// Nov 2025).
|
||||||
|
const dateIso =
|
||||||
|
displays[i].kind === 'report_card'
|
||||||
|
? ofsted?.rc_inspection_date ?? null
|
||||||
|
: ofsted?.inspection_date ?? null;
|
||||||
|
const age = yearsSince(dateIso);
|
||||||
return (
|
return (
|
||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
{formatInspectionDate(ofsted?.inspection_date ?? null)}{' '}
|
{formatInspectionDate(dateIso)}{' '}
|
||||||
{age != null && age > 4 && <Chip tone="neutral">4+ years ago</Chip>}
|
{age != null && age > 4 && <Chip tone="neutral">4+ years ago</Chip>}
|
||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<RowLabel tip="Older-style inspections: one rating per judgement area, where published. New-style inspections: the full report card, one rating per area of school life.">
|
</Measure>
|
||||||
Judgement detail
|
|
||||||
</RowLabel>
|
<Measure
|
||||||
|
tip="Older-style inspections: one rating per judgement area, where published. New-style inspections: the full report card, one rating per area of school life."
|
||||||
|
label="Judgement detail"
|
||||||
|
>
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const ofsted = data[String(school.urn)]?.ofsted;
|
const ofsted = data[String(school.urn)]?.ofsted;
|
||||||
return (
|
return (
|
||||||
@@ -196,21 +227,34 @@ export function CompareOfsted({
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<RowLabel tip="Links to the school's page on ofsted.gov.uk, where all its inspection reports are listed.">
|
</Measure>
|
||||||
Ofsted page
|
|
||||||
</RowLabel>
|
<Measure
|
||||||
|
tip="Links to the school's page on ofsted.gov.uk, where all its inspection reports are listed."
|
||||||
|
label="Ofsted page"
|
||||||
|
>
|
||||||
{schools.map((school, i) => {
|
{schools.map((school, i) => {
|
||||||
const url =
|
const url =
|
||||||
data[String(school.urn)]?.ofsted?.ofsted_page_url ??
|
data[String(school.urn)]?.ofsted?.ofsted_page_url ??
|
||||||
`https://reports.ofsted.gov.uk/provider/21/${school.urn}`;
|
`https://reports.ofsted.gov.uk/provider/21/${school.urn}`;
|
||||||
return (
|
return (
|
||||||
<Cell key={school.urn} school={school} index={i}>
|
<Cell key={school.urn} school={school} index={i}>
|
||||||
<a className={s.link} href={url} target="_blank" rel="noopener noreferrer">
|
{/* Short visible label to save space on mobile (the coloured
|
||||||
{school.school_name}'s Ofsted page →
|
school name already leads the row); the full name stays in
|
||||||
|
aria-label so screen readers can tell the links apart. */}
|
||||||
|
<a
|
||||||
|
className={s.link}
|
||||||
|
href={url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label={`${school.school_name}'s Ofsted page`}
|
||||||
|
>
|
||||||
|
Ofsted page →
|
||||||
</a>
|
</a>
|
||||||
</Cell>
|
</Cell>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
</Measure>
|
||||||
</SectionGrid>
|
</SectionGrid>
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -60,37 +60,10 @@
|
|||||||
margin: 0 0 1rem;
|
margin: 0 0 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ComparisonChart owns its own canvas height now (a definite px value per
|
||||||
|
breakpoint), with the mobile chip legend above and the gap note below it
|
||||||
|
flowing at natural size. This box therefore only needs to not constrain
|
||||||
|
that height — no fixed height, or the note would again eat the plot. */
|
||||||
.chartBox {
|
.chartBox {
|
||||||
min-height: 320px;
|
min-height: 0;
|
||||||
}
|
|
||||||
|
|
||||||
.tableWrapper {
|
|
||||||
overflow-x: auto;
|
|
||||||
margin-top: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table {
|
|
||||||
width: 100%;
|
|
||||||
border-collapse: collapse;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.table th,
|
|
||||||
.table td {
|
|
||||||
text-align: left;
|
|
||||||
padding: 0.6rem 0.75rem;
|
|
||||||
border-bottom: 1px solid var(--border-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
.table th {
|
|
||||||
background: var(--bg-secondary);
|
|
||||||
font-size: 0.8rem;
|
|
||||||
text-transform: uppercase;
|
|
||||||
letter-spacing: 0.03em;
|
|
||||||
color: var(--text-secondary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.yearCell {
|
|
||||||
font-weight: 600;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Explore trends — the full grouped metric catalogue (nothing from the old
|
* Explore trends — the full grouped metric catalogue (nothing from the old
|
||||||
* compare page is lost; spec §4's tier 3) driving the year-by-year chart
|
* compare page is lost; spec §4's tier 3) driving the year-by-year chart with
|
||||||
* with its England reference line, plus the year-by-year table. Progress
|
* its England reference line. Matches the mockup: a measure picker and the
|
||||||
* metrics carry CI-based bands for the years DfE published them.
|
* chart only (no data table).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
|
|
||||||
import { progressBand } from '@/lib/compareLogic';
|
|
||||||
import type { ComparisonData, MetricDefinition, NationalAverages, School } from '@/lib/types';
|
import type { ComparisonData, MetricDefinition, NationalAverages, School } from '@/lib/types';
|
||||||
import { formatAcademicYear, formatMetricValue, metricKind } from '@/lib/utils';
|
|
||||||
import { track } from '@/lib/analytics';
|
import { track } from '@/lib/analytics';
|
||||||
import { Chip, Section, sectionStyles as s } from './sectionShared';
|
import { Section } from './sectionShared';
|
||||||
import styles from './TrendsExplorer.module.css';
|
import styles from './TrendsExplorer.module.css';
|
||||||
|
|
||||||
const ComparisonChart = dynamic(
|
const ComparisonChart = dynamic(
|
||||||
@@ -40,14 +38,6 @@ const SECONDARY_OPTGROUPS: { label: string; category: string }[] = [
|
|||||||
export const PRIMARY_CATEGORIES = PRIMARY_OPTGROUPS.map((g) => g.category);
|
export const PRIMARY_CATEGORIES = PRIMARY_OPTGROUPS.map((g) => g.category);
|
||||||
export const SECONDARY_CATEGORIES = SECONDARY_OPTGROUPS.map((g) => g.category);
|
export const SECONDARY_CATEGORIES = SECONDARY_OPTGROUPS.map((g) => g.category);
|
||||||
|
|
||||||
const PROGRESS_CI: Record<string, [string, string]> = {
|
|
||||||
reading_progress: ['reading_progress_lower_ci', 'reading_progress_upper_ci'],
|
|
||||||
writing_progress: ['writing_progress_lower_ci', 'writing_progress_upper_ci'],
|
|
||||||
maths_progress: ['maths_progress_lower_ci', 'maths_progress_upper_ci'],
|
|
||||||
};
|
|
||||||
|
|
||||||
const BAND_LABEL = { above: 'Above average', average: 'Average', below: 'Below average' } as const;
|
|
||||||
|
|
||||||
export function TrendsExplorer({
|
export function TrendsExplorer({
|
||||||
schools,
|
schools,
|
||||||
data,
|
data,
|
||||||
@@ -78,21 +68,11 @@ export function TrendsExplorer({
|
|||||||
nationalByYear[entry.year] = block?.[metric] ?? null;
|
nationalByYear[entry.year] = block?.[metric] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const years = [
|
|
||||||
...new Set(
|
|
||||||
schools.flatMap(
|
|
||||||
(school) => data[String(school.urn)]?.yearly_data.map((d) => Math.trunc(d.year)) ?? [],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
].sort((a, b) => a - b);
|
|
||||||
|
|
||||||
const handleMetricChange = (next: string) => {
|
const handleMetricChange = (next: string) => {
|
||||||
track('compare_metric_changed', { metric: next, phase: isPrimaryPhase ? 'primary' : 'secondary' });
|
track('compare_metric_changed', { metric: next, phase: isPrimaryPhase ? 'primary' : 'secondary' });
|
||||||
onMetricChange(next);
|
onMetricChange(next);
|
||||||
};
|
};
|
||||||
|
|
||||||
const ciKeys = PROGRESS_CI[metric];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section
|
<Section
|
||||||
title="Explore trends"
|
title="Explore trends"
|
||||||
@@ -128,8 +108,7 @@ export function TrendsExplorer({
|
|||||||
{metric.includes('progress') && (
|
{metric.includes('progress') && (
|
||||||
<p className={styles.progressNote}>
|
<p className={styles.progressNote}>
|
||||||
Progress scores measure pupils' progress from KS1 to KS2. A score of 0 equals the
|
Progress scores measure pupils' progress from KS1 to KS2. A score of 0 equals the
|
||||||
national average. DfE stopped publishing KS2 progress after 2022/23 (no KS1 baseline);
|
national average. DfE stopped publishing KS2 progress after 2022/23 (no KS1 baseline).
|
||||||
bands use DfE's confidence intervals, not the raw score alone.
|
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -140,54 +119,9 @@ export function TrendsExplorer({
|
|||||||
metric={metric}
|
metric={metric}
|
||||||
metricLabel={metricLabel}
|
metricLabel={metricLabel}
|
||||||
nationalByYear={nationalByYear}
|
nationalByYear={nationalByYear}
|
||||||
|
isSecondary={!isPrimaryPhase}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{years.length > 0 && (
|
|
||||||
<div className={styles.tableWrapper}>
|
|
||||||
<table className={styles.table}>
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>Year</th>
|
|
||||||
{schools.map((school) => (
|
|
||||||
<th key={school.urn}>{school.school_name}</th>
|
|
||||||
))}
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
{years.map((year) => (
|
|
||||||
<tr key={year}>
|
|
||||||
<td className={styles.yearCell}>{formatAcademicYear(year)}</td>
|
|
||||||
{schools.map((school) => {
|
|
||||||
const row = data[String(school.urn)]?.yearly_data.find(
|
|
||||||
(d) => Math.trunc(d.year) === year,
|
|
||||||
) as (Record<string, unknown> & { year: number }) | undefined;
|
|
||||||
const value = row?.[metric];
|
|
||||||
if (typeof value !== 'number') return <td key={school.urn}>–</td>;
|
|
||||||
const band = ciKeys
|
|
||||||
? progressBand(
|
|
||||||
value,
|
|
||||||
(row?.[ciKeys[0]] as number | null) ?? null,
|
|
||||||
(row?.[ciKeys[1]] as number | null) ?? null,
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
return (
|
|
||||||
<td key={school.urn}>
|
|
||||||
{formatMetricValue(value, metricKind(metric))}{' '}
|
|
||||||
{band && (
|
|
||||||
<Chip tone={band === 'above' ? 'good' : band === 'below' ? 'warn' : 'neutral'}>
|
|
||||||
{BAND_LABEL[band]}
|
|
||||||
</Chip>
|
|
||||||
)}
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
))}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</details>
|
</details>
|
||||||
</Section>
|
</Section>
|
||||||
|
|||||||
@@ -31,43 +31,76 @@
|
|||||||
margin-top: 1.25rem;
|
margin-top: 1.25rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Mobile base: each measure is a card; each cell is a school row led by a
|
||||||
|
colour dot + short name. `display: contents` at ≥761px dissolves the card
|
||||||
|
back into the shared grid. */
|
||||||
|
.measure {
|
||||||
|
background: var(--bg-card);
|
||||||
|
border: 1px solid var(--border-light);
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: var(--shadow-soft);
|
||||||
|
padding: 0.75rem 0.85rem;
|
||||||
|
margin-bottom: 0.6rem;
|
||||||
|
}
|
||||||
|
|
||||||
.rowLabel {
|
.rowLabel {
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--text-secondary);
|
color: var(--text-primary);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.35rem;
|
gap: 0.35rem;
|
||||||
background: var(--bg-secondary);
|
padding: 0 0 0.1rem;
|
||||||
border-radius: 6px;
|
|
||||||
padding: 0.4rem 0.6rem;
|
|
||||||
margin-top: 0.8rem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.cell {
|
.cell {
|
||||||
padding: 0.4rem 0.6rem;
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 0.35rem 0.5rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
border-top: 1px solid var(--border-light);
|
||||||
|
margin-top: 0.5rem;
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cell::before {
|
/* The school name gets its own full-width line above the value — real
|
||||||
content: attr(data-school);
|
school names are long and varied, so a fixed-width name column truncated
|
||||||
display: block;
|
them ("Our Lady Queen of H…") or crowded the value. */
|
||||||
font-size: 0.72rem;
|
.cellTag {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
flex-basis: 100%;
|
||||||
|
/* Slightly larger than the values below it so the school each row belongs
|
||||||
|
to is easy to read on mobile (hidden on desktop, where the column header
|
||||||
|
names the school). */
|
||||||
|
font-size: 0.9rem;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--sc, var(--text-muted));
|
color: var(--sc, var(--text-secondary));
|
||||||
|
margin-bottom: 0.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cellDot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--dot, var(--text-muted));
|
||||||
|
flex: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.big {
|
.big {
|
||||||
font-size: 1.35rem;
|
font-size: 1.05rem;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
font-variant-numeric: tabular-nums;
|
font-variant-numeric: tabular-nums;
|
||||||
}
|
}
|
||||||
|
|
||||||
.small {
|
.small {
|
||||||
display: block;
|
display: block;
|
||||||
|
flex-basis: 100%;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
margin-top: 0.1rem;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.chip {
|
.chip {
|
||||||
@@ -159,6 +192,7 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 0.3rem;
|
gap: 0.3rem;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
flex-basis: 100%;
|
||||||
margin-top: 0.3rem;
|
margin-top: 0.3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,20 +231,37 @@
|
|||||||
gap: 0 0.75rem;
|
gap: 0 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Dissolve the per-measure card so its label + cells become grid items of
|
||||||
|
.grid, keeping columns aligned across every measure. */
|
||||||
|
.measure {
|
||||||
|
display: contents;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cellTag {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
.rowLabel {
|
.rowLabel {
|
||||||
background: none;
|
color: var(--text-secondary);
|
||||||
border-radius: 0;
|
|
||||||
margin-top: 0;
|
|
||||||
padding: 0.85rem 0.5rem 0.85rem 0;
|
padding: 0.85rem 0.5rem 0.85rem 0;
|
||||||
border-bottom: 1px solid var(--border-light);
|
border-bottom: 1px solid var(--border-light);
|
||||||
}
|
}
|
||||||
|
|
||||||
.cell {
|
.cell {
|
||||||
|
display: block;
|
||||||
padding: 0.85rem 0.25rem;
|
padding: 0.85rem 0.25rem;
|
||||||
|
border-top: none;
|
||||||
border-bottom: 1px solid var(--border-light);
|
border-bottom: 1px solid var(--border-light);
|
||||||
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cell::before {
|
.big {
|
||||||
content: none;
|
font-size: 1.35rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.small {
|
||||||
|
flex-basis: auto;
|
||||||
|
padding-left: 0;
|
||||||
|
margin-top: 0.1rem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import type { CSSProperties, ReactNode } from 'react';
|
import type { CSSProperties, ReactNode } from 'react';
|
||||||
|
|
||||||
import type { School } from '@/lib/types';
|
import type { School } from '@/lib/types';
|
||||||
import { CHART_TEXT_COLORS } from '@/lib/utils';
|
import { CHART_COLORS, CHART_TEXT_COLORS, shortName } from '@/lib/utils';
|
||||||
import styles from './compareSections.module.css';
|
import styles from './compareSections.module.css';
|
||||||
|
|
||||||
export function Section({
|
export function Section({
|
||||||
@@ -61,6 +61,29 @@ export function RowLabel({ children, tip }: { children: ReactNode; tip?: string
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One measure = its row label plus a cell per school. `display: contents` on
|
||||||
|
* desktop (see CSS) makes these flow into the section grid as if this wrapper
|
||||||
|
* weren't here, keeping columns aligned across measures; on mobile the wrapper
|
||||||
|
* becomes a card so each measure reads as its own block.
|
||||||
|
*/
|
||||||
|
export function Measure({
|
||||||
|
label,
|
||||||
|
tip,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
label: ReactNode;
|
||||||
|
tip?: string;
|
||||||
|
children: ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className={styles.measure}>
|
||||||
|
<RowLabel tip={tip}>{label}</RowLabel>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function Cell({
|
export function Cell({
|
||||||
school,
|
school,
|
||||||
index,
|
index,
|
||||||
@@ -73,9 +96,19 @@ export function Cell({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={styles.cell}
|
className={styles.cell}
|
||||||
data-school={school.school_name}
|
style={
|
||||||
style={{ '--sc': CHART_TEXT_COLORS[index % CHART_TEXT_COLORS.length] } as CSSProperties}
|
{
|
||||||
|
'--sc': CHART_TEXT_COLORS[index % CHART_TEXT_COLORS.length],
|
||||||
|
'--dot': CHART_COLORS[index % CHART_COLORS.length],
|
||||||
|
} as CSSProperties
|
||||||
|
}
|
||||||
>
|
>
|
||||||
|
{/* Mobile-only per-school tag (dot + short name); hidden on desktop,
|
||||||
|
where the column header identifies the school. */}
|
||||||
|
<span className={styles.cellTag}>
|
||||||
|
<span className={styles.cellDot} aria-hidden="true" />
|
||||||
|
{shortName(school.school_name)}
|
||||||
|
</span>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ export interface CompareChart {
|
|||||||
/** True when England published a 2021/22 figure but no school has one —
|
/** True when England published a 2021/22 figure but no school has one —
|
||||||
* the UI shows: "DfE didn't publish school-level figures for 2021/22". */
|
* the UI shows: "DfE didn't publish school-level figures for 2021/22". */
|
||||||
showUnpublished202122Note: boolean;
|
showUnpublished202122Note: boolean;
|
||||||
|
/** Years where the England overlay has a value but no school does — the
|
||||||
|
* chart shows a dashed-line-only stretch that needs explaining (KS2 and
|
||||||
|
* KS4 have different honest explanations, so the component owns the copy). */
|
||||||
|
englandOnlyYears: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildCompareChart(
|
export function buildCompareChart(
|
||||||
@@ -92,11 +96,12 @@ export function buildCompareChart(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const idx202122 = years.indexOf(202122);
|
const englandOnlyYears = years.filter(
|
||||||
const showUnpublished202122Note =
|
(year, i) =>
|
||||||
idx202122 >= 0 &&
|
englandDataset?.data[i] != null && schoolDatasets.every((ds) => ds.data[i] == null),
|
||||||
englandDataset?.data[idx202122] != null &&
|
);
|
||||||
schoolDatasets.every((ds) => ds.data[idx202122] == null);
|
|
||||||
|
|
||||||
return { years, schoolDatasets, englandDataset, showUnpublished202122Note };
|
const showUnpublished202122Note = englandOnlyYears.includes(202122);
|
||||||
|
|
||||||
|
return { years, schoolDatasets, englandDataset, showUnpublished202122Note, englandOnlyYears };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ export type OfstedDisplay =
|
|||||||
| { kind: 'none' }
|
| { kind: 'none' }
|
||||||
| { kind: 'graded'; grade: number; gradeLabel: string; carriedForward: false }
|
| { kind: 'graded'; grade: number; gradeLabel: string; carriedForward: false }
|
||||||
| { kind: 'carried_forward'; grade: number; gradeLabel: string; carriedForward: true }
|
| { kind: 'carried_forward'; grade: number; gradeLabel: string; carriedForward: true }
|
||||||
|
| { kind: 'transitional' }
|
||||||
| { kind: 'report_card'; summary: ReportCardSummary };
|
| { kind: 'report_card'; summary: ReportCardSummary };
|
||||||
|
|
||||||
export function ofstedDisplay(
|
export function ofstedDisplay(
|
||||||
@@ -117,7 +118,12 @@ export function ofstedDisplay(
|
|||||||
|
|
||||||
const grade = ofsted.overall_effectiveness;
|
const grade = ofsted.overall_effectiveness;
|
||||||
const gradeLabel = grade != null ? OFSTED_LEGACY_GRADES[grade] : undefined;
|
const gradeLabel = grade != null ? OFSTED_LEGACY_GRADES[grade] : undefined;
|
||||||
if (grade == null || gradeLabel === undefined) return { kind: 'none' };
|
if (grade == null || gradeLabel === undefined) {
|
||||||
|
if (ofsted.inspection_date) {
|
||||||
|
return { kind: 'transitional' };
|
||||||
|
}
|
||||||
|
return { kind: 'none' };
|
||||||
|
}
|
||||||
|
|
||||||
if (ofsted.grade_source === 'ungraded_carried_forward') {
|
if (ofsted.grade_source === 'ungraded_carried_forward') {
|
||||||
return { kind: 'carried_forward', grade, gradeLabel, carriedForward: true };
|
return { kind: 'carried_forward', grade, gradeLabel, carriedForward: true };
|
||||||
@@ -137,6 +143,41 @@ export interface AdmissionsSummary {
|
|||||||
interest: string | null;
|
interest: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pick the admissions round for the ACTIVE phase tab. An all-through school
|
||||||
|
* can carry only a Year 7 (Secondary) round — rendering that beside pure
|
||||||
|
* primaries' Reception rounds made 433-forms-for-173-places read as
|
||||||
|
* Reception odds. Rows matching the target phase win (latest year first);
|
||||||
|
* rows tagged with the OTHER phase are never substituted. Untagged rows
|
||||||
|
* (legacy data, no school_phase) are used only when no row carries a phase.
|
||||||
|
*/
|
||||||
|
export function admissionsForPhase(
|
||||||
|
data:
|
||||||
|
| { admissions?: SchoolAdmissions | null; admissions_history?: SchoolAdmissions[] }
|
||||||
|
| null
|
||||||
|
| undefined,
|
||||||
|
isSecondary: boolean,
|
||||||
|
): SchoolAdmissions | null {
|
||||||
|
if (!data) return null;
|
||||||
|
const rows: SchoolAdmissions[] = [
|
||||||
|
...(data.admissions_history ?? []),
|
||||||
|
...(data.admissions ? [data.admissions] : []),
|
||||||
|
];
|
||||||
|
if (rows.length === 0) return null;
|
||||||
|
const target = isSecondary ? 'secondary' : 'primary';
|
||||||
|
const byYearDesc = (a: SchoolAdmissions, b: SchoolAdmissions) => (b.year ?? 0) - (a.year ?? 0);
|
||||||
|
|
||||||
|
const matching = rows
|
||||||
|
.filter((r) => r.school_phase?.toLowerCase() === target)
|
||||||
|
.sort(byYearDesc);
|
||||||
|
if (matching.length > 0) return matching[0];
|
||||||
|
|
||||||
|
const tagged = rows.some((r) => r.school_phase != null);
|
||||||
|
if (!tagged) return [...rows].sort(byYearDesc)[0];
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export function summariseAdmissions(
|
export function summariseAdmissions(
|
||||||
a: SchoolAdmissions | null | undefined,
|
a: SchoolAdmissions | null | undefined,
|
||||||
): AdmissionsSummary {
|
): AdmissionsSummary {
|
||||||
@@ -151,6 +192,12 @@ export function summariseAdmissions(
|
|||||||
if (pct != null) {
|
if (pct != null) {
|
||||||
if (pct >= 100) {
|
if (pct >= 100) {
|
||||||
chip = { tone: 'good', text: 'All first choices offered' };
|
chip = { tone: 'good', text: 'All first choices offered' };
|
||||||
|
} else if (pct < 50) {
|
||||||
|
// Banded, not one blanket chip: "Over 1 in 4" on a school where more
|
||||||
|
// than half missed out understated the worst cases by half.
|
||||||
|
chip = { tone: 'warn', text: 'More than half of first choices missed out' };
|
||||||
|
} else if (pct < 67) {
|
||||||
|
chip = { tone: 'warn', text: 'About 1 in 3 first choices missed out' };
|
||||||
} else if (pct < 75) {
|
} else if (pct < 75) {
|
||||||
chip = { tone: 'warn', text: 'Over 1 in 4 first choices missed out' };
|
chip = { tone: 'warn', text: 'Over 1 in 4 first choices missed out' };
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ export interface School {
|
|||||||
|
|
||||||
// Ofsted (for list view — summary only)
|
// Ofsted (for list view — summary only)
|
||||||
ofsted_grade?: 1 | 2 | 3 | 4 | null;
|
ofsted_grade?: 1 | 2 | 3 | 4 | null;
|
||||||
|
/** 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. */
|
||||||
|
ofsted_rc_date?: string | null;
|
||||||
ofsted_date?: string | null;
|
ofsted_date?: string | null;
|
||||||
ofsted_framework?: string | null;
|
ofsted_framework?: string | null;
|
||||||
}
|
}
|
||||||
@@ -79,12 +82,16 @@ export interface School {
|
|||||||
export interface OfstedInspection {
|
export interface OfstedInspection {
|
||||||
framework: 'OEIF' | 'ReportCard' | null;
|
framework: 'OEIF' | 'ReportCard' | null;
|
||||||
inspection_date: string | null;
|
inspection_date: string | null;
|
||||||
|
/** Start date of the report-card inspection itself (Nov 2025+); null otherwise. */
|
||||||
|
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)
|
||||||
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;
|
||||||
personal_development: number | null;
|
personal_development: number | null;
|
||||||
|
/** Sixth-form judgement where applicable; sentinel 9 = not applicable. */
|
||||||
|
sixth_form_provision?: number | null;
|
||||||
leadership_management: number | null;
|
leadership_management: number | null;
|
||||||
early_years_provision: number | null;
|
early_years_provision: number | null;
|
||||||
previous_overall: number | null;
|
previous_overall: number | null;
|
||||||
@@ -357,6 +364,7 @@ export interface BenchmarkBlock {
|
|||||||
eal_pct: number | null;
|
eal_pct: number | null;
|
||||||
sen_support_pct: number | null;
|
sen_support_pct: number | null;
|
||||||
disadvantaged_pct: number | null;
|
disadvantaged_pct: number | null;
|
||||||
|
fsm_pct?: number | null;
|
||||||
median_pupils: number | null;
|
median_pupils: number | null;
|
||||||
/** Primary only — weighted by cohort size. */
|
/** Primary only — weighted by cohort size. */
|
||||||
disadvantaged_rwm_expected_pct?: number | null;
|
disadvantaged_rwm_expected_pct?: number | null;
|
||||||
|
|||||||
+68
-6
@@ -59,6 +59,24 @@ export function truncate(text: string, maxLength: number): string {
|
|||||||
return text.slice(0, maxLength).trim() + '...';
|
return text.slice(0, maxLength).trim() + '...';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A compact school label for tight spaces (mobile compare rows, chip bars):
|
||||||
|
* drop the trailing establishment-type words so "Barclay Primary School" →
|
||||||
|
* "Barclay", "St Mary's Catholic Primary School" → "St Mary's". Falls back to
|
||||||
|
* a length-capped truncation for names that don't carry a type suffix.
|
||||||
|
*/
|
||||||
|
export function shortName(name: string, maxLength = 32): string {
|
||||||
|
let s = name
|
||||||
|
.replace(
|
||||||
|
/\s+(primary|junior|infant|nursery|community|foundation|catholic|academy|school|college)\b.*$/i,
|
||||||
|
'',
|
||||||
|
)
|
||||||
|
.trim();
|
||||||
|
if (!s) s = name;
|
||||||
|
if (s.length > maxLength) s = s.slice(0, maxLength - 1).trim() + '…';
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a school's age range for display, e.g. "3-11" → "Ages 3–11".
|
* Format a school's age range for display, e.g. "3-11" → "Ages 3–11".
|
||||||
* Display-only — leaves the raw `age_range` field (used for sixth-form
|
* Display-only — leaves the raw `age_range` field (used for sixth-form
|
||||||
@@ -662,6 +680,42 @@ export function buildSchoolSummary(
|
|||||||
return parts.join(', ') + '.';
|
return parts.join(', ') + '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── Legacy (OEIF) sub-judgement areas ────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface OfstedLegacyArea {
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The published OEIF sub-judgement areas for the legacy Ofsted layout, in
|
||||||
|
* display order. Only real grades (1–4) are returned: Ofsted's sentinel
|
||||||
|
* codes for "not applicable / no judgement" (9, and any 0/8 variants) and
|
||||||
|
* nulls are filtered out, so a cryptic "9" never renders as a rating.
|
||||||
|
* Sixth Form provision is included where a school has one — it was
|
||||||
|
* previously dropped from the detail grid entirely.
|
||||||
|
*/
|
||||||
|
export function ofstedLegacyAreas(ofsted: {
|
||||||
|
quality_of_education?: number | null;
|
||||||
|
behaviour_attitudes?: number | null;
|
||||||
|
personal_development?: number | null;
|
||||||
|
leadership_management?: number | null;
|
||||||
|
early_years_provision?: number | null;
|
||||||
|
sixth_form_provision?: number | null;
|
||||||
|
}): OfstedLegacyArea[] {
|
||||||
|
const candidates: Array<[string, number | null | undefined]> = [
|
||||||
|
['Quality of Teaching', ofsted.quality_of_education],
|
||||||
|
['Behaviour in School', ofsted.behaviour_attitudes],
|
||||||
|
["Pupils' Wider Development", ofsted.personal_development],
|
||||||
|
['School Leadership', ofsted.leadership_management],
|
||||||
|
['Early Years (Reception)', ofsted.early_years_provision],
|
||||||
|
['Sixth Form', ofsted.sixth_form_provision],
|
||||||
|
];
|
||||||
|
return candidates
|
||||||
|
.filter((c): c is [string, number] => c[1] != null && c[1] >= 1 && c[1] <= 4)
|
||||||
|
.map(([label, value]) => ({ label, value }));
|
||||||
|
}
|
||||||
|
|
||||||
// ─── List-level Ofsted badge ──────────────────────────────────────────────────
|
// ─── List-level Ofsted badge ──────────────────────────────────────────────────
|
||||||
|
|
||||||
export interface OfstedListBadge {
|
export interface OfstedListBadge {
|
||||||
@@ -673,9 +727,12 @@ export interface OfstedListBadge {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the Ofsted badge for a school card in the list/map view.
|
* Build the Ofsted badge for a school card in the list/map view.
|
||||||
* Three states:
|
* States, in priority order:
|
||||||
|
* - Report Card school (ofsted_rc_date set): "Report Card · YYYY" in purple.
|
||||||
|
* 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
|
||||||
|
* event grouping ("Schools - S5"), never "ReportCard".
|
||||||
* - OEIF school (ofsted_grade set): grade word + year, colour-keyed
|
* - OEIF school (ofsted_grade set): grade word + year, colour-keyed
|
||||||
* - ReportCard school (ofsted_framework === 'ReportCard'): "Report Card · YYYY" in purple
|
|
||||||
* - Inspected without an overall grade (OEIF post-Sept-2024, where Ofsted no
|
* - Inspected without an overall grade (OEIF post-Sept-2024, where Ofsted no
|
||||||
* longer issues an overall judgement): "Inspected · YYYY" — mirrors the
|
* longer issues an overall judgement): "Inspected · YYYY" — mirrors the
|
||||||
* detail page's hero chip so a school never reads as both inspected and
|
* detail page's hero chip so a school never reads as both inspected and
|
||||||
@@ -686,7 +743,16 @@ export function buildOfstedListBadge(school: {
|
|||||||
ofsted_grade?: 1 | 2 | 3 | 4 | null;
|
ofsted_grade?: 1 | 2 | 3 | 4 | null;
|
||||||
ofsted_date?: string | null;
|
ofsted_date?: string | null;
|
||||||
ofsted_framework?: string | null;
|
ofsted_framework?: string | null;
|
||||||
|
ofsted_rc_date?: string | null;
|
||||||
}): OfstedListBadge {
|
}): OfstedListBadge {
|
||||||
|
// A report card wins over any carried-forward legacy grade — signalled by
|
||||||
|
// ofsted_rc_date. ofsted_framework is the raw event grouping ("Schools -
|
||||||
|
// S5"), never "ReportCard", so it can't detect report cards.
|
||||||
|
if (school.ofsted_rc_date) {
|
||||||
|
const rcYear = new Date(school.ofsted_rc_date).getFullYear();
|
||||||
|
return { label: `Report Card · ${rcYear}`, cssClass: 'ofstedRc' };
|
||||||
|
}
|
||||||
|
|
||||||
const year = school.ofsted_date
|
const year = school.ofsted_date
|
||||||
? new Date(school.ofsted_date).getFullYear()
|
? new Date(school.ofsted_date).getFullYear()
|
||||||
: null;
|
: null;
|
||||||
@@ -705,10 +771,6 @@ export function buildOfstedListBadge(school: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (school.ofsted_framework === 'ReportCard') {
|
|
||||||
return { label: `Report Card${yearStr}`, cssClass: 'ofstedRc' };
|
|
||||||
}
|
|
||||||
|
|
||||||
// An inspection is on record (date or framework present) but carries no
|
// An inspection is on record (date or framework present) but carries no
|
||||||
// overall grade — a post-Sept-2024 OEIF inspection. Distinct from a school
|
// overall grade — a post-Sept-2024 OEIF inspection. Distinct from a school
|
||||||
// that has genuinely never been inspected.
|
// that has genuinely never been inspected.
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ with DAG(
|
|||||||
|
|
||||||
dbt_build_ees = BashOperator(
|
dbt_build_ees = BashOperator(
|
||||||
task_id="dbt_build",
|
task_id="dbt_build",
|
||||||
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_ees_ks2+ stg_legacy_ks2+ stg_ees_ks4+ stg_legacy_ks4+ stg_ees_census+ stg_ees_admissions+ stg_ees_ks2_national+",
|
bash_command=f"cd {PIPELINE_DIR}/transform && {DBT_BIN} build --profiles-dir . --target production --select stg_ees_ks2+ stg_legacy_ks2+ stg_ees_ks4+ stg_legacy_ks4+ stg_ees_census+ stg_ees_admissions+ stg_ees_ks2_national+ stg_ees_ks4_national+",
|
||||||
)
|
)
|
||||||
|
|
||||||
sync_typesense_ees = BashOperator(
|
sync_typesense_ees = BashOperator(
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ plugins:
|
|||||||
- name: mi_url
|
- name: mi_url
|
||||||
kind: string
|
kind: string
|
||||||
description: Ofsted Management Information download URL
|
description: Ofsted Management Information download URL
|
||||||
|
- name: independent_mi_url
|
||||||
|
kind: string
|
||||||
|
description: Ofsted Independent Schools Management Information download URL
|
||||||
|
|
||||||
- name: tap-uk-fbit
|
- name: tap-uk-fbit
|
||||||
namespace: uk_fbit
|
namespace: uk_fbit
|
||||||
|
|||||||
@@ -564,6 +564,74 @@ class EESKs2NationalStream(Stream):
|
|||||||
yield record
|
yield record
|
||||||
|
|
||||||
|
|
||||||
|
# ── KS4 National Headlines (national level only — one row per year) ──────────
|
||||||
|
# Dataset: "National characteristics summary data" (Key stage 4 performance).
|
||||||
|
# Official England state-funded headline measures, 2018/19 → latest.
|
||||||
|
# Suppressed values ('z', 'x') → NULL downstream. Progress 8 is legitimately
|
||||||
|
# absent in years with no KS2 baseline (e.g. 2024/25) — that is DfE policy,
|
||||||
|
# not missing data.
|
||||||
|
|
||||||
|
_KS4_NATIONAL_CSV_URL = (
|
||||||
|
"https://explore-education-statistics.service.gov.uk/data-catalogue/"
|
||||||
|
"data-set/1b649e16-01e8-435b-a814-56be2faf9054/csv"
|
||||||
|
)
|
||||||
|
|
||||||
|
_KS4_NATIONAL_COL_MAP = {
|
||||||
|
"attainment8_average": "attainment_8_score",
|
||||||
|
"progress8_average": "progress_8_score",
|
||||||
|
"engmath_94_percent": "english_maths_standard_pass_pct",
|
||||||
|
"engmath_95_percent": "english_maths_strong_pass_pct",
|
||||||
|
"ebacc_entering_percent": "ebacc_entry_pct",
|
||||||
|
"ebacc_94_percent": "ebacc_standard_pass_pct",
|
||||||
|
"ebacc_95_percent": "ebacc_strong_pass_pct",
|
||||||
|
"ebacc_aps_average": "ebacc_avg_score",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EESKs4NationalStream(Stream):
|
||||||
|
"""National KS4 headline averages — one row per academic year.
|
||||||
|
|
||||||
|
Filters to geographic_level == 'National', establishment_type_group ==
|
||||||
|
'All state-funded', breakdown_topic == 'Total', breakdown == 'Total'
|
||||||
|
so only the England-wide all-pupils row per year is emitted.
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = "ees_ks4_national"
|
||||||
|
primary_keys = ["time_period"]
|
||||||
|
replication_key = None
|
||||||
|
|
||||||
|
schema = th.PropertiesList(
|
||||||
|
th.Property("time_period", th.StringType, required=True),
|
||||||
|
*[th.Property(out, th.StringType) for out in _KS4_NATIONAL_COL_MAP.values()],
|
||||||
|
).to_dict()
|
||||||
|
|
||||||
|
def get_records(self, context):
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
self.logger.info("Downloading KS4 national headlines: %s", _KS4_NATIONAL_CSV_URL)
|
||||||
|
resp = requests.get(_KS4_NATIONAL_CSV_URL, timeout=60)
|
||||||
|
resp.raise_for_status()
|
||||||
|
|
||||||
|
df = pd.read_csv(io.BytesIO(resp.content), dtype=str, keep_default_na=False)
|
||||||
|
df.columns = [c.strip().lower() for c in df.columns]
|
||||||
|
|
||||||
|
for col, want in [
|
||||||
|
("geographic_level", "national"),
|
||||||
|
("establishment_type_group", "all state-funded"),
|
||||||
|
("breakdown_topic", "total"),
|
||||||
|
("breakdown", "total"),
|
||||||
|
]:
|
||||||
|
if col in df.columns:
|
||||||
|
df = df[df[col].str.strip().str.lower() == want]
|
||||||
|
|
||||||
|
self.logger.info("Emitting %d national KS4 rows", len(df))
|
||||||
|
for _, row in df.iterrows():
|
||||||
|
record = {"time_period": row.get("time_period", "").strip()}
|
||||||
|
for csv_col, field in _KS4_NATIONAL_COL_MAP.items():
|
||||||
|
record[field] = row.get(csv_col, "").strip()
|
||||||
|
yield record
|
||||||
|
|
||||||
|
|
||||||
# ── Legacy KS2 (pre-COVID wide format from DfE performance tables) ────────────
|
# ── Legacy KS2 (pre-COVID wide format from DfE performance tables) ────────────
|
||||||
# The DfE "Compare School Performance" site published school-level KS2 CSVs
|
# The DfE "Compare School Performance" site published school-level KS2 CSVs
|
||||||
# in a wide format (one row per school, ~300 columns). EES only has school-level
|
# in a wide format (one row per school, ~300 columns). EES only has school-level
|
||||||
@@ -903,6 +971,7 @@ class TapUKEES(Tap):
|
|||||||
LegacyKS2Stream(self),
|
LegacyKS2Stream(self),
|
||||||
LegacyKS4Stream(self),
|
LegacyKS4Stream(self),
|
||||||
EESKs2NationalStream(self),
|
EESKs2NationalStream(self),
|
||||||
|
EESKs4NationalStream(self),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
import io
|
import io
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -14,20 +15,28 @@ GOV_UK_PAGE = (
|
|||||||
"monthly-management-information-ofsteds-school-inspections-outcomes"
|
"monthly-management-information-ofsteds-school-inspections-outcomes"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
INDEPENDENT_GOV_UK_PAGE = (
|
||||||
|
"https://www.gov.uk/government/statistical-data-sets/"
|
||||||
|
"non-association-independent-schools-inspections-and-outcomes-management-information"
|
||||||
|
)
|
||||||
|
|
||||||
# Column name → internal field, in priority order (first match wins).
|
# Column name → internal field, in priority order (first match wins).
|
||||||
# Handles both current and older file formats.
|
# Handles both current and older file formats.
|
||||||
COLUMN_PRIORITY = {
|
COLUMN_PRIORITY = {
|
||||||
"urn": ["URN", "Urn", "urn"],
|
"urn": ["URN", "Urn", "urn"],
|
||||||
"inspection_date": [
|
"inspection_date": [
|
||||||
"Inspection start date of latest OEIF graded inspection",
|
"Inspection start date of latest OEIF graded inspection",
|
||||||
|
"Inspection start date of latest OEIF standard inspection",
|
||||||
"Inspection start date",
|
"Inspection start date",
|
||||||
"Inspection date",
|
"Inspection date",
|
||||||
],
|
],
|
||||||
"inspection_type": [
|
"inspection_type": [
|
||||||
"Inspection type of latest OEIF graded inspection",
|
"Inspection type of latest OEIF graded inspection",
|
||||||
|
"Inspection type of latest OEIF standard inspection",
|
||||||
"Inspection type",
|
"Inspection type",
|
||||||
],
|
],
|
||||||
"event_type_grouping": [
|
"event_type_grouping": [
|
||||||
|
"Event type grouping of latest OEIF standard inspection",
|
||||||
"Event type grouping",
|
"Event type grouping",
|
||||||
"Inspection type grouping",
|
"Inspection type grouping",
|
||||||
],
|
],
|
||||||
@@ -52,10 +61,12 @@ COLUMN_PRIORITY = {
|
|||||||
"Effectiveness of leadership and management",
|
"Effectiveness of leadership and management",
|
||||||
],
|
],
|
||||||
"early_years_provision": [
|
"early_years_provision": [
|
||||||
|
"Latest OEIF early years provision (where applicable)",
|
||||||
"Latest OEIF early years provision",
|
"Latest OEIF early years provision",
|
||||||
"Early years provision (where applicable)",
|
"Early years provision (where applicable)",
|
||||||
],
|
],
|
||||||
"sixth_form_provision": [
|
"sixth_form_provision": [
|
||||||
|
"Latest OEIF sixth form provision (where applicable)",
|
||||||
"Latest OEIF sixth form provision",
|
"Latest OEIF sixth form provision",
|
||||||
"Sixth form provision (where applicable)",
|
"Sixth form provision (where applicable)",
|
||||||
],
|
],
|
||||||
@@ -68,12 +79,7 @@ COLUMN_PRIORITY = {
|
|||||||
"ungraded_inspection_date": [
|
"ungraded_inspection_date": [
|
||||||
"Date of latest ungraded inspection",
|
"Date of latest ungraded inspection",
|
||||||
],
|
],
|
||||||
# Report Card fields (post-Nov 2025 framework). Confirmed verbatim MI
|
# Report Card fields (post-Nov 2025 framework).
|
||||||
# headers per diagnose_compare_gaps.py's Task 1(c) findings. No MI column
|
|
||||||
# currently exists for early-years or sixth-form report-card grades, so
|
|
||||||
# those two fields are deliberately omitted here (see schema below) --
|
|
||||||
# they stay absent from every record, same as the existing `report_url`
|
|
||||||
# pattern for fields with no COLUMN_PRIORITY entry.
|
|
||||||
"rc_safeguarding_met": ["Safeguarding standards"],
|
"rc_safeguarding_met": ["Safeguarding standards"],
|
||||||
"rc_inclusion": ["Inclusion"],
|
"rc_inclusion": ["Inclusion"],
|
||||||
"rc_curriculum_teaching": ["Curriculum and teaching"],
|
"rc_curriculum_teaching": ["Curriculum and teaching"],
|
||||||
@@ -81,20 +87,59 @@ COLUMN_PRIORITY = {
|
|||||||
"rc_attendance_behaviour": ["Attendance and behaviour"],
|
"rc_attendance_behaviour": ["Attendance and behaviour"],
|
||||||
"rc_personal_development": ["Personal development and wellbeing"],
|
"rc_personal_development": ["Personal development and wellbeing"],
|
||||||
"rc_leadership_governance": ["Leadership and governance"],
|
"rc_leadership_governance": ["Leadership and governance"],
|
||||||
|
"rc_early_years": ["Early years (where applicable)"],
|
||||||
|
"rc_sixth_form": ["Post-16 provision (where applicable)"],
|
||||||
|
# Date of the latest FULL inspection — in the renewed framework this is
|
||||||
|
# the report-card inspection's own start date (col "Inspection start
|
||||||
|
# date"), distinct from the legacy OEIF graded/ungraded dates above.
|
||||||
|
"rc_inspection_date": ["Inspection start date"],
|
||||||
|
"report_url": [
|
||||||
|
"Web Link (opens in new window)",
|
||||||
|
"Web link to Ofsted provider page",
|
||||||
|
"Web link",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def discover_csv_url() -> str | None:
|
def discover_csv_url() -> str | None:
|
||||||
"""Scrape GOV.UK page to find the latest MI CSV download link."""
|
"""Scrape GOV.UK page to find the latest MI CSV download link.
|
||||||
|
|
||||||
|
The page lists a decade of monthly files, oldest first — take the
|
||||||
|
newest 'latest inspections as at <date>' link by parsing its date,
|
||||||
|
never matches[0] (that is a 2017 file).
|
||||||
|
"""
|
||||||
resp = requests.get(GOV_UK_PAGE, timeout=30)
|
resp = requests.get(GOV_UK_PAGE, timeout=30)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
# Look for CSV attachment links
|
csv_links = re.findall(
|
||||||
matches = re.findall(
|
|
||||||
r'href="(https://assets\.publishing\.service\.gov\.uk/[^"]+\.csv)"',
|
r'href="(https://assets\.publishing\.service\.gov\.uk/[^"]+\.csv)"',
|
||||||
resp.text,
|
resp.text,
|
||||||
)
|
)
|
||||||
if matches:
|
|
||||||
return matches[0]
|
months = {
|
||||||
|
'january': 1, 'february': 2, 'march': 3, 'april': 4, 'may': 5, 'june': 6,
|
||||||
|
'july': 7, 'august': 8, 'september': 9, 'october': 10, 'november': 11, 'december': 12,
|
||||||
|
'jan': 1, 'feb': 2, 'mar': 3, 'apr': 4, 'jun': 6,
|
||||||
|
'jul': 7, 'aug': 8, 'sep': 9, 'oct': 10, 'nov': 11, 'dec': 12,
|
||||||
|
}
|
||||||
|
parsed_links = []
|
||||||
|
for link in csv_links:
|
||||||
|
normalized = link.lower().replace('-', '_')
|
||||||
|
if 'latest_inspections_as_at' not in normalized:
|
||||||
|
continue
|
||||||
|
match = re.search(r'as_at_(\d{1,2})_([a-z]+)_(\d{4})', normalized)
|
||||||
|
if match:
|
||||||
|
day, month_str, year = match.groups()
|
||||||
|
month = months.get(month_str)
|
||||||
|
if month:
|
||||||
|
try:
|
||||||
|
parsed_links.append((datetime(int(year), month, int(day)), link))
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
parsed_links.sort(reverse=True)
|
||||||
|
if parsed_links:
|
||||||
|
return parsed_links[0][1]
|
||||||
|
if csv_links:
|
||||||
|
return csv_links[-1]
|
||||||
# Fall back to ODS
|
# Fall back to ODS
|
||||||
matches = re.findall(
|
matches = re.findall(
|
||||||
r'href="(https://assets\.publishing\.service\.gov\.uk/[^"]+\.ods)"',
|
r'href="(https://assets\.publishing\.service\.gov\.uk/[^"]+\.ods)"',
|
||||||
@@ -103,6 +148,51 @@ def discover_csv_url() -> str | None:
|
|||||||
return matches[0] if matches else None
|
return matches[0] if matches else None
|
||||||
|
|
||||||
|
|
||||||
|
def discover_independent_csv_url() -> str | None:
|
||||||
|
"""Scrape GOV.UK page to find the latest independent schools MI CSV download link."""
|
||||||
|
resp = requests.get(INDEPENDENT_GOV_UK_PAGE, timeout=30)
|
||||||
|
resp.raise_for_status()
|
||||||
|
# Look for CSV attachment links
|
||||||
|
csv_links = re.findall(
|
||||||
|
r'href="(https://assets\.publishing\.service\.gov\.uk/[^"]+\.csv)"',
|
||||||
|
resp.text,
|
||||||
|
)
|
||||||
|
if not csv_links:
|
||||||
|
# Fall back to ODS
|
||||||
|
csv_links = re.findall(
|
||||||
|
r'href="(https://assets\.publishing\.service\.gov\.uk/[^"]+\.ods)"',
|
||||||
|
resp.text,
|
||||||
|
)
|
||||||
|
|
||||||
|
months = {
|
||||||
|
'january': 1, 'february': 2, 'march': 3, 'april': 4, 'may': 5, 'june': 6,
|
||||||
|
'july': 7, 'august': 8, 'september': 9, 'october': 10, 'november': 11, 'december': 12
|
||||||
|
}
|
||||||
|
|
||||||
|
parsed_links = []
|
||||||
|
for link in csv_links:
|
||||||
|
normalized_link = link.lower().replace('-', '_')
|
||||||
|
if 'most_recent' not in normalized_link:
|
||||||
|
continue
|
||||||
|
|
||||||
|
match = re.search(r'as_at_(\d{1,2})_([a-z]+)_(\d{4})', normalized_link)
|
||||||
|
if match:
|
||||||
|
day, month_str, year = match.groups()
|
||||||
|
month = months.get(month_str)
|
||||||
|
if month:
|
||||||
|
try:
|
||||||
|
dt = datetime(int(year), month, int(day))
|
||||||
|
parsed_links.append((dt, link))
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
|
||||||
|
parsed_links.sort(reverse=True)
|
||||||
|
if parsed_links:
|
||||||
|
return parsed_links[0][1]
|
||||||
|
|
||||||
|
return csv_links[0] if csv_links else None
|
||||||
|
|
||||||
|
|
||||||
class OfstedInspectionsStream(Stream):
|
class OfstedInspectionsStream(Stream):
|
||||||
"""Stream: Ofsted inspection records."""
|
"""Stream: Ofsted inspection records."""
|
||||||
|
|
||||||
@@ -131,10 +221,9 @@ class OfstedInspectionsStream(Stream):
|
|||||||
th.Property("rc_attendance_behaviour", th.StringType),
|
th.Property("rc_attendance_behaviour", th.StringType),
|
||||||
th.Property("rc_personal_development", th.StringType),
|
th.Property("rc_personal_development", th.StringType),
|
||||||
th.Property("rc_leadership_governance", th.StringType),
|
th.Property("rc_leadership_governance", th.StringType),
|
||||||
# No MI column exists for these yet; declared for forward
|
|
||||||
# compatibility with the mart schema, always emitted as absent/NULL.
|
|
||||||
th.Property("rc_early_years", th.StringType),
|
th.Property("rc_early_years", th.StringType),
|
||||||
th.Property("rc_sixth_form", th.StringType),
|
th.Property("rc_sixth_form", th.StringType),
|
||||||
|
th.Property("rc_inspection_date", th.StringType),
|
||||||
th.Property("report_url", th.StringType),
|
th.Property("report_url", th.StringType),
|
||||||
).to_dict()
|
).to_dict()
|
||||||
|
|
||||||
@@ -148,15 +237,8 @@ class OfstedInspectionsStream(Stream):
|
|||||||
break
|
break
|
||||||
return mapping
|
return mapping
|
||||||
|
|
||||||
def get_records(self, context):
|
def _fetch_and_parse_url(self, url: str, pd) -> list[dict]:
|
||||||
import pandas as pd
|
"""Download file and parse records."""
|
||||||
|
|
||||||
url = self.config.get("mi_url") or discover_csv_url()
|
|
||||||
if not url:
|
|
||||||
self.logger.error("Could not discover Ofsted MI download URL")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.logger.info("Downloading Ofsted MI: %s", url)
|
|
||||||
resp = requests.get(url, timeout=120)
|
resp = requests.get(url, timeout=120)
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
@@ -172,8 +254,6 @@ class OfstedInspectionsStream(Stream):
|
|||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
header_idx = 0
|
header_idx = 0
|
||||||
for i, line in enumerate(lines[:20]):
|
for i, line in enumerate(lines[:20]):
|
||||||
# Match lines where URN appears as a CSV field (start or after comma),
|
|
||||||
# not as a substring of words like "turn" or "return".
|
|
||||||
if re.search(r'(?:^|,)\s*URN\s*(?:,|$)', line):
|
if re.search(r'(?:^|,)\s*URN\s*(?:,|$)', line):
|
||||||
header_idx = i
|
header_idx = i
|
||||||
break
|
break
|
||||||
@@ -191,16 +271,38 @@ class OfstedInspectionsStream(Stream):
|
|||||||
for _, row in df.iterrows():
|
for _, row in df.iterrows():
|
||||||
record = {}
|
record = {}
|
||||||
for field, col in col_map.items():
|
for field, col in col_map.items():
|
||||||
record[field] = row.get(col, None)
|
val = row.get(col, None)
|
||||||
|
if pd.isna(val):
|
||||||
|
val = None
|
||||||
|
record[field] = val
|
||||||
|
|
||||||
# Cast URN
|
# Cast URN
|
||||||
try:
|
try:
|
||||||
record["urn"] = int(record["urn"])
|
record["urn"] = int(record.get("urn"))
|
||||||
except (ValueError, KeyError, TypeError):
|
except (ValueError, KeyError, TypeError):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
yield record
|
yield record
|
||||||
|
|
||||||
|
def get_records(self, context):
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
# 1. State-funded schools
|
||||||
|
state_url = self.config.get("mi_url") or discover_csv_url()
|
||||||
|
if state_url:
|
||||||
|
self.logger.info("Downloading Ofsted state-funded MI: %s", state_url)
|
||||||
|
yield from self._fetch_and_parse_url(state_url, pd)
|
||||||
|
else:
|
||||||
|
self.logger.error("Could not discover Ofsted state-funded MI download URL")
|
||||||
|
|
||||||
|
# 2. Independent schools
|
||||||
|
ind_url = self.config.get("independent_mi_url") or discover_independent_csv_url()
|
||||||
|
if ind_url:
|
||||||
|
self.logger.info("Downloading Ofsted independent MI: %s", ind_url)
|
||||||
|
yield from self._fetch_and_parse_url(ind_url, pd)
|
||||||
|
else:
|
||||||
|
self.logger.error("Could not discover Ofsted independent MI download URL")
|
||||||
|
|
||||||
|
|
||||||
class TapUKOfsted(Tap):
|
class TapUKOfsted(Tap):
|
||||||
"""Singer tap for UK Ofsted Management Information."""
|
"""Singer tap for UK Ofsted Management Information."""
|
||||||
@@ -209,6 +311,7 @@ class TapUKOfsted(Tap):
|
|||||||
|
|
||||||
config_jsonschema = th.PropertiesList(
|
config_jsonschema = th.PropertiesList(
|
||||||
th.Property("mi_url", th.StringType, description="Direct URL to Ofsted MI file"),
|
th.Property("mi_url", th.StringType, description="Direct URL to Ofsted MI file"),
|
||||||
|
th.Property("independent_mi_url", th.StringType, description="Direct URL to Ofsted Independent Schools MI file"),
|
||||||
).to_dict()
|
).to_dict()
|
||||||
|
|
||||||
def discover_streams(self):
|
def discover_streams(self):
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ select
|
|||||||
rc_leadership_governance,
|
rc_leadership_governance,
|
||||||
rc_early_years,
|
rc_early_years,
|
||||||
rc_sixth_form,
|
rc_sixth_form,
|
||||||
|
rc_inspection_date,
|
||||||
report_url
|
report_url
|
||||||
from ranked
|
from ranked
|
||||||
where rn = 1
|
where rn = 1
|
||||||
|
|||||||
@@ -133,6 +133,16 @@ models:
|
|||||||
- name: year
|
- name: year
|
||||||
tests: [not_null]
|
tests: [not_null]
|
||||||
|
|
||||||
|
- name: fact_census_benchmarks
|
||||||
|
description: >
|
||||||
|
State-school context benchmarks from the pupil census — one row per
|
||||||
|
phase (primary/secondary), latest census year. fsm_pct/eal_pct are
|
||||||
|
pupil-weighted means; consumers label them "state-school average
|
||||||
|
(computed from our dataset)", never "England average".
|
||||||
|
columns:
|
||||||
|
- name: phase
|
||||||
|
tests: [not_null, unique]
|
||||||
|
|
||||||
- name: fact_admissions
|
- name: fact_admissions
|
||||||
description: School admissions — one row per URN per year
|
description: School admissions — one row per URN per year
|
||||||
columns:
|
columns:
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
{{ config(materialized='table') }}
|
||||||
|
|
||||||
|
-- Mart: state-school context benchmarks from the pupil census — one row per
|
||||||
|
-- phase, latest census year. Computed at import time (never per request).
|
||||||
|
-- fsm_pct / eal_pct are pupil-weighted means, i.e. "what % of pupils", not
|
||||||
|
-- "the median school" — this matches how DfE quotes national FSM/EAL rates.
|
||||||
|
-- Consumers must label these "state-school average (computed from our
|
||||||
|
-- dataset)" (spec §8.6), never "England average".
|
||||||
|
|
||||||
|
with latest as (
|
||||||
|
select max(year) as year from {{ ref('fact_pupil_characteristics') }}
|
||||||
|
),
|
||||||
|
|
||||||
|
classified as (
|
||||||
|
select
|
||||||
|
case
|
||||||
|
when p.phase_type_grouping ilike '%primary%' then 'primary'
|
||||||
|
when p.phase_type_grouping ilike '%secondary%' then 'secondary'
|
||||||
|
end as phase,
|
||||||
|
p.total_pupils,
|
||||||
|
p.fsm_pct,
|
||||||
|
p.eal_pct,
|
||||||
|
l.year
|
||||||
|
from {{ ref('fact_pupil_characteristics') }} p
|
||||||
|
join latest l on p.year = l.year
|
||||||
|
where p.total_pupils is not null and p.total_pupils > 0
|
||||||
|
)
|
||||||
|
|
||||||
|
select
|
||||||
|
phase,
|
||||||
|
max(year) as year,
|
||||||
|
round((sum(fsm_pct * total_pupils) filter (where fsm_pct is not null)
|
||||||
|
/ nullif(sum(total_pupils) filter (where fsm_pct is not null), 0))::numeric, 1) as fsm_pct,
|
||||||
|
round((sum(eal_pct * total_pupils) filter (where eal_pct is not null)
|
||||||
|
/ nullif(sum(total_pupils) filter (where eal_pct is not null), 0))::numeric, 1) as eal_pct,
|
||||||
|
round(percentile_cont(0.5) within group (order by total_pupils))::integer as median_pupils
|
||||||
|
from classified
|
||||||
|
where phase is not null
|
||||||
|
group by phase
|
||||||
@@ -1,25 +1,22 @@
|
|||||||
{{ config(materialized='table') }}
|
{{ config(materialized='table') }}
|
||||||
|
|
||||||
-- Mart: Computed national KS4 averages — one row per academic year.
|
-- Mart: OFFICIAL DfE KS4 national headline averages — one row per academic
|
||||||
-- Unlike fact_ks2_national_averages (official DfE figures), DfE publishes no
|
-- year (England, state-funded, all pupils), from the EES national dataset.
|
||||||
-- KS4 national-headline dataset we ingest yet, so these are means computed
|
-- Replaces the previous unweighted school-level means, which were 7–15
|
||||||
-- across the state schools in our dataset. Computed once at build time so the
|
-- points off every headline measure and produced an arithmetically
|
||||||
-- API never has to aggregate the full performance table per request.
|
-- impossible national Progress 8. gcse_grade_91_pct has no official
|
||||||
-- Semantics match the API's previous per-request computation: rows where
|
-- national series and is NULL (schema kept for the API model).
|
||||||
-- attainment_8_score is non-null; per-column means ignore NULLs.
|
|
||||||
|
|
||||||
select
|
select
|
||||||
year,
|
year,
|
||||||
round(avg(attainment_8_score)::numeric, 2) as attainment_8_score,
|
attainment_8_score,
|
||||||
round(avg(progress_8_score)::numeric, 2) as progress_8_score,
|
progress_8_score,
|
||||||
round(avg(english_maths_standard_pass_pct)::numeric, 2) as english_maths_standard_pass_pct,
|
english_maths_standard_pass_pct,
|
||||||
round(avg(english_maths_strong_pass_pct)::numeric, 2) as english_maths_strong_pass_pct,
|
english_maths_strong_pass_pct,
|
||||||
round(avg(ebacc_entry_pct)::numeric, 2) as ebacc_entry_pct,
|
ebacc_entry_pct,
|
||||||
round(avg(ebacc_standard_pass_pct)::numeric, 2) as ebacc_standard_pass_pct,
|
ebacc_standard_pass_pct,
|
||||||
round(avg(ebacc_strong_pass_pct)::numeric, 2) as ebacc_strong_pass_pct,
|
ebacc_strong_pass_pct,
|
||||||
round(avg(ebacc_avg_score)::numeric, 2) as ebacc_avg_score,
|
ebacc_avg_score,
|
||||||
round(avg(gcse_grade_91_pct)::numeric, 2) as gcse_grade_91_pct
|
cast(null as double precision) as gcse_grade_91_pct
|
||||||
from {{ ref('fact_ks4_performance') }}
|
from {{ ref('stg_ees_ks4_national') }}
|
||||||
where attainment_8_score is not null
|
|
||||||
group by year
|
|
||||||
order by year
|
order by year
|
||||||
|
|||||||
@@ -23,5 +23,6 @@ select
|
|||||||
rc_leadership_governance,
|
rc_leadership_governance,
|
||||||
rc_early_years,
|
rc_early_years,
|
||||||
rc_sixth_form,
|
rc_sixth_form,
|
||||||
|
rc_inspection_date,
|
||||||
report_url
|
report_url
|
||||||
from {{ ref('stg_ofsted_inspections') }}
|
from {{ ref('stg_ofsted_inspections') }}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ sources:
|
|||||||
- name: ees_ks2_national
|
- name: ees_ks2_national
|
||||||
description: KS2 national headline averages from DfE EES data catalogue — one row per academic year
|
description: KS2 national headline averages from DfE EES data catalogue — one row per academic year
|
||||||
|
|
||||||
|
- name: ees_ks4_national
|
||||||
|
description: Official KS4 national headline averages from DfE EES data catalogue — one row per academic year
|
||||||
|
|
||||||
# Phonics: no school-level data on EES (only national/LA level)
|
# Phonics: no school-level data on EES (only national/LA level)
|
||||||
|
|
||||||
- name: fbit_finance
|
- name: fbit_finance
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{{ config(materialized='table') }}
|
||||||
|
|
||||||
|
-- Staging model: official DfE KS4 national headline averages — one row per
|
||||||
|
-- academic year (England, all state-funded, all pupils). Source: EES data
|
||||||
|
-- catalogue "National characteristics summary data". Suppressed values
|
||||||
|
-- ('z', 'x') are coerced to NULL by safe_numeric — Progress 8 is 'z' in
|
||||||
|
-- years with no KS2 baseline (e.g. 2024/25): legitimately unpublished.
|
||||||
|
|
||||||
|
select
|
||||||
|
cast(trim(time_period) as integer) as year,
|
||||||
|
{{ safe_numeric('attainment_8_score') }} as attainment_8_score,
|
||||||
|
{{ safe_numeric('progress_8_score') }} as progress_8_score,
|
||||||
|
{{ safe_numeric('english_maths_standard_pass_pct') }} as english_maths_standard_pass_pct,
|
||||||
|
{{ safe_numeric('english_maths_strong_pass_pct') }} as english_maths_strong_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_entry_pct') }} as ebacc_entry_pct,
|
||||||
|
{{ safe_numeric('ebacc_standard_pass_pct') }} as ebacc_standard_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_strong_pass_pct') }} as ebacc_strong_pass_pct,
|
||||||
|
{{ safe_numeric('ebacc_avg_score') }} as ebacc_avg_score
|
||||||
|
from {{ source('raw', 'ees_ks4_national') }}
|
||||||
|
where time_period ~ '^[0-9]+$'
|
||||||
@@ -46,12 +46,16 @@ renamed as (
|
|||||||
{{ parse_report_card_grade('rc_attendance_behaviour') }}::integer as rc_attendance_behaviour,
|
{{ parse_report_card_grade('rc_attendance_behaviour') }}::integer as rc_attendance_behaviour,
|
||||||
{{ parse_report_card_grade('rc_personal_development') }}::integer as rc_personal_development,
|
{{ parse_report_card_grade('rc_personal_development') }}::integer as rc_personal_development,
|
||||||
{{ parse_report_card_grade('rc_leadership_governance') }}::integer as rc_leadership_governance,
|
{{ parse_report_card_grade('rc_leadership_governance') }}::integer as rc_leadership_governance,
|
||||||
-- No MI column exists for these yet (see tap.py); the tap never
|
{{ parse_report_card_grade('rc_early_years') }}::integer as rc_early_years,
|
||||||
-- emits rc_early_years/rc_sixth_form, so these stay NULL.
|
{{ parse_report_card_grade('rc_sixth_form') }}::integer as rc_sixth_form,
|
||||||
null::integer as rc_early_years,
|
|
||||||
null::integer as rc_sixth_form,
|
|
||||||
|
|
||||||
report_url
|
-- Start date of the latest FULL inspection (the report-card
|
||||||
|
-- inspection in the renewed framework). Guarded in the final select:
|
||||||
|
-- only kept when the row actually carries report-card grades, because
|
||||||
|
-- in legacy-format files this column is the legacy inspection date.
|
||||||
|
to_date(nullif(trim(rc_inspection_date), 'NULL'), 'DD/MM/YYYY') as rc_inspection_date_raw,
|
||||||
|
|
||||||
|
nullif(trim(report_url), 'NULL') as report_url
|
||||||
from source
|
from source
|
||||||
where urn is not null
|
where urn is not null
|
||||||
and (
|
and (
|
||||||
@@ -60,5 +64,17 @@ renamed as (
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
select * from renamed
|
select
|
||||||
|
*,
|
||||||
|
case
|
||||||
|
when rc_safeguarding_met is not null
|
||||||
|
or rc_inclusion is not null
|
||||||
|
or rc_curriculum_teaching is not null
|
||||||
|
or rc_achievement is not null
|
||||||
|
or rc_attendance_behaviour is not null
|
||||||
|
or rc_personal_development is not null
|
||||||
|
or rc_leadership_governance is not null
|
||||||
|
then rc_inspection_date_raw
|
||||||
|
end as rc_inspection_date
|
||||||
|
from renamed
|
||||||
where inspection_date is not null
|
where inspection_date is not null
|
||||||
|
|||||||
Reference in New Issue
Block a user