new demo mode & tenure
Some checks failed
Build and publish Docker image / build-and-push (push) Successful in 8m43s
CI / Check (push) Failing after 8m49s

This commit is contained in:
Andras Schmelczer 2026-06-17 07:54:30 +01:00
parent 7656f24544
commit 4a0f00f2a4
64 changed files with 2875 additions and 338 deletions

View file

@ -15,7 +15,7 @@ use crate::state::SharedState;
use crate::utils::normalize_postcode;
use super::hexagon_stats::{
parse_area_stats_field_set, top_filter_exclusions, HexagonStatsResponse,
parse_area_stats_field_set, top_filter_exclusions, EnumFeatureStats, HexagonStatsResponse,
};
use super::stats;
use super::travel_time::{load_travel_data, parse_optional_travel, row_passes_travel_filters};
@ -38,6 +38,7 @@ pub struct PostcodeStatsParams {
pub async fn get_postcode_stats(
State(shared): State<Arc<SharedState>>,
Extension(user): Extension<OptionalUser>,
Extension(geo): Extension<crate::demo_zone::DemoZone>,
Query(params): Query<PostcodeStatsParams>,
) -> Result<Json<HexagonStatsResponse>, axum::response::Response> {
let state = shared.load_state();
@ -63,6 +64,7 @@ pub async fn get_postcode_stats(
&user.0,
centroid_lat as f64,
centroid_lon as f64,
geo.free_zone,
share_bounds,
)?;
@ -157,7 +159,7 @@ pub async fn get_postcode_stats(
&field_set,
);
let (mut numeric_features, enum_features_out) = stats::compute_feature_stats(
let (mut numeric_features, mut enum_features_out) = stats::compute_feature_stats(
&matching_rows,
&state.data,
&state.data.feature_names,
@ -173,6 +175,31 @@ pub async fn get_postcode_stats(
&field_set,
));
// The council-house count is an attribute of the postcode itself, not of
// the currently filter-matching subset: recompute it over every property
// in the postcode so toggling filters never changes it. (When no filters
// are applied, `area_rows == matching_rows` and this is a no-op.)
if let Some(&council_idx) = state
.feature_name_to_index
.get(crate::consts::FORMER_COUNCIL_HOUSE_FEATURE)
{
enum_features_out.retain(|f| f.name != crate::consts::FORMER_COUNCIL_HOUSE_FEATURE);
let included = !fields_specified
|| field_set.contains(crate::consts::FORMER_COUNCIL_HOUSE_FEATURE);
if included {
if let Some(counts) =
stats::compute_enum_feature_counts(&area_rows, &state.data, council_idx)
{
if !counts.is_empty() {
enum_features_out.push(EnumFeatureStats {
name: crate::consts::FORMER_COUNCIL_HOUSE_FEATURE.to_string(),
counts,
});
}
}
}
}
let elapsed = start_time.elapsed();
info!(
postcode = %postcode_str,