all good
This commit is contained in:
parent
47d89f6fad
commit
017902b8e6
82 changed files with 331466 additions and 54841 deletions
|
|
@ -1,6 +1,9 @@
|
|||
import polars as pl
|
||||
from pyproj import Transformer
|
||||
|
||||
from pipeline.download.places import (
|
||||
_assign_london_display_city,
|
||||
_display_city_from_tags,
|
||||
_is_dlr_station,
|
||||
_is_tram_station,
|
||||
_naptan_dlr_stations,
|
||||
|
|
@ -9,6 +12,22 @@ from pipeline.download.places import (
|
|||
_station_display_name,
|
||||
)
|
||||
|
||||
WGS84_TO_BNG = Transformer.from_crs("EPSG:4326", "EPSG:27700", always_xy=True)
|
||||
|
||||
|
||||
def _postcode_row(postcode: str, lat: float, lon: float, *, london: bool) -> dict:
|
||||
easting, northing = WGS84_TO_BNG.transform(lon, lat)
|
||||
return {
|
||||
"pcds": postcode,
|
||||
"doterm": None,
|
||||
"ctry25cd": "E92000001",
|
||||
"east1m": int(round(easting)),
|
||||
"north1m": int(round(northing)),
|
||||
"rgn25cd": "E12000007" if london else "E12000008",
|
||||
"lad25cd": "E09000008" if london else "E07000208",
|
||||
"cty25cd": "E13000002" if london else "E10000030",
|
||||
}
|
||||
|
||||
|
||||
def test_dlr_light_rail_is_not_treated_as_tram():
|
||||
dlr_tags = {
|
||||
|
|
@ -144,5 +163,56 @@ def test_ofs_universities_extracts_university_title_rows_with_postcode_coords():
|
|||
"lon": -1.2643,
|
||||
"population": 0,
|
||||
"travel_destination": True,
|
||||
"display_city": None,
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_display_city_from_tags_uses_explicit_london_context():
|
||||
assert _display_city_from_tags({"is_in": "Croydon, London, UK"}) == "London"
|
||||
assert _display_city_from_tags({"is_in": "Croydon, Cambridgeshire, UK"}) is None
|
||||
|
||||
|
||||
def test_assign_london_display_city_uses_nearest_active_postcode_admin(tmp_path):
|
||||
postcodes = tmp_path / "postcodes.parquet"
|
||||
pl.DataFrame(
|
||||
[
|
||||
_postcode_row("CR0 1SZ", 51.371273, -0.101793, london=True),
|
||||
_postcode_row("KT19 8AG", 51.3326, -0.2678, london=False),
|
||||
]
|
||||
).write_parquet(postcodes)
|
||||
|
||||
places = [
|
||||
{
|
||||
"name": "Croydon",
|
||||
"place_type": "town",
|
||||
"lat": 51.3713049,
|
||||
"lon": -0.101957,
|
||||
"population": 173314,
|
||||
"travel_destination": False,
|
||||
"display_city": None,
|
||||
},
|
||||
{
|
||||
"name": "East Croydon railway station",
|
||||
"place_type": "station",
|
||||
"lat": 51.375845,
|
||||
"lon": -0.092732,
|
||||
"population": 0,
|
||||
"travel_destination": True,
|
||||
"display_city": None,
|
||||
},
|
||||
{
|
||||
"name": "Epsom",
|
||||
"place_type": "town",
|
||||
"lat": 51.3326,
|
||||
"lon": -0.2678,
|
||||
"population": 31489,
|
||||
"travel_destination": False,
|
||||
"display_city": None,
|
||||
},
|
||||
]
|
||||
|
||||
assigned = _assign_london_display_city(places, postcodes)
|
||||
|
||||
assert assigned == 2
|
||||
assert [place["display_city"] for place in places] == ["London", "London", None]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue