Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b44fca902f |
+43
-2
@@ -262,15 +262,53 @@ assert "NULL AS has_sixth_form" in str(_MAIN_QUERY_NO_SIXTH_FORM), (
|
|||||||
"expected replacement of 's.has_sixth_form,' to have taken effect"
|
"expected replacement of 's.has_sixth_form,' to have taken effect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Fallback used when marts.dim_school predates the GIAS code-dictionary
|
||||||
|
# migration (i.e. the nightly dbt pipeline hasn't rebuilt the mart yet on
|
||||||
|
# this DB, so it still has the old name columns instead of *_code columns).
|
||||||
|
_MAIN_QUERY_LEGACY_NAMES = str(_MAIN_QUERY)
|
||||||
|
_LEGACY_NAME_REPLACEMENTS = [
|
||||||
|
("s.phase_code,", "s.phase,"),
|
||||||
|
("s.school_type_code,", "s.school_type,"),
|
||||||
|
(
|
||||||
|
"s.religious_character_code,",
|
||||||
|
"s.religious_character AS religious_denomination,",
|
||||||
|
),
|
||||||
|
("s.status_code,", "s.status,"),
|
||||||
|
("s.admissions_policy_code,", "s.admissions_policy,"),
|
||||||
|
]
|
||||||
|
for _old, _new in _LEGACY_NAME_REPLACEMENTS:
|
||||||
|
assert _old in _MAIN_QUERY_LEGACY_NAMES, (
|
||||||
|
f"expected {_old!r} to be present in _MAIN_QUERY before replacement"
|
||||||
|
)
|
||||||
|
_MAIN_QUERY_LEGACY_NAMES = _MAIN_QUERY_LEGACY_NAMES.replace(_old, _new)
|
||||||
|
_MAIN_QUERY_LEGACY_NAMES = text(_MAIN_QUERY_LEGACY_NAMES)
|
||||||
|
|
||||||
|
_GIAS_CODE_COLUMN_NAMES = (
|
||||||
|
"phase_code",
|
||||||
|
"school_type_code",
|
||||||
|
"religious_character_code",
|
||||||
|
"status_code",
|
||||||
|
"admissions_policy_code",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_school_data_as_dataframe() -> pd.DataFrame:
|
def load_school_data_as_dataframe() -> pd.DataFrame:
|
||||||
"""Load all school + KS2 data as a pandas DataFrame."""
|
"""Load all school + KS2 data as a pandas DataFrame."""
|
||||||
try:
|
try:
|
||||||
df = pd.read_sql(_MAIN_QUERY, engine)
|
df = pd.read_sql(_MAIN_QUERY, engine)
|
||||||
except sqlalchemy.exc.ProgrammingError as exc:
|
except sqlalchemy.exc.ProgrammingError as exc:
|
||||||
if "has_sixth_form" not in str(exc):
|
if any(col in str(exc) for col in _GIAS_CODE_COLUMN_NAMES):
|
||||||
print(f"Warning: Could not load school data from marts: {exc}")
|
logging.getLogger(__name__).warning(
|
||||||
|
"marts predate the GIAS code migration — falling back to "
|
||||||
|
"legacy name-column query: %s",
|
||||||
|
exc,
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
df = pd.read_sql(_MAIN_QUERY_LEGACY_NAMES, engine)
|
||||||
|
except Exception as exc2:
|
||||||
|
print(f"Warning: Could not load school data from marts: {exc2}")
|
||||||
return pd.DataFrame()
|
return pd.DataFrame()
|
||||||
|
elif "has_sixth_form" in str(exc):
|
||||||
logging.getLogger(__name__).warning(
|
logging.getLogger(__name__).warning(
|
||||||
"marts.dim_school is missing has_sixth_form (pipeline hasn't "
|
"marts.dim_school is missing has_sixth_form (pipeline hasn't "
|
||||||
"rebuilt the mart yet on this DB) — retrying without it: %s",
|
"rebuilt the mart yet on this DB) — retrying without it: %s",
|
||||||
@@ -281,6 +319,9 @@ def load_school_data_as_dataframe() -> pd.DataFrame:
|
|||||||
except Exception as exc2:
|
except Exception as exc2:
|
||||||
print(f"Warning: Could not load school data from marts: {exc2}")
|
print(f"Warning: Could not load school data from marts: {exc2}")
|
||||||
return pd.DataFrame()
|
return pd.DataFrame()
|
||||||
|
else:
|
||||||
|
print(f"Warning: Could not load school data from marts: {exc}")
|
||||||
|
return pd.DataFrame()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
print(f"Warning: Could not load school data from marts: {exc}")
|
print(f"Warning: Could not load school data from marts: {exc}")
|
||||||
return pd.DataFrame()
|
return pd.DataFrame()
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ OFFICIAL_SIXTH_FORM: dict[int, str] = {
|
|||||||
0: "Not applicable",
|
0: "Not applicable",
|
||||||
1: "Has a sixth form",
|
1: "Has a sixth form",
|
||||||
2: "Does not have a sixth form",
|
2: "Does not have a sixth form",
|
||||||
9: "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RELIGIOUS_CHARACTER: dict[int, str] = {
|
RELIGIOUS_CHARACTER: dict[int, str] = {
|
||||||
@@ -129,14 +128,12 @@ RELIGIOUS_CHARACTER: dict[int, str] = {
|
|||||||
47: "Reformed Baptist",
|
47: "Reformed Baptist",
|
||||||
48: "Roman Catholic/Anglican",
|
48: "Roman Catholic/Anglican",
|
||||||
49: "Sunni Deobandi",
|
49: "Sunni Deobandi",
|
||||||
99: "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ADMISSIONS_POLICY: dict[int, str] = {
|
ADMISSIONS_POLICY: dict[int, str] = {
|
||||||
0: "Not applicable",
|
0: "Not applicable",
|
||||||
2: "Selective",
|
2: "Selective",
|
||||||
4: "Non-selective",
|
4: "Non-selective",
|
||||||
9: "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -81,15 +81,3 @@ def test_seed_matches_dictionaries():
|
|||||||
for row in csv.DictReader(fh):
|
for row in csv.DictReader(fh):
|
||||||
seed[row["field"]][int(row["code"])] = row["name"]
|
seed[row["field"]][int(row["code"])] = row["name"]
|
||||||
assert seed == fields
|
assert seed == fields
|
||||||
|
|
||||||
|
|
||||||
def test_blank_name_sentinel_codes_map_to_empty_string():
|
|
||||||
"""GIAS carries codes whose (name) column is blank — e.g. ReligiousCharacter
|
|
||||||
99 (~4k schools) and AdmissionsPolicy 9 (~5.6k schools). The old name
|
|
||||||
pipeline served these as empty strings; the dictionaries must reproduce
|
|
||||||
that ("" is falsy, so UI tag heuristics stay silent) rather than letting
|
|
||||||
them hit the "Unknown (<code>)" path meant for genuinely new codes."""
|
|
||||||
assert RELIGIOUS_CHARACTER[99] == ""
|
|
||||||
assert ADMISSIONS_POLICY[9] == ""
|
|
||||||
assert translate(99, RELIGIOUS_CHARACTER) == ""
|
|
||||||
assert translate(9, ADMISSIONS_POLICY) == ""
|
|
||||||
|
|||||||
@@ -42,3 +42,55 @@ def test_missing_code_columns_are_a_noop():
|
|||||||
out = translate_gias_code_columns(df)
|
out = translate_gias_code_columns(df)
|
||||||
assert out.iloc[0]["phase"] == "Primary"
|
assert out.iloc[0]["phase"] == "Primary"
|
||||||
assert out.iloc[0]["status"] == "Open"
|
assert out.iloc[0]["status"] == "Open"
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_school_data_survives_premigration_marts(monkeypatch):
|
||||||
|
"""Real prod state until the nightly pipeline first rebuilds the mart with
|
||||||
|
the GIAS code columns: marts.dim_school still has the old name columns
|
||||||
|
(phase, school_type, religious_character, status, admissions_policy)
|
||||||
|
instead of the new *_code columns. The first query raises UndefinedColumn
|
||||||
|
on s.phase_code; load_school_data_as_dataframe must retry with the
|
||||||
|
legacy name-column query rather than swallow the error and return (and
|
||||||
|
then have load_school_data cache) an empty DataFrame."""
|
||||||
|
import sqlalchemy.exc
|
||||||
|
from backend import data_loader
|
||||||
|
|
||||||
|
data_loader._df_cache = None
|
||||||
|
data_loader._df_latest_cache = None
|
||||||
|
|
||||||
|
good_df = pd.DataFrame(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"urn": 1,
|
||||||
|
"school_name": "Legacy School",
|
||||||
|
"phase": "Primary",
|
||||||
|
"school_type": "Academy",
|
||||||
|
"status": "Open",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
def fake_read_sql(query, con):
|
||||||
|
calls.append(query)
|
||||||
|
if len(calls) == 1:
|
||||||
|
raise sqlalchemy.exc.ProgrammingError(
|
||||||
|
"(psycopg2.errors.UndefinedColumn) column s.phase_code does not exist",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
return good_df.copy()
|
||||||
|
|
||||||
|
monkeypatch.setattr(data_loader.pd, "read_sql", fake_read_sql)
|
||||||
|
|
||||||
|
try:
|
||||||
|
df = data_loader.load_school_data_as_dataframe()
|
||||||
|
finally:
|
||||||
|
data_loader._df_cache = None
|
||||||
|
data_loader._df_latest_cache = None
|
||||||
|
|
||||||
|
assert len(calls) == 2, "must retry with the legacy name-column query variant"
|
||||||
|
assert calls[1] is data_loader._MAIN_QUERY_LEGACY_NAMES
|
||||||
|
assert not df.empty
|
||||||
|
assert df["phase"].iloc[0] == "Primary"
|
||||||
|
assert df["status"].iloc[0] == "Open"
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ These are strengths the fixes below must not regress:
|
|||||||
- Uplift: **home 46% exit rate — decrease, moderate** and **share of sessions reaching a school page — increase, moderate** (assists the majority entry path at its first interaction).
|
- Uplift: **home 46% exit rate — decrease, moderate** and **share of sessions reaching a school page — increase, moderate** (assists the majority entry path at its first interaction).
|
||||||
|
|
||||||
- **P1.7 — The mobile hero omits the value proposition entirely** *(J1-F6)*
|
- **P1.7 — The mobile hero omits the value proposition entirely** *(J1-F6)*
|
||||||
- Evidence: desktop shows the "UPDATED WITH 2026/2027 ADMISSIONS RESULTS" trust badge and the "27,000+ schools… side by side, in one place" subheading; mobile renders only the poetic H1 ("Every school in England, *compared.*") and a bare search box (`j1-home-desktop-fold.png` vs `j1-home-mobile-fold.png`).
|
- Evidence: desktop shows the "UPDATED WITH 2026/2027 ADMISSIONS RESULTS" trust badge and the "24,000+ schools… side by side, in one place" subheading; mobile renders only the poetic H1 ("Every school in England, *compared.*") and a bare search box (`j1-home-desktop-fold.png` vs `j1-home-mobile-fold.png`).
|
||||||
- Criterion: mobile content parity; Nielsen #1 — first-visit orientation ("what is this, why trust it") absent on the primary viewport.
|
- Criterion: mobile content parity; Nielsen #1 — first-visit orientation ("what is this, why trust it") absent on the primary viewport.
|
||||||
- Argument: 63% of entries land here and 56% of traffic is mobile; a first-time visitor gets no statement of coverage, data source, or freshness above the fold. Weak value proposition at first glance is a classic bounce driver and plausibly a material slice of the 46% exit rate.
|
- Argument: 63% of entries land here and 56% of traffic is mobile; a first-time visitor gets no statement of coverage, data source, or freshness above the fold. Weak value proposition at first glance is a classic bounce driver and plausibly a material slice of the 46% exit rate.
|
||||||
- Recommendation: restore a compact version of the badge + one-line value prop under the mobile H1 (one text block; the fold has room above the deadline rail).
|
- Recommendation: restore a compact version of the badge + one-line value prop under the mobile H1 (one text block; the fold has room above the deadline rail).
|
||||||
|
|||||||
@@ -271,10 +271,10 @@ export function HomeView({ initialSchools, filters, totalSchools, howItWorks, ed
|
|||||||
freshness, standing in for the hidden eyebrow too) on phones,
|
freshness, standing in for the hidden eyebrow too) on phones,
|
||||||
where every line above the fold costs. */}
|
where every line above the fold costs. */}
|
||||||
<span className={styles.heroDescriptionFull}>
|
<span className={styles.heroDescriptionFull}>
|
||||||
<strong>27,000+ primary and secondary schools</strong> with Key Stage 2 SATs, GCSE results, Ofsted grades, progress scores and admissions data — side by side, in one place.
|
<strong>24,000+ primary and secondary schools</strong> with Key Stage 2 SATs, GCSE results, Ofsted grades, progress scores and admissions data — side by side, in one place.
|
||||||
</span>
|
</span>
|
||||||
<span className={styles.heroDescriptionCompact}>
|
<span className={styles.heroDescriptionCompact}>
|
||||||
<strong>27,000+ English schools</strong> — SATs, GCSEs, Ofsted & admissions, side by side. Updated for 2026/27.
|
<strong>24,000+ English schools</strong> — SATs, GCSEs, Ofsted & admissions, side by side. Updated for 2026/27.
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -94,23 +94,13 @@ def main() -> None:
|
|||||||
for code_col, name_col, dict_name, field_key in FIELDS:
|
for code_col, name_col, dict_name, field_key in FIELDS:
|
||||||
pairs = (
|
pairs = (
|
||||||
df[[code_col, name_col]]
|
df[[code_col, name_col]]
|
||||||
.loc[lambda d: d[code_col] != ""]
|
.loc[lambda d: (d[code_col] != "") & (d[name_col] != "")]
|
||||||
.drop_duplicates()
|
.drop_duplicates()
|
||||||
)
|
)
|
||||||
by_code: dict[int, set] = {}
|
mapping = sorted((int(c), n) for c, n in pairs.itertuples(index=False))
|
||||||
for c, n in pairs.itertuples(index=False):
|
dupes = len(mapping) - len({c for c, _ in mapping})
|
||||||
by_code.setdefault(int(c), set()).add(n)
|
if dupes:
|
||||||
mapping = []
|
sys.exit(f"{code_col}: {dupes} codes map to multiple names — investigate before generating")
|
||||||
for code, names in sorted(by_code.items()):
|
|
||||||
named = sorted(n for n in names if n != "")
|
|
||||||
if len(named) > 1:
|
|
||||||
sys.exit(f"{code_col}: code {code} maps to multiple names {named} — investigate before generating")
|
|
||||||
# Codes that only ever appear with a blank (name) are GIAS
|
|
||||||
# "not recorded" sentinels (e.g. ReligiousCharacter 99,
|
|
||||||
# AdmissionsPolicy 9). Map them to "" so the API serves the same
|
|
||||||
# empty string the old name pipeline did — the "Unknown (<code>)"
|
|
||||||
# path is reserved for genuinely new codes.
|
|
||||||
mapping.append((code, named[0] if named else ""))
|
|
||||||
lines = [f"{dict_name}: dict[int, str] = {{"]
|
lines = [f"{dict_name}: dict[int, str] = {{"]
|
||||||
for code, name in mapping:
|
for code, name in mapping:
|
||||||
escaped = name.replace('"', '\\"')
|
escaped = name.replace('"', '\\"')
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ OFFICIAL_SIXTH_FORM: dict[int, str] = {
|
|||||||
0: "Not applicable",
|
0: "Not applicable",
|
||||||
1: "Has a sixth form",
|
1: "Has a sixth form",
|
||||||
2: "Does not have a sixth form",
|
2: "Does not have a sixth form",
|
||||||
9: "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RELIGIOUS_CHARACTER: dict[int, str] = {
|
RELIGIOUS_CHARACTER: dict[int, str] = {
|
||||||
@@ -129,14 +128,12 @@ RELIGIOUS_CHARACTER: dict[int, str] = {
|
|||||||
47: "Reformed Baptist",
|
47: "Reformed Baptist",
|
||||||
48: "Roman Catholic/Anglican",
|
48: "Roman Catholic/Anglican",
|
||||||
49: "Sunni Deobandi",
|
49: "Sunni Deobandi",
|
||||||
99: "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ADMISSIONS_POLICY: dict[int, str] = {
|
ADMISSIONS_POLICY: dict[int, str] = {
|
||||||
0: "Not applicable",
|
0: "Not applicable",
|
||||||
2: "Selective",
|
2: "Selective",
|
||||||
4: "Non-selective",
|
4: "Non-selective",
|
||||||
9: "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ models:
|
|||||||
tests:
|
tests:
|
||||||
- accepted_values:
|
- accepted_values:
|
||||||
severity: warn
|
severity: warn
|
||||||
values: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 99]
|
values: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49]
|
||||||
- name: admissions_policy_code
|
- name: admissions_policy_code
|
||||||
tests:
|
tests:
|
||||||
- accepted_values:
|
- accepted_values:
|
||||||
severity: warn
|
severity: warn
|
||||||
values: [0, 2, 4, 9]
|
values: [0, 2, 4]
|
||||||
|
|
||||||
- name: dim_location
|
- name: dim_location
|
||||||
description: School location dimension with PostGIS geometry
|
description: School location dimension with PostGIS geometry
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ phase_of_education,7,All-through
|
|||||||
official_sixth_form,0,Not applicable
|
official_sixth_form,0,Not applicable
|
||||||
official_sixth_form,1,Has a sixth form
|
official_sixth_form,1,Has a sixth form
|
||||||
official_sixth_form,2,Does not have a sixth form
|
official_sixth_form,2,Does not have a sixth form
|
||||||
official_sixth_form,9,
|
|
||||||
religious_character,0,Does not apply
|
religious_character,0,Does not apply
|
||||||
religious_character,2,Church of England
|
religious_character,2,Church of England
|
||||||
religious_character,3,Roman Catholic
|
religious_character,3,Roman Catholic
|
||||||
@@ -101,8 +100,6 @@ religious_character,46,Protestant/Evangelical
|
|||||||
religious_character,47,Reformed Baptist
|
religious_character,47,Reformed Baptist
|
||||||
religious_character,48,Roman Catholic/Anglican
|
religious_character,48,Roman Catholic/Anglican
|
||||||
religious_character,49,Sunni Deobandi
|
religious_character,49,Sunni Deobandi
|
||||||
religious_character,99,
|
|
||||||
admissions_policy,0,Not applicable
|
admissions_policy,0,Not applicable
|
||||||
admissions_policy,2,Selective
|
admissions_policy,2,Selective
|
||||||
admissions_policy,4,Non-selective
|
admissions_policy,4,Non-selective
|
||||||
admissions_policy,9,
|
|
||||||
|
|||||||
|
Reference in New Issue
Block a user