These work
This commit is contained in:
parent
3599803589
commit
1588c01b19
19 changed files with 260 additions and 201 deletions
|
|
@ -90,7 +90,8 @@ pub async fn get_hexagon_stats(
|
|||
params.filters.as_deref(),
|
||||
&state.feature_name_to_index,
|
||||
&state.data.enum_values,
|
||||
);
|
||||
)
|
||||
.map_err(|err| (StatusCode::BAD_REQUEST, err))?;
|
||||
let num_filters = parsed_filters.len() + parsed_enum_filters.len();
|
||||
|
||||
let (fields_specified, field_set) = parse_field_set(params.fields.as_deref());
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ pub async fn get_postcode_stats(
|
|||
params.filters.as_deref(),
|
||||
&state.feature_name_to_index,
|
||||
&state.data.enum_values,
|
||||
);
|
||||
)
|
||||
.map_err(|err| (StatusCode::BAD_REQUEST, err))?;
|
||||
let num_filters = parsed_filters.len() + parsed_enum_filters.len();
|
||||
|
||||
let (fields_specified, field_set) = parse_field_set(params.fields.as_deref());
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ fn non_empty_string(text: &str) -> Option<String> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Look up an enum feature value by trying multiple possible column names.
|
||||
/// Look up an enum feature value by column name.
|
||||
/// Uses the unified feature model: enum values stored as f32 indices in feature_data.
|
||||
fn lookup_enum_value(
|
||||
feature_name_to_index: &FxHashMap<String, usize>,
|
||||
|
|
@ -71,22 +71,17 @@ fn lookup_enum_value(
|
|||
num_features: usize,
|
||||
enum_values: &FxHashMap<usize, Vec<String>>,
|
||||
row: usize,
|
||||
names: &[&str],
|
||||
name: &str,
|
||||
) -> Option<String> {
|
||||
for name in names {
|
||||
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() {
|
||||
let idx = value as usize;
|
||||
if let Some(str_value) = values.get(idx) {
|
||||
return Some(str_value.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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];
|
||||
if value.is_finite() {
|
||||
let idx = value as usize;
|
||||
values.get(idx).cloned()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub async fn get_hexagon_properties(
|
||||
|
|
@ -111,7 +106,8 @@ pub async fn get_hexagon_properties(
|
|||
params.filters.as_deref(),
|
||||
&state.feature_name_to_index,
|
||||
&state.data.enum_values,
|
||||
);
|
||||
)
|
||||
.map_err(|err| (StatusCode::BAD_REQUEST, err))?;
|
||||
let num_filters = parsed_filters.len() + parsed_enum_filters.len();
|
||||
|
||||
let result = tokio::task::spawn_blocking(move || {
|
||||
|
|
@ -182,7 +178,7 @@ pub async fn get_hexagon_properties(
|
|||
num_features,
|
||||
enum_values,
|
||||
row,
|
||||
&["Property type", "epc_property_type", "pp_property_type"],
|
||||
"Property type",
|
||||
),
|
||||
built_form: lookup_enum_value(
|
||||
feature_name_to_index,
|
||||
|
|
@ -190,7 +186,7 @@ pub async fn get_hexagon_properties(
|
|||
num_features,
|
||||
enum_values,
|
||||
row,
|
||||
&["Property type/built form", "built_form"],
|
||||
"Property type/built form",
|
||||
),
|
||||
duration: lookup_enum_value(
|
||||
feature_name_to_index,
|
||||
|
|
@ -198,7 +194,7 @@ pub async fn get_hexagon_properties(
|
|||
num_features,
|
||||
enum_values,
|
||||
row,
|
||||
&["Leashold/Freehold", "duration"],
|
||||
"Leashold/Freehold",
|
||||
),
|
||||
current_energy_rating: lookup_enum_value(
|
||||
feature_name_to_index,
|
||||
|
|
@ -206,7 +202,7 @@ pub async fn get_hexagon_properties(
|
|||
num_features,
|
||||
enum_values,
|
||||
row,
|
||||
&["Current energy rating", "current_energy_rating"],
|
||||
"Current energy rating",
|
||||
),
|
||||
potential_energy_rating: lookup_enum_value(
|
||||
feature_name_to_index,
|
||||
|
|
@ -214,7 +210,7 @@ pub async fn get_hexagon_properties(
|
|||
num_features,
|
||||
enum_values,
|
||||
row,
|
||||
&["Potential energy rating", "potential_energy_rating"],
|
||||
"Potential energy rating",
|
||||
),
|
||||
lat: state.data.lat[row],
|
||||
lon: state.data.lon[row],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue