fix(backend): serve the current Ofsted status from fact_ofsted_latest
The list query and the batch Ofsted fetch each picked 'the latest row' of fact_ofsted_inspection themselves, and _ofsted_block carried an older ungraded grade forward when the latest graded inspection gave none. All three now read marts.fact_ofsted_latest. List rows: ofsted_grade is the grade still in force, ofsted_grade_date when it was awarded or confirmed, ofsted_date the latest visit. The ofsted block gains current_grade and latest_visit and loses grade_source; overall_effectiveness is the graded inspection's own result. A school with only an inspection stays publishable in the sitemap. Requires fact_ofsted_latest (PR #183's pipeline run) on the database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
96732c56d1
commit
a9e3a6a700
8 files changed
+188
-78
No files matched your search
@@ -85,12 +85,15 @@ def _ofsted_row(urn, date, oe):
|
||||
"framework", "inspection_type", "quality_of_education", "behaviour_attitudes",
|
||||
"personal_development", "leadership_management", "early_years_provision",
|
||||
"sixth_form_provision", "ungraded_outcome", "ungraded_grade",
|
||||
"ungraded_inspection_date", "rc_inspection_date", "latest_visit_outcome",
|
||||
"rc_safeguarding_met", "rc_inclusion", "rc_curriculum_teaching", "rc_achievement",
|
||||
"rc_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)
|
||||
when = types.SimpleNamespace(isoformat=lambda: date)
|
||||
base.update(urn=urn, graded_inspection_date=when, latest_visit_date=when,
|
||||
latest_visit_kind="graded", overall_effectiveness=oe,
|
||||
current_grade=oe, current_grade_date=when, current_grade_basis="graded")
|
||||
return types.SimpleNamespace(**base)
|
||||
|
||||
|
||||
@@ -114,10 +117,9 @@ def _dist_row(urn, year, distance_m, route_count=1):
|
||||
|
||||
def test_one_query_per_table_and_latest_row_per_urn():
|
||||
rows = {
|
||||
# URN 1 has two Ofsted rows; the batch must keep the most recent (2023).
|
||||
"FactOfstedInspection": [
|
||||
# The mart holds one current Ofsted status per URN.
|
||||
"FactOfstedLatest": [
|
||||
_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)],
|
||||
@@ -142,14 +144,14 @@ def test_one_query_per_table_and_latest_row_per_urn():
|
||||
assert sorted(session.queries) == [
|
||||
"FactAdmissionDistance", "FactAdmissions", "FactDeprivation",
|
||||
"FactFinance", "FactKs4Destinations", "FactKs5Destinations",
|
||||
"FactOfstedInspection", "FactPupilCharacteristics",
|
||||
"FactOfstedLatest", "FactPupilCharacteristics",
|
||||
]
|
||||
|
||||
# A school with no destination rows gets null, not an empty shell — the
|
||||
# frontend renders the section from the block's presence.
|
||||
assert out[1]["destinations"] is None
|
||||
|
||||
# Latest Ofsted kept per URN
|
||||
# Each URN's current Ofsted status
|
||||
assert out[1]["ofsted"]["overall_effectiveness"] == 2
|
||||
assert out[2]["ofsted"]["overall_effectiveness"] == 1
|
||||
|
||||
@@ -175,7 +177,7 @@ def test_one_query_per_table_and_latest_row_per_urn():
|
||||
|
||||
|
||||
def test_single_wrapper_matches_batch(monkeypatch):
|
||||
session = _FakeSession({"FactOfstedInspection": [_ofsted_row(5, "2022-01-01", 2)]})
|
||||
session = _FakeSession({"FactOfstedLatest": [_ofsted_row(5, "2022-01-01", 2)]})
|
||||
single = data_loader.get_supplementary_data(session, 5)
|
||||
assert single["ofsted"]["overall_effectiveness"] == 2
|
||||
assert single["admissions_history"] == []
|
||||
|
||||
Reference in new issue
Block a user