Deploy again
This commit is contained in:
parent
ffe080adef
commit
787428f1a5
18 changed files with 717 additions and 223 deletions
|
|
@ -437,82 +437,11 @@ impl PropertyData {
|
|||
tracing::info!(rows = prop_count, "Properties joined with postcodes");
|
||||
|
||||
// Load online listings (buy + rent) — these have their own lat/lon.
|
||||
// Normalize column names from finder output to server-expected names.
|
||||
// strict=false: columns already using the new name are silently skipped.
|
||||
// Expects the new finder parquet format with human-readable column names.
|
||||
let load_listings = |path: &Path, label: &str| -> anyhow::Result<DataFrame> {
|
||||
tracing::info!("Loading {} listings from {:?}", label, path);
|
||||
let mut lf = LazyFrame::scan_parquet(path, Default::default())
|
||||
let lf = LazyFrame::scan_parquet(path, Default::default())
|
||||
.with_context(|| format!("Failed to scan {label} listings parquet"))?;
|
||||
let schema = lf
|
||||
.collect_schema()
|
||||
.with_context(|| format!("Failed to read {label} listings schema"))?;
|
||||
|
||||
// Rename raw finder columns → server-expected names (no-op if already renamed)
|
||||
let lf = lf.rename(
|
||||
[
|
||||
"postcode",
|
||||
"address",
|
||||
"latitude",
|
||||
"longitude",
|
||||
"bedrooms",
|
||||
"bathrooms",
|
||||
"total_rooms",
|
||||
"tenure",
|
||||
"property_type",
|
||||
"property_sub_type",
|
||||
"price_qualifier",
|
||||
"floorspace_sqm",
|
||||
"url",
|
||||
"features",
|
||||
],
|
||||
[
|
||||
"Postcode",
|
||||
"Address per Property Register",
|
||||
"lat",
|
||||
"lon",
|
||||
"Bedrooms",
|
||||
"Bathrooms",
|
||||
"Number of bedrooms & living rooms",
|
||||
"Leashold/Freehold",
|
||||
"Property type",
|
||||
"Property sub-type",
|
||||
"Price qualifier",
|
||||
"Total floor area (sqm)",
|
||||
"Listing URL",
|
||||
"Listing features",
|
||||
],
|
||||
false,
|
||||
);
|
||||
|
||||
// Derive missing columns for raw finder output that doesn't have them
|
||||
let listing_status = if label == "buy" {
|
||||
"For sale"
|
||||
} else {
|
||||
"For rent"
|
||||
};
|
||||
let lf = if schema.get("Listing status").is_none() {
|
||||
lf.with_column(lit(listing_status).alias("Listing status"))
|
||||
} else {
|
||||
lf
|
||||
};
|
||||
let lf = if schema.get("Asking price").is_none() && schema.get("price").is_some() {
|
||||
if label == "buy" {
|
||||
lf.with_column(col("price").alias("Asking price"))
|
||||
} else {
|
||||
// Normalize rent to monthly: weekly×52/12, yearly÷12
|
||||
lf.with_column(
|
||||
when(col("price_frequency").eq(lit("weekly")))
|
||||
.then(col("price").cast(DataType::Float64) * lit(52.0 / 12.0))
|
||||
.when(col("price_frequency").eq(lit("yearly")))
|
||||
.then(col("price").cast(DataType::Float64) / lit(12.0))
|
||||
.otherwise(col("price").cast(DataType::Float64))
|
||||
.cast(DataType::Int64)
|
||||
.alias("Asking rent (monthly)"),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
lf
|
||||
};
|
||||
|
||||
// Join with postcodes for area features (listings have their own lat/lon)
|
||||
let pc_no_coords = postcode_df.clone().lazy().drop(["lat", "lon"]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue