This commit is contained in:
Andras Schmelczer 2026-03-15 17:38:26 +00:00
parent 80c093b7ba
commit f72c43a9fa
101 changed files with 2168 additions and 1177 deletions

View file

@ -11,12 +11,12 @@ use tracing::{info, warn};
use crate::auth::OptionalUser;
use crate::consts::{DEFAULT_PROPERTIES_LIMIT, MAX_PROPERTIES_LIMIT};
use crate::data::RenovationEvent;
use crate::licensing::check_license_bounds;
use crate::parsing::{
cell_for_row, h3_cell_bounds, needs_parent, parse_filters, row_passes_filters,
validate_h3_resolution,
};
use crate::data::RenovationEvent;
use crate::state::AppState;
#[derive(Deserialize)]
@ -78,18 +78,17 @@ fn non_empty_string(text: &str) -> Option<String> {
}
/// Look up an enum feature value by column name.
/// Uses the unified feature model: enum values stored as f32 indices in feature_data.
/// Uses the unified feature model: enum values stored as u16 indices in feature_data.
fn lookup_enum_value(
feature_name_to_index: &FxHashMap<String, usize>,
feature_data: &[f32],
num_features: usize,
data: &crate::data::PropertyData,
enum_values: &FxHashMap<usize, Vec<String>>,
row: usize,
name: &str,
) -> Option<String> {
let &feat_idx = feature_name_to_index.get(name)?;
let values = enum_values.get(&feat_idx)?;
let value = feature_data[row * num_features + feat_idx];
let value = data.get_feature(row, feat_idx);
if value.is_finite() {
let idx = value as usize;
values.get(idx).cloned()
@ -103,17 +102,14 @@ pub fn build_property(
state: &AppState,
feature_names: &[String],
feature_name_to_index: &FxHashMap<String, usize>,
feature_data: &[f32],
num_features: usize,
enum_values: &FxHashMap<usize, Vec<String>>,
) -> Property {
let mut features = FxHashMap::default();
let base = row * num_features;
for (feat_idx, feat_name) in feature_names.iter().enumerate() {
if enum_values.contains_key(&feat_idx) {
continue;
}
let value = feature_data[base + feat_idx];
let value = state.data.get_feature(row, feat_idx);
if value.is_finite() {
features.insert(feat_name.clone(), value);
}
@ -124,26 +120,50 @@ pub fn build_property(
postcode: non_empty_string(state.data.postcode(row)),
is_construction_date_approximate: Some(state.data.is_approx_build_date(row)),
property_type: lookup_enum_value(
feature_name_to_index, feature_data, num_features, enum_values, row, "Property type",
feature_name_to_index,
&state.data,
enum_values,
row,
"Property type",
),
built_form: lookup_enum_value(
feature_name_to_index, feature_data, num_features, enum_values, row, "Property type/built form",
feature_name_to_index,
&state.data,
enum_values,
row,
"Property type/built form",
),
duration: lookup_enum_value(
feature_name_to_index, feature_data, num_features, enum_values, row, "Leasehold/Freehold",
feature_name_to_index,
&state.data,
enum_values,
row,
"Leasehold/Freehold",
),
current_energy_rating: lookup_enum_value(
feature_name_to_index, feature_data, num_features, enum_values, row, "Current energy rating",
feature_name_to_index,
&state.data,
enum_values,
row,
"Current energy rating",
),
potential_energy_rating: lookup_enum_value(
feature_name_to_index, feature_data, num_features, enum_values, row, "Potential energy rating",
feature_name_to_index,
&state.data,
enum_values,
row,
"Potential energy rating",
),
lat: state.data.lat[row],
lon: state.data.lon[row],
renovation_history: state.data.renovation_history(row).to_vec(),
listing_features: state.data.listing_features(row).to_vec(),
listing_status: lookup_enum_value(
feature_name_to_index, feature_data, num_features, enum_values, row, "Listing status",
feature_name_to_index,
&state.data,
enum_values,
row,
"Listing status",
),
listing_url: state.data.listing_url(row).map(String::from),
property_sub_type: state.data.property_sub_type(row).map(String::from),
@ -175,10 +195,12 @@ pub async fn get_hexagon_properties(
check_license_bounds(&user.0, h3_bounds)?;
let h3_str = params.h3;
let quant = state.data.quant_ref();
let (parsed_filters, parsed_enum_filters) = parse_filters(
params.filters.as_deref(),
&state.feature_name_to_index,
&state.data.enum_values,
&quant,
)
.map_err(|err| (StatusCode::BAD_REQUEST, err).into_response())?;
let num_filters = parsed_filters.len() + parsed_enum_filters.len();
@ -233,8 +255,11 @@ pub async fn get_hexagon_properties(
.take(limit)
.map(|&row| {
build_property(
row, &state, feature_names, feature_name_to_index, feature_data,
num_features, enum_values,
row,
&state,
feature_names,
feature_name_to_index,
enum_values,
)
})
.collect();