FIxes
This commit is contained in:
parent
5f30928c64
commit
74d6dd7bf8
10 changed files with 306 additions and 149 deletions
|
|
@ -98,6 +98,60 @@ fn lookup_enum_value(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn build_property(
|
||||
row: usize,
|
||||
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];
|
||||
if value.is_finite() {
|
||||
features.insert(feat_name.clone(), value);
|
||||
}
|
||||
}
|
||||
|
||||
Property {
|
||||
address: non_empty_string(state.data.address(row)),
|
||||
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",
|
||||
),
|
||||
built_form: lookup_enum_value(
|
||||
feature_name_to_index, feature_data, num_features, enum_values, row, "Property type/built form",
|
||||
),
|
||||
duration: lookup_enum_value(
|
||||
feature_name_to_index, feature_data, num_features, enum_values, row, "Leashold/Freehold",
|
||||
),
|
||||
current_energy_rating: lookup_enum_value(
|
||||
feature_name_to_index, feature_data, num_features, 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",
|
||||
),
|
||||
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",
|
||||
),
|
||||
listing_url: state.data.listing_url(row).map(String::from),
|
||||
property_sub_type: state.data.property_sub_type(row).map(String::from),
|
||||
price_qualifier: state.data.price_qualifier(row).map(String::from),
|
||||
features,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_hexagon_properties(
|
||||
state: Arc<AppState>,
|
||||
Extension(user): Extension<OptionalUser>,
|
||||
|
|
@ -178,80 +232,10 @@ pub async fn get_hexagon_properties(
|
|||
.skip(offset)
|
||||
.take(limit)
|
||||
.map(|&row| {
|
||||
let mut features = FxHashMap::default();
|
||||
let base = row * num_features;
|
||||
for (feat_idx, feat_name) in feature_names.iter().enumerate() {
|
||||
// Skip enum features in the generic features map
|
||||
if enum_values.contains_key(&feat_idx) {
|
||||
continue;
|
||||
}
|
||||
let value = feature_data[base + feat_idx];
|
||||
if value.is_finite() {
|
||||
features.insert(feat_name.clone(), value);
|
||||
}
|
||||
}
|
||||
|
||||
Property {
|
||||
address: non_empty_string(state.data.address(row)),
|
||||
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",
|
||||
),
|
||||
built_form: lookup_enum_value(
|
||||
feature_name_to_index,
|
||||
feature_data,
|
||||
num_features,
|
||||
enum_values,
|
||||
row,
|
||||
"Property type/built form",
|
||||
),
|
||||
duration: lookup_enum_value(
|
||||
feature_name_to_index,
|
||||
feature_data,
|
||||
num_features,
|
||||
enum_values,
|
||||
row,
|
||||
"Leashold/Freehold",
|
||||
),
|
||||
current_energy_rating: lookup_enum_value(
|
||||
feature_name_to_index,
|
||||
feature_data,
|
||||
num_features,
|
||||
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",
|
||||
),
|
||||
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",
|
||||
),
|
||||
listing_url: state.data.listing_url(row).map(String::from),
|
||||
property_sub_type: state.data.property_sub_type(row).map(String::from),
|
||||
price_qualifier: state.data.price_qualifier(row).map(String::from),
|
||||
features,
|
||||
}
|
||||
build_property(
|
||||
row, &state, feature_names, feature_name_to_index, feature_data,
|
||||
num_features, enum_values,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue