fix(compare): date report cards with their own inspection date, never the legacy one

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0146VHeLAWjDVE2B5uU67jCB
This commit is contained in:
Tudor
2026-07-16 14:48:17 +01:00
co-authored by Claude Fable 5
parent e00a1b38a8
commit 9773483221
6 changed files with 79 additions and 2 deletions
+5
View File
@@ -617,6 +617,11 @@ def _ofsted_block(o, urn: int) -> dict:
block = {
"framework": o.framework,
"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,
"overall_effectiveness": overall,
"grade_source": grade_source,
+3
View File
@@ -156,6 +156,9 @@ class FactOfstedInspection(Base):
rc_leadership_governance = Column(Integer)
rc_early_years = 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)
@@ -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."""
import types
from datetime import date
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
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():
block = _ofsted_block(_row(overall_effectiveness=2, quality_of_education=2), urn=1)
for key in ("framework", "inspection_date", "overall_effectiveness",