Various fixes

This commit is contained in:
Andras Schmelczer 2026-02-04 22:29:42 +00:00
parent 34a4d0ba86
commit 55598aaaa0
14 changed files with 1250 additions and 130 deletions

View file

@ -66,7 +66,7 @@ fn non_empty_string(text: &str) -> Option<String> {
/// Look up an enum feature value by trying multiple possible column names.
/// Uses the unified feature model: enum values stored as f32 indices in feature_data.
fn lookup_enum_value(
feature_names: &[String],
feature_name_to_index: &FxHashMap<String, usize>,
feature_data: &[f32],
num_features: usize,
enum_values: &FxHashMap<usize, Vec<String>>,
@ -74,7 +74,7 @@ fn lookup_enum_value(
names: &[&str],
) -> Option<String> {
for name in names {
if let Some(feat_idx) = feature_names.iter().position(|feat_name| feat_name == *name) {
if let Some(&feat_idx) = feature_name_to_index.get(*name) {
if let Some(values) = enum_values.get(&feat_idx) {
let value = feature_data[row * num_features + feat_idx];
if value.is_finite() {
@ -120,7 +120,7 @@ pub async fn get_hexagon_properties(
let filters_str = params.filters.clone();
let (parsed_filters, parsed_enum_filters) = parse_filters(
params.filters.as_deref(),
&state.data.feature_names,
&state.feature_name_to_index,
&state.data.enum_values,
);
let num_filters = parsed_filters.len() + parsed_enum_filters.len();
@ -134,6 +134,7 @@ pub async fn get_hexagon_properties(
let num_features = state.data.num_features;
let feature_data = &state.data.feature_data;
let feature_names = &state.data.feature_names;
let feature_name_to_index = &state.feature_name_to_index;
let enum_values = &state.data.enum_values;
let (min_lat, min_lon, max_lat, max_lon) = h3_cell_bounds(cell, 0.001);
@ -199,7 +200,7 @@ pub async fn get_hexagon_properties(
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_names,
feature_name_to_index,
feature_data,
num_features,
enum_values,
@ -207,7 +208,7 @@ pub async fn get_hexagon_properties(
&["Property type", "epc_property_type", "pp_property_type"],
),
built_form: lookup_enum_value(
feature_names,
feature_name_to_index,
feature_data,
num_features,
enum_values,
@ -215,7 +216,7 @@ pub async fn get_hexagon_properties(
&["Property type/built form", "built_form"],
),
duration: lookup_enum_value(
feature_names,
feature_name_to_index,
feature_data,
num_features,
enum_values,
@ -223,7 +224,7 @@ pub async fn get_hexagon_properties(
&["Leashold/Freehold", "duration"],
),
current_energy_rating: lookup_enum_value(
feature_names,
feature_name_to_index,
feature_data,
num_features,
enum_values,
@ -231,7 +232,7 @@ pub async fn get_hexagon_properties(
&["Current energy rating", "current_energy_rating"],
),
potential_energy_rating: lookup_enum_value(
feature_names,
feature_name_to_index,
feature_data,
num_features,
enum_values,