Add fitzrovia commute
This commit is contained in:
parent
c388059f68
commit
7a2ff48201
2 changed files with 46 additions and 40 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import argparse
|
||||
|
||||
import polars as pl
|
||||
from pathlib import Path
|
||||
|
||||
|
|
@ -6,12 +7,35 @@ MIN_PRICE = 10_000
|
|||
MIN_FLOOR_AREA_M2 = 10
|
||||
|
||||
|
||||
def _join_journey_times(
|
||||
wide: pl.LazyFrame,
|
||||
journey_times_path: Path,
|
||||
destination_name: str,
|
||||
) -> pl.LazyFrame:
|
||||
"""Join journey times for a single destination, renaming columns appropriately."""
|
||||
journey_times = (
|
||||
pl.scan_parquet(journey_times_path)
|
||||
.select(
|
||||
"postcode",
|
||||
pl.col("public_transport_quick_minutes").alias(
|
||||
f"Public transport to {destination_name} (mins)"
|
||||
),
|
||||
pl.col("cycling_minutes").alias(f"Cycling to {destination_name} (mins)"),
|
||||
)
|
||||
.sort(f"Public transport to {destination_name} (mins)", nulls_last=True)
|
||||
.group_by("postcode")
|
||||
.first()
|
||||
)
|
||||
return wide.join(journey_times, on="postcode", how="left")
|
||||
|
||||
|
||||
def _build_wide(
|
||||
epc_pp_path: Path,
|
||||
arcgis_path: Path,
|
||||
iod_path: Path,
|
||||
poi_proximity_path: Path,
|
||||
journey_times_path: Path,
|
||||
journey_times_bank_path: Path,
|
||||
journey_times_fitzrovia_path: Path,
|
||||
ethnicity_path: Path,
|
||||
crime_path: Path,
|
||||
noise_path: Path,
|
||||
|
|
@ -30,19 +54,8 @@ def _build_wide(
|
|||
)
|
||||
wide = wide.join(arcgis, on="postcode", how="inner")
|
||||
|
||||
journey_times = (
|
||||
pl.scan_parquet(journey_times_path)
|
||||
.select(
|
||||
"postcode",
|
||||
"public_transport_easy_minutes",
|
||||
"public_transport_quick_minutes",
|
||||
"cycling_minutes",
|
||||
)
|
||||
.sort("public_transport_quick_minutes", nulls_last=True)
|
||||
.group_by("postcode")
|
||||
.first()
|
||||
)
|
||||
wide = wide.join(journey_times, on="postcode", how="left")
|
||||
wide = _join_journey_times(wide, journey_times_bank_path, "Bank")
|
||||
wide = _join_journey_times(wide, journey_times_fitzrovia_path, "Fitzrovia")
|
||||
|
||||
iod = pl.scan_parquet(iod_path)
|
||||
wide = wide.join(iod, left_on="lsoa21", right_on="LSOA code (2021)", how="left")
|
||||
|
|
@ -227,10 +240,16 @@ def main():
|
|||
help="POI proximity counts parquet file (optional)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--journey-times",
|
||||
required=True,
|
||||
"--journey-times-bank",
|
||||
type=Path,
|
||||
help="Journey times parquet file (optional)",
|
||||
default=None,
|
||||
help="Journey times to Bank parquet file",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--journey-times-fitzrovia",
|
||||
type=Path,
|
||||
default=None,
|
||||
help="Journey times to Fitzrovia parquet file",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--ethnicity",
|
||||
|
|
@ -269,7 +288,8 @@ def main():
|
|||
arcgis_path=args.arcgis,
|
||||
iod_path=args.iod,
|
||||
poi_proximity_path=args.poi_proximity,
|
||||
journey_times_path=args.journey_times,
|
||||
journey_times_bank_path=args.journey_times_bank,
|
||||
journey_times_fitzrovia_path=args.journey_times_fitzrovia,
|
||||
ethnicity_path=args.ethnicity,
|
||||
crime_path=args.crime,
|
||||
noise_path=args.noise,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue