fix: don't portray special schools as failing the mainstream benchmark
PR Checks / Frontend Typecheck + Tests (pull_request) Successful in 1m8s
PR Checks / Backend Smoke (pull_request) Successful in 7s
PR Checks / Build Backend (no push) (pull_request) Successful in 10s
PR Checks / Build Frontend (no push) (pull_request) Successful in 46s
PR Checks / Build Pipeline (no push) (pull_request) Successful in 10s
PR Checks / AI Code Review (Claude) (pull_request) Successful in 2m1s

Special schools, PRUs and alternative provision teach pupils with SEND who
sit the same KS2/KS4 assessments but very few reach the mainstream "expected
standard". Their headline attainment is therefore ~0% (or a very low
Attainment 8), and the site was comparing that to the England average and
painting it red — e.g. Greenmead School (a community special school) rendered
as "0.0% — −62 pts below England average" with three 0% red SATs bars. That
portrays a special school as catastrophically failing against a benchmark
that doesn't fit it.

Add a shared `isSpecialSchool()` helper (detects every DfE special-school
establishment type — all contain "special" — plus PRUs / alternative
provision) and drop the mainstream England comparison + "below" framing for
these schools across every surface:

- Detail (primary + secondary): a plain-English context note explaining the
  school is special and why the comparison isn't shown; England-average delta
  chips, "England avg" hints, the SATs national markers, the Attainment-8
  "vs national" bar and the trend chart's England overlay are all suppressed.
  An all-zero placeholder SATs row hides the (empty) subject bar chart and the
  "why is combined lower" bridge.
- Rankings / search rows (primary + secondary): the mainstream RWM / Attainment
  8 stat shows "—" with no "vs national" delta, instead of "0% · −62 vs
  national".
- Compare: special schools' attainment values are dropped (no misleading dot
  at 0% / no "Below England average" chip); progress banding, which IS a fair
  measure for special schools, is kept.

Belt-and-braces zero-guard: a whole-row zero attainment (special or a
suppressed cohort) is also treated as not-comparable, while a legitimate
single 0 (e.g. 0% exceeding at a mainstream school) stays comparable.

Tests: new isSpecialSchool unit tests (every DfE special type matched, no
mainstream false positives); an e2e journey asserts Greenmead shows the
special-school note and no England-average comparison. tsc clean; 108/108 unit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0146VHeLAWjDVE2B5uU67jCB
This commit is contained in:
Tudor
2026-07-20 20:39:16 +01:00
co-authored by Claude Opus 4.8
parent 5e370d09f1
commit ae6ef6860b
10 changed files with 276 additions and 71 deletions
+24 -2
View File
@@ -175,8 +175,30 @@ test('an all-through school shows BOTH its KS2 SATs and its GCSE results, not ju
// The combined results section carries both phases. // The combined results section carries both phases.
const results = page.locator('#results'); const results = page.locator('#results');
await expect(results.getByText(/SATs & GCSE Results/)).toBeVisible(); await expect(results.getByText(/SATs & GCSE Results/)).toBeVisible();
await expect(results.getByText('Reading, Writing & Maths combined')).toBeVisible(); // KS2 await expect(results.getByRole('heading', { name: /Primary.*KS2 SATs/ })).toBeVisible(); // KS2 block
await expect(results.getByText('Attainment 8').first()).toBeVisible(); // KS4 await expect(results.getByRole('heading', { name: /Secondary.*GCSEs/ })).toBeVisible(); // KS4 block
});
test('a special school is not shown as failing against the mainstream England average', async ({ page }) => {
// Special schools sit the same tests but very few pupils reach the mainstream
// "expected standard", so a "0.0% · 62 pts below England average" rendering
// portrays them as failing against a benchmark that doesn't fit. The results
// section drops the England comparison and explains the context instead.
const SP_URN = 101099; // Greenmead School — a community special school
const res = await page.request.get(`/api/schools/${SP_URN}`);
expect(res.ok()).toBeTruthy();
const detail = await res.json();
test.skip(
!/special|pupil referral|alternative provision/i.test(detail.school_info?.school_type ?? ''),
'precondition: chosen URN must currently be a special school',
);
await page.goto(`/school/${SP_URN}`);
const results = page.locator('#results');
// The special-school context note is shown…
await expect(results.getByText(/This is a special school/i)).toBeVisible({ timeout: 15_000 });
// …and the mainstream England-average comparison is dropped entirely.
await expect(results.getByText(/England avg/i)).toHaveCount(0);
}); });
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 }) => {
+38
View File
@@ -269,6 +269,44 @@ describe('isProposedToClose', () => {
}); });
}); });
describe('isSpecialSchool', () => {
const { isSpecialSchool } = require('@/lib/utils');
it('matches every DfE special-school establishment type', () => {
for (const t of [
'Community special school',
'Foundation special school',
'Academy special converter',
'Academy special sponsor led',
'Non-maintained special school',
'Free schools special',
'Other independent special school',
]) {
expect(isSpecialSchool({ school_type: t })).toBe(true);
}
});
it('matches pupil referral units and alternative provision', () => {
expect(isSpecialSchool({ school_type: 'Pupil referral unit' })).toBe(true);
expect(isSpecialSchool({ school_type: 'Academy alternative provision converter' })).toBe(true);
});
it('does not match mainstream types (no false positives)', () => {
for (const t of [
'Academy converter',
'Community school',
'Voluntary aided school',
'Free schools',
'University technical college',
'Other independent school',
null,
undefined,
]) {
expect(isSpecialSchool({ school_type: t })).toBe(false);
}
});
});
describe('shortName', () => { describe('shortName', () => {
it('drops the trailing establishment-type words', () => { it('drops the trailing establishment-type words', () => {
expect(shortName('Barclay Primary School')).toBe('Barclay'); expect(shortName('Barclay Primary School')).toBe('Barclay');
@@ -1558,3 +1558,21 @@
.closingStrip strong { .closingStrip strong {
color: #8a6200; color: #8a6200;
} }
/* Special-school context note: soft, informational (teal), not a warning. It
explains why the mainstream attainment measures and England comparison are
dropped for special schools / PRUs / AP. */
.specialNote {
background: var(--bg-secondary, #f3ede4);
border-left: 4px solid var(--accent-teal, #2d7d7d);
border-radius: 0 6px 6px 0;
padding: 0.7rem 1rem;
margin: 0 0 1rem;
font-size: 0.9rem;
line-height: 1.5;
color: var(--text-secondary, #5c564d);
max-width: 72ch;
}
.specialNote strong {
color: var(--text-primary, #1a1612);
}
+87 -43
View File
@@ -18,7 +18,7 @@ import type {
SchoolDeprivation, SchoolFinance, NationalAverages, SchoolDeprivation, SchoolFinance, NationalAverages,
} from '@/lib/types'; } from '@/lib/types';
import { import {
formatPercentage, formatProgress, formatAcademicYear, isProposedToClose, ofstedLegacyAreas, formatPercentage, formatProgress, formatAcademicYear, isProposedToClose, ofstedLegacyAreas, isSpecialSchool,
} from '@/lib/utils'; } from '@/lib/utils';
import { DeltaChip } from './DeltaChip'; import { DeltaChip } from './DeltaChip';
import { summariseAdmissions } from '@/lib/compareLogic'; import { summariseAdmissions } from '@/lib/compareLogic';
@@ -233,6 +233,24 @@ export function SchoolDetailView({
const hasKS4Results = latestResults != null && latestResults.attainment_8_score != null; const hasKS4Results = latestResults != null && latestResults.attainment_8_score != null;
const hasAnyResults = hasKS2Results || hasKS4Results; const hasAnyResults = hasKS2Results || hasKS4Results;
// Special schools / PRUs / AP: their pupils sit the same tests but very few
// reach the mainstream "expected standard", so a 0% headline and an England
// comparison portray them as failing against a benchmark that doesn't fit.
const isSpecial = isSpecialSchool(schoolInfo);
// Belt-and-braces: a whole-row zero attainment (special or suppressed cohort)
// is a placeholder, not a real mainstream result — suppress its comparison
// too. A single 0 (e.g. 0% exceeding at a normal school) stays comparable.
const ks2Placeholder = latestResults != null
&& latestResults.rwm_expected_pct === 0
&& (latestResults.reading_expected_pct ?? 0) === 0
&& (latestResults.writing_expected_pct ?? 0) === 0
&& (latestResults.maths_expected_pct ?? 0) === 0;
const ks4Placeholder = latestResults != null && latestResults.attainment_8_score === 0;
// Whether to drop the England-average deltas / national markers / "below"
// framing on the attainment measures.
const suppressKs2Comparison = isSpecial || ks2Placeholder;
const suppressKs4Comparison = isSpecial || ks4Placeholder;
// Build section nav items dynamically — only sections with data. // Build section nav items dynamically — only sections with data.
// Order is engagement-led (from section_nav_used analytics): the most-sought // Order is engagement-led (from section_nav_used analytics): the most-sought
// sections — results, admissions, inclusion, history — sit near the top, // sections — results, admissions, inclusion, history — sit near the top,
@@ -624,13 +642,32 @@ export function SchoolDetailView({
{isAllThrough ? 'SATs & GCSE Results' : 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}>
{isAllThrough {isSpecial
? 'KS2 SATs (end of Year 6) and GCSE results (Year 11) — this school covers both. England averages shown for comparison.' ? (isSecondary
: isSecondary ? 'GCSE results for Year 11 pupils.'
? 'GCSE results for Year 11 pupils. England averages shown for comparison.' : 'End-of-primary-school tests taken by Year 6 pupils.')
: 'End-of-primary-school tests taken by Year 6 pupils. England averages shown for comparison.'} : isAllThrough
? 'KS2 SATs (end of Year 6) and GCSE results (Year 11) — this school covers both. England 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>
{/* Special schools sit the same national assessments but teach pupils
with SEND, so very few reach the mainstream "expected standard".
Explain that up front and drop the England comparison below, so a
0% headline never reads as a failing grade against a benchmark
that doesn't fit the school. */}
{isSpecial && (
<div className={styles.specialNote} role="note">
<strong>This is a special school.</strong> Its pupils have special educational
needs and work towards individual targets. They sit the same national tests, but
very few reach the mainstream &ldquo;expected standard&rdquo; these measures report,
so a comparison with the England average isn&rsquo;t a meaningful guide to the
school. Where available, the progress pupils make (below) is a fairer measure.
</div>
)}
{/* ── Primary / KS2 content ── */} {/* ── Primary / KS2 content ── */}
{hasKS2Results && ( {hasKS2Results && (
<> <>
@@ -646,7 +683,7 @@ export function SchoolDetailView({
</div> </div>
<div className={styles.heroStatValue}> <div className={styles.heroStatValue}>
{formatPercentage(latestResults.rwm_expected_pct)} {formatPercentage(latestResults.rwm_expected_pct)}
{primaryAvg.rwm_expected_pct != null && ( {!suppressKs2Comparison && primaryAvg.rwm_expected_pct != null && (
<DeltaChip <DeltaChip
value={latestResults.rwm_expected_pct} value={latestResults.rwm_expected_pct}
baseline={primaryAvg.rwm_expected_pct} baseline={primaryAvg.rwm_expected_pct}
@@ -655,7 +692,7 @@ export function SchoolDetailView({
/> />
)} )}
</div> </div>
{primaryAvg.rwm_expected_pct != null && ( {!suppressKs2Comparison && primaryAvg.rwm_expected_pct != null && (
<div className={styles.heroStatHint}>England avg: {primaryAvg.rwm_expected_pct.toFixed(0)}%</div> <div className={styles.heroStatHint}>England avg: {primaryAvg.rwm_expected_pct.toFixed(0)}%</div>
)} )}
</div> </div>
@@ -668,7 +705,7 @@ export function SchoolDetailView({
</div> </div>
<div className={styles.heroStatValue}> <div className={styles.heroStatValue}>
{formatPercentage(latestResults.rwm_high_pct)} {formatPercentage(latestResults.rwm_high_pct)}
{primaryAvg.rwm_high_pct != null && ( {!suppressKs2Comparison && primaryAvg.rwm_high_pct != null && (
<DeltaChip <DeltaChip
value={latestResults.rwm_high_pct} value={latestResults.rwm_high_pct}
baseline={primaryAvg.rwm_high_pct} baseline={primaryAvg.rwm_high_pct}
@@ -677,14 +714,15 @@ export function SchoolDetailView({
/> />
)} )}
</div> </div>
{primaryAvg.rwm_high_pct != null && ( {!suppressKs2Comparison && primaryAvg.rwm_high_pct != null && (
<div className={styles.heroStatHint}>England avg: {primaryAvg.rwm_high_pct.toFixed(0)}%</div> <div className={styles.heroStatHint}>England avg: {primaryAvg.rwm_high_pct.toFixed(0)}%</div>
)} )}
</div> </div>
)} )}
</div> </div>
{latestResults.rwm_expected_pct != null && {!suppressKs2Comparison &&
latestResults.rwm_expected_pct != null &&
latestResults.reading_expected_pct != null && latestResults.reading_expected_pct != null &&
latestResults.writing_expected_pct != null && latestResults.writing_expected_pct != null &&
latestResults.maths_expected_pct != null && ( latestResults.maths_expected_pct != null && (
@@ -708,28 +746,34 @@ export function SchoolDetailView({
</div> </div>
)} )}
<SatsChart {/* All-zero placeholder rows (special / suppressed) would render as
subjects={[ three empty bars against the national markers — misleading, so
{ skip the chart. For a special school with some non-zero
name: 'Reading', subjects, keep the bars but drop the national markers. */}
expectedPct: latestResults.reading_expected_pct, {!ks2Placeholder && (
exceedingPct: latestResults.reading_high_pct, <SatsChart
nationalExpectedPct: primaryAvg.reading_expected_pct, subjects={[
}, {
{ name: 'Reading',
name: 'Writing', expectedPct: latestResults.reading_expected_pct,
expectedPct: latestResults.writing_expected_pct, exceedingPct: latestResults.reading_high_pct,
exceedingPct: latestResults.writing_high_pct, nationalExpectedPct: suppressKs2Comparison ? null : primaryAvg.reading_expected_pct,
nationalExpectedPct: primaryAvg.writing_expected_pct, },
}, {
{ name: 'Writing',
name: 'Maths', expectedPct: latestResults.writing_expected_pct,
expectedPct: latestResults.maths_expected_pct, exceedingPct: latestResults.writing_high_pct,
exceedingPct: latestResults.maths_high_pct, nationalExpectedPct: suppressKs2Comparison ? null : primaryAvg.writing_expected_pct,
nationalExpectedPct: primaryAvg.maths_expected_pct, },
}, {
]} name: 'Maths',
/> expectedPct: latestResults.maths_expected_pct,
exceedingPct: latestResults.maths_high_pct,
nationalExpectedPct: suppressKs2Comparison ? null : primaryAvg.maths_expected_pct,
},
]}
/>
)}
{/* Progress scores row */} {/* Progress scores row */}
{(latestResults.reading_progress != null || latestResults.writing_progress != null || latestResults.maths_progress != null) && ( {(latestResults.reading_progress != null || latestResults.writing_progress != null || latestResults.maths_progress != null) && (
@@ -786,7 +830,7 @@ export function SchoolDetailView({
<MetricTooltip metricKey="attainment_8_score" /> <MetricTooltip metricKey="attainment_8_score" />
</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 && ( {!suppressKs4Comparison && secondaryAvg.attainment_8_score != null && (
<div className={styles.metricHint}>England avg: {secondaryAvg.attainment_8_score.toFixed(1)}</div> <div className={styles.metricHint}>England avg: {secondaryAvg.attainment_8_score.toFixed(1)}</div>
)} )}
</div> </div>
@@ -810,7 +854,7 @@ export function SchoolDetailView({
<MetricTooltip metricKey="english_maths_standard_pass_pct" /> <MetricTooltip metricKey="english_maths_standard_pass_pct" />
</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 && ( {!suppressKs4Comparison && secondaryAvg.english_maths_standard_pass_pct != null && (
<div className={styles.metricHint}>England 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>
@@ -822,7 +866,7 @@ export function SchoolDetailView({
<MetricTooltip metricKey="english_maths_strong_pass_pct" /> <MetricTooltip metricKey="english_maths_strong_pass_pct" />
</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 && ( {!suppressKs4Comparison && secondaryAvg.english_maths_strong_pass_pct != null && (
<div className={styles.metricHint}>England 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>
@@ -1076,8 +1120,8 @@ export function SchoolDetailView({
data={yearlyData} data={yearlyData}
schoolName={schoolInfo.school_name} schoolName={schoolInfo.school_name}
isSecondary={false} isSecondary={false}
nationalRwmAvg={primaryAvg.rwm_expected_pct ?? null} nationalRwmAvg={suppressKs2Comparison ? null : (primaryAvg.rwm_expected_pct ?? null)}
nationalByYear={nationalAvg?.by_year} nationalByYear={suppressKs2Comparison ? undefined : nationalAvg?.by_year}
/> />
</div> </div>
</> </>
@@ -1090,8 +1134,8 @@ export function SchoolDetailView({
data={yearlyData} data={yearlyData}
schoolName={schoolInfo.school_name} schoolName={schoolInfo.school_name}
isSecondary={true} isSecondary={true}
nationalAtt8Avg={secondaryAvg.attainment_8_score ?? null} nationalAtt8Avg={suppressKs4Comparison ? null : (secondaryAvg.attainment_8_score ?? null)}
nationalByYear={nationalAvg?.by_year} nationalByYear={suppressKs4Comparison ? undefined : nationalAvg?.by_year}
/> />
</div> </div>
</> </>
@@ -1103,9 +1147,9 @@ export function SchoolDetailView({
data={yearlyData} data={yearlyData}
schoolName={schoolInfo.school_name} schoolName={schoolInfo.school_name}
isSecondary={isSecondary} isSecondary={isSecondary}
nationalRwmAvg={isPrimary ? (primaryAvg.rwm_expected_pct ?? null) : null} nationalRwmAvg={isPrimary && !suppressKs2Comparison ? (primaryAvg.rwm_expected_pct ?? null) : null}
nationalAtt8Avg={isSecondary ? (secondaryAvg.attainment_8_score ?? null) : null} nationalAtt8Avg={isSecondary && !suppressKs4Comparison ? (secondaryAvg.attainment_8_score ?? null) : null}
nationalByYear={nationalAvg?.by_year} nationalByYear={(isPrimary ? suppressKs2Comparison : suppressKs4Comparison) ? undefined : nationalAvg?.by_year}
/> />
</div> </div>
)} )}
+14 -5
View File
@@ -9,7 +9,7 @@
*/ */
import type { School } from '@/lib/types'; import type { School } from '@/lib/types';
import { formatPercentage, calculateTrend, getPhaseStyle, schoolUrl, buildOfstedListBadge, formatAgeRange, isProposedToClose } from '@/lib/utils'; import { formatPercentage, calculateTrend, getPhaseStyle, schoolUrl, buildOfstedListBadge, formatAgeRange, isProposedToClose, isSpecialSchool } from '@/lib/utils';
import styles from './SchoolRow.module.css'; import styles from './SchoolRow.module.css';
interface SchoolRowProps { interface SchoolRowProps {
@@ -38,10 +38,19 @@ export function SchoolRow({
school.religious_denomination && school.religious_denomination &&
school.religious_denomination !== 'Does not apply'; school.religious_denomination !== 'Does not apply';
// Special schools / PRUs / AP: the mainstream RWM measure and its England
// comparison aren't a fair judgement (their pupils have SEND), so a "0% ·
// 62 vs national" row misrepresents them. Treat the mainstream stat as not
// comparable — same for a placeholder all-zero value.
const rwmComparable =
school.rwm_expected_pct != null &&
school.rwm_expected_pct !== 0 &&
!isSpecialSchool(school);
// vs-national delta // vs-national delta
const rwmDelta = const rwmDelta =
school.rwm_expected_pct != null && nationalAvgRwm != null rwmComparable && nationalAvgRwm != null
? Math.round(school.rwm_expected_pct - nationalAvgRwm) ? Math.round((school.rwm_expected_pct as number) - nationalAvgRwm)
: null; : null;
const handleCompareClick = () => { const handleCompareClick = () => {
@@ -87,9 +96,9 @@ export function SchoolRow({
<div className={styles.line3}> <div className={styles.line3}>
<span className={styles.stat}> <span className={styles.stat}>
<strong className={styles.statValue}> <strong className={styles.statValue}>
{school.rwm_expected_pct != null ? formatPercentage(school.rwm_expected_pct, 0) : '—'} {rwmComparable ? formatPercentage(school.rwm_expected_pct, 0) : '—'}
</strong> </strong>
{school.prev_rwm_expected_pct != null && ( {rwmComparable && school.prev_rwm_expected_pct != null && (
<span <span
className={`${styles.trend} ${styles[`trend${trend.charAt(0).toUpperCase() + trend.slice(1)}`]}`} className={`${styles.trend} ${styles[`trend${trend.charAt(0).toUpperCase() + trend.slice(1)}`]}`}
title={`Previous year: ${formatPercentage(school.prev_rwm_expected_pct)}`} title={`Previous year: ${formatPercentage(school.prev_rwm_expected_pct)}`}
@@ -395,6 +395,22 @@
line-height: 1.5; line-height: 1.5;
} }
/* Special-school context note: soft, informational (teal), not a warning. */
.specialNote {
background: var(--bg-secondary, #f3ede4);
border-left: 4px solid var(--accent-teal, #2d7d7d);
border-radius: 0 6px 6px 0;
padding: 0.7rem 1rem;
margin: 0 0 1rem;
font-size: 0.9rem;
line-height: 1.5;
color: var(--text-secondary, #5c564d);
max-width: 72ch;
}
.specialNote strong {
color: var(--text-primary, #1a1612);
}
/* ── Metrics Grid & Cards ────────────────────────────── */ /* ── Metrics Grid & Cards ────────────────────────────── */
.metricsGrid { .metricsGrid {
display: grid; display: grid;
@@ -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, ofstedLegacyAreas } from '@/lib/utils'; import { formatPercentage, formatProgress, formatAcademicYear, formatAgeRange, isProposedToClose, ofstedLegacyAreas, isSpecialSchool } 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';
@@ -107,6 +107,14 @@ export function SecondarySchoolDetailView({
const p8Suspended = latestResults != null && latestResults.year >= 202425; const p8Suspended = latestResults != null && latestResults.year >= 202425;
const hasResults = latestResults?.attainment_8_score != null; const hasResults = latestResults?.attainment_8_score != null;
// Special schools / PRUs / AP sit the same GCSEs but teach pupils with SEND,
// so their headline attainment is far below the mainstream average by design.
// Drop the England comparison + "below" framing so the page doesn't portray
// them as failing against a benchmark that doesn't fit. (Also guards a
// placeholder all-zero Attainment 8.)
const isSpecial = isSpecialSchool(schoolInfo);
const suppressComparison = isSpecial || (latestResults != null && latestResults.attainment_8_score === 0);
const admissionsTag = (() => { const admissionsTag = (() => {
const policy = schoolInfo.admissions_policy?.toLowerCase() ?? ''; const policy = schoolInfo.admissions_policy?.toLowerCase() ?? '';
if (policy.includes('selective')) return 'Selective'; if (policy.includes('selective')) return 'Selective';
@@ -452,9 +460,18 @@ 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. England averages shown for comparison. GCSE results for Year 11 pupils.{!suppressComparison && ' England averages shown for comparison.'}
</p> </p>
{isSpecial && (
<div className={styles.specialNote} role="note">
<strong>This is a special school.</strong> Its pupils have special educational
needs and work towards individual targets. They sit the same GCSEs, but their
headline attainment is far below the mainstream average by design, so a comparison
with the England average isn&rsquo;t a meaningful guide to the school.
</div>
)}
{p8Suspended && ( {p8Suspended && (
<div className={styles.p8Banner}> <div className={styles.p8Banner}>
Progress 8 isn&apos;t published for 2024/25: this GCSE year group sat no KS2 tests Progress 8 isn&apos;t published for 2024/25: this GCSE year group sat no KS2 tests
@@ -472,7 +489,7 @@ export function SecondarySchoolDetailView({
</div> </div>
<div className={styles.heroStatValue}> <div className={styles.heroStatValue}>
{latestResults.attainment_8_score.toFixed(1)} {latestResults.attainment_8_score.toFixed(1)}
{secondaryAvg.attainment_8_score != null && ( {!suppressComparison && secondaryAvg.attainment_8_score != null && (
<DeltaChip <DeltaChip
value={latestResults.attainment_8_score} value={latestResults.attainment_8_score}
baseline={secondaryAvg.attainment_8_score} baseline={secondaryAvg.attainment_8_score}
@@ -481,7 +498,7 @@ export function SecondarySchoolDetailView({
/> />
)} )}
</div> </div>
{secondaryAvg.attainment_8_score != null && ( {!suppressComparison && secondaryAvg.attainment_8_score != null && (
<div className={styles.heroStatHint}>England avg: {secondaryAvg.attainment_8_score.toFixed(1)}</div> <div className={styles.heroStatHint}>England avg: {secondaryAvg.attainment_8_score.toFixed(1)}</div>
)} )}
</div> </div>
@@ -512,7 +529,7 @@ export function SecondarySchoolDetailView({
</div> </div>
<div className={styles.heroStatValue}> <div className={styles.heroStatValue}>
{formatPercentage(latestResults.english_maths_strong_pass_pct)} {formatPercentage(latestResults.english_maths_strong_pass_pct)}
{secondaryAvg.english_maths_strong_pass_pct != null && ( {!suppressComparison && secondaryAvg.english_maths_strong_pass_pct != null && (
<DeltaChip <DeltaChip
value={latestResults.english_maths_strong_pass_pct} value={latestResults.english_maths_strong_pass_pct}
baseline={secondaryAvg.english_maths_strong_pass_pct} baseline={secondaryAvg.english_maths_strong_pass_pct}
@@ -521,7 +538,7 @@ export function SecondarySchoolDetailView({
/> />
)} )}
</div> </div>
{secondaryAvg.english_maths_strong_pass_pct != null && ( {!suppressComparison && secondaryAvg.english_maths_strong_pass_pct != null && (
<div className={styles.heroStatHint}>England 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>
@@ -534,7 +551,7 @@ export function SecondarySchoolDetailView({
</div> </div>
<div className={styles.heroStatValue}> <div className={styles.heroStatValue}>
{formatPercentage(latestResults.english_maths_standard_pass_pct)} {formatPercentage(latestResults.english_maths_standard_pass_pct)}
{secondaryAvg.english_maths_standard_pass_pct != null && ( {!suppressComparison && secondaryAvg.english_maths_standard_pass_pct != null && (
<DeltaChip <DeltaChip
value={latestResults.english_maths_standard_pass_pct} value={latestResults.english_maths_standard_pass_pct}
baseline={secondaryAvg.english_maths_standard_pass_pct} baseline={secondaryAvg.english_maths_standard_pass_pct}
@@ -543,15 +560,17 @@ export function SecondarySchoolDetailView({
/> />
)} )}
</div> </div>
{secondaryAvg.english_maths_standard_pass_pct != null && ( {!suppressComparison && secondaryAvg.english_maths_standard_pass_pct != null && (
<div className={styles.heroStatHint}>England 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>
)} )}
</div> </div>
{/* Attainment 8 visual bar (080 scale) */} {/* Attainment 8 visual bar (080 scale). This viz is explicitly
{latestResults.attainment_8_score != null && ( "school vs national", so it's dropped for special schools where
that comparison isn't meaningful. */}
{!suppressComparison && latestResults.attainment_8_score != null && (
<div className={styles.att8Viz}> <div className={styles.att8Viz}>
<div className={styles.att8VizLabel}>Attainment 8 school vs national</div> <div className={styles.att8VizLabel}>Attainment 8 school vs national</div>
<div className={styles.att8VizTrack}> <div className={styles.att8VizTrack}>
@@ -743,8 +762,8 @@ export function SecondarySchoolDetailView({
data={yearlyData} data={yearlyData}
schoolName={schoolInfo.school_name} schoolName={schoolInfo.school_name}
isSecondary={true} isSecondary={true}
nationalAtt8Avg={heroAtt8Nat} nationalAtt8Avg={suppressComparison ? null : heroAtt8Nat}
nationalByYear={nationalAvg?.by_year} nationalByYear={suppressComparison ? undefined : nationalAvg?.by_year}
/> />
</div> </div>
</> </>
+7 -3
View File
@@ -11,7 +11,7 @@
'use client'; 'use client';
import type { School } from '@/lib/types'; import type { School } from '@/lib/types';
import { buildOfstedListBadge, getPhaseStyle, schoolUrl, formatAgeRange, isProposedToClose } from '@/lib/utils'; import { buildOfstedListBadge, getPhaseStyle, schoolUrl, formatAgeRange, isProposedToClose, isSpecialSchool } from '@/lib/utils';
import styles from './SecondarySchoolRow.module.css'; import styles from './SecondarySchoolRow.module.css';
function detectAdmissionsTag(school: School): string | null { function detectAdmissionsTag(school: School): string | null {
@@ -55,8 +55,12 @@ export function SecondarySchoolRow({
const ofstedBadge = buildOfstedListBadge(school); const ofstedBadge = buildOfstedListBadge(school);
const phase = getPhaseStyle(school.phase); const phase = getPhaseStyle(school.phase);
const att8 = school.attainment_8_score; const att8 = school.attainment_8_score;
// Special schools / PRUs / AP: Attainment 8 vs the LA average isn't a fair
// comparison (their pupils have SEND), so drop the delta and the number
// rather than show them trailing "the average" by design.
const att8Comparable = att8 != null && att8 !== 0 && !isSpecialSchool(school);
const laDelta = const laDelta =
att8 != null && laAvgAttainment8 != null ? att8 - laAvgAttainment8 : null; att8Comparable && laAvgAttainment8 != null ? (att8 as number) - laAvgAttainment8 : null;
const admissionsTag = detectAdmissionsTag(school); const admissionsTag = detectAdmissionsTag(school);
const sixthForm = hasSixthForm(school); const sixthForm = hasSixthForm(school);
@@ -106,7 +110,7 @@ export function SecondarySchoolRow({
<div className={styles.line3}> <div className={styles.line3}>
<span className={styles.stat}> <span className={styles.stat}>
<strong className={styles.statValueLarge}> <strong className={styles.statValueLarge}>
{att8 != null ? att8.toFixed(1) : '—'} {att8Comparable ? (att8 as number).toFixed(1) : '—'}
</strong> </strong>
<span className={styles.statLabel}>Attainment 8</span> <span className={styles.statLabel}>Attainment 8</span>
</span> </span>
@@ -8,6 +8,7 @@
'use client'; 'use client';
import { latestValues, verdict } from '@/lib/compareLogic'; import { latestValues, verdict } from '@/lib/compareLogic';
import { isSpecialSchool } from '@/lib/utils';
import type { Benchmarks, ComparisonData, NationalAverages, School } from '@/lib/types'; import type { Benchmarks, ComparisonData, NationalAverages, School } from '@/lib/types';
import { DotStrip } from '@/components/DotStrip'; import { DotStrip } from '@/components/DotStrip';
import { Cell, Chip, RowLabel, Section, SectionGrid, sectionStyles as s } from './sectionShared'; import { Cell, Chip, RowLabel, Section, SectionGrid, sectionStyles as s } from './sectionShared';
@@ -90,15 +91,19 @@ function Strip({
urns, urns,
schoolNames, schoolNames,
national, national,
special,
}: { }: {
spec: StripSpec; spec: StripSpec;
data: Record<string, ComparisonData>; data: Record<string, ComparisonData>;
urns: number[]; urns: number[];
schoolNames: string[]; schoolNames: string[];
national: Record<string, number> | undefined; national: Record<string, number> | undefined;
/** Per-school special-school flag; special schools' mainstream attainment is
* not a fair comparison, so it's dropped from the strip (no dot). */
special: boolean[];
}) { }) {
const values = latestValues(data, urns, spec.metric).map((v) => const values = latestValues(data, urns, spec.metric).map((v, i) =>
v != null ? Math.round(v) : null, v != null && !special[i] ? Math.round(v) : null,
); );
const anchorValue = spec.anchorKey ? national?.[spec.anchorKey] : undefined; const anchorValue = spec.anchorKey ? national?.[spec.anchorKey] : undefined;
const anchor = const anchor =
@@ -135,12 +140,19 @@ export function CompareAcademics({
}) { }) {
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);
// Special schools / PRUs / AP: their pupils sit the same assessments but very
// few reach the mainstream standard, so their attainment isn't a fair
// like-for-like comparison — drop it (progress banding, which IS meaningful,
// is kept).
const specialFlags = schools.map((school) => isSpecialSchool(school));
const dropSpecial = (vals: Array<number | null>) =>
vals.map((v, i) => (specialFlags[i] ? null : v));
const isSecondary = propIsSecondary !== undefined ? propIsSecondary : 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,
); );
if (isSecondary) { if (isSecondary) {
const att8 = latestValues(data, urns, 'attainment_8_score'); const att8 = dropSpecial(latestValues(data, urns, 'attainment_8_score'));
const banding = urns.map((urn) => { const banding = urns.map((urn) => {
const rows = data[String(urn)]?.yearly_data ?? []; const rows = data[String(urn)]?.yearly_data ?? [];
for (let i = rows.length - 1; i >= 0; i--) { for (let i = rows.length - 1; i >= 0; i--) {
@@ -159,8 +171,8 @@ export function CompareAcademics({
const y = rows.length ? Math.trunc(rows[rows.length - 1].year) : 0; const y = rows.length ? Math.trunc(rows[rows.length - 1].year) : 0;
return y >= 202425; return y >= 202425;
}); });
const grade5 = latestValues(data, urns, 'english_maths_strong_pass_pct'); const grade5 = dropSpecial(latestValues(data, urns, 'english_maths_strong_pass_pct'));
const ebacc = latestValues(data, urns, 'ebacc_entry_pct'); const ebacc = dropSpecial(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 grade5Anchor = nationalAverages?.secondary?.english_maths_strong_pass_pct;
const ebaccAnchor = nationalAverages?.secondary?.ebacc_entry_pct; const ebaccAnchor = nationalAverages?.secondary?.ebacc_entry_pct;
@@ -272,7 +284,7 @@ export function CompareAcademics({
} }
const national = nationalAverages?.primary; const national = nationalAverages?.primary;
const disadvantaged = latestValues(data, urns, 'rwm_expected_disadvantaged_pct'); const disadvantaged = dropSpecial(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 // Cohort size behind the disadvantaged figure (spec §8.5): these are small
// groups where single pupils move the percentage — show roughly how many // groups where single pupils move the percentage — show roughly how many
@@ -307,6 +319,7 @@ export function CompareAcademics({
urns={urns} urns={urns}
schoolNames={schoolNames} schoolNames={schoolNames}
national={national} national={national}
special={specialFlags}
/> />
))} ))}
@@ -320,6 +333,7 @@ export function CompareAcademics({
urns={urns} urns={urns}
schoolNames={schoolNames} schoolNames={schoolNames}
national={national} national={national}
special={specialFlags}
/> />
))} ))}
<p className={styles.stripNote}> <p className={styles.stripNote}>
+21
View File
@@ -795,3 +795,24 @@ export const PROPOSED_TO_CLOSE_STATUS = 'Open, but proposed to close';
export function isProposedToClose(school: { status?: string | null }): boolean { export function isProposedToClose(school: { status?: string | null }): boolean {
return school.status === PROPOSED_TO_CLOSE_STATUS; return school.status === PROPOSED_TO_CLOSE_STATUS;
} }
/**
* Special schools, pupil referral units and alternative provision teach pupils
* with SEND or outside mainstream settings. Their pupils sit the same KS2/KS4
* assessments but very few reach the mainstream "expected standard", so the
* headline attainment measures — and any comparison to the England average —
* are not a fair judgement of the school. Callers use this to drop the
* mainstream-benchmark framing (deltas, "below England", national markers)
* rather than portray these schools as failing.
*
* Detection is by establishment type: every DfE special-school type contains
* "special" (e.g. "Community special school", "Academy special converter/sponsor
* led", "Foundation special school", "Non-maintained special school", "Free
* schools special", "Other independent special school"); PRUs and alternative
* provision are matched by name. Special schools carry a mainstream `phase`
* (Primary/Secondary/All-through), so `phase` alone can't identify them.
*/
export function isSpecialSchool(school: { school_type?: string | null }): boolean {
const t = (school.school_type ?? '').toLowerCase();
return /\bspecial\b/.test(t) || /pupil referral/.test(t) || /alternative provision/.test(t);
}