More FE changes
This commit is contained in:
parent
f114ada255
commit
a48eb945e0
48 changed files with 4127 additions and 1751 deletions
|
|
@ -4,10 +4,40 @@ mod postcodes;
|
|||
mod property;
|
||||
pub mod travel_time;
|
||||
|
||||
fn panic_payload_message(payload: &(dyn std::any::Any + Send)) -> String {
|
||||
if let Some(message) = payload.downcast_ref::<&'static str>() {
|
||||
(*message).to_string()
|
||||
} else if let Some(message) = payload.downcast_ref::<String>() {
|
||||
message.clone()
|
||||
} else {
|
||||
"unknown panic payload".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn run_polars_io<T, F>(work: F) -> anyhow::Result<T>
|
||||
where
|
||||
T: Send,
|
||||
F: FnOnce() -> anyhow::Result<T> + Send,
|
||||
{
|
||||
if tokio::runtime::Handle::try_current().is_err() {
|
||||
return work();
|
||||
}
|
||||
|
||||
std::thread::scope(|scope| {
|
||||
scope.spawn(work).join().map_err(|payload| {
|
||||
anyhow::anyhow!(
|
||||
"Polars worker thread panicked: {}",
|
||||
panic_payload_message(payload.as_ref())
|
||||
)
|
||||
})?
|
||||
})
|
||||
}
|
||||
|
||||
pub use places::{normalize_search_text, PlaceData};
|
||||
pub use poi::{POICategoryGroup, POIData};
|
||||
pub use poi::{resolve_poi_category_filter, POICategoryGroup, POIData};
|
||||
pub use postcodes::{OutcodeData, PostcodeData};
|
||||
pub use property::{
|
||||
precompute_h3, FeatureStats, Histogram, PropertyData, QuantRef, RenovationEvent,
|
||||
precompute_h3, FeatureStats, Histogram, PostcodePoiMetrics, PropertyData, QuantRef,
|
||||
RenovationEvent,
|
||||
};
|
||||
pub use travel_time::{slugify, TravelTimeStore};
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use crate::auth::OptionalUser;
|
|||
use crate::consts::{AI_FILTERS_MAX_TOKENS, AI_FILTERS_TEMPERATURE, AI_FILTERS_WEEKLY_TOKEN_LIMIT};
|
||||
use crate::data::slugify;
|
||||
use crate::data::travel_time::TravelData;
|
||||
use crate::parsing::{parse_filters, row_passes_filters};
|
||||
use crate::parsing::{parse_filters_with_poi, row_passes_filters, row_passes_poi_filters};
|
||||
use crate::pocketbase::{get_superuser_token, log_ai_query};
|
||||
use crate::routes::{FeatureInfo, FeaturesResponse};
|
||||
use crate::state::{AppState, SharedState};
|
||||
|
|
@ -655,14 +655,17 @@ fn count_matching_rows(
|
|||
let filter_str = filters_to_filter_string(filters);
|
||||
|
||||
let quant = state.data.quant_ref();
|
||||
let (parsed_filters, parsed_enum_filters) = if filter_str.is_empty() {
|
||||
(Vec::new(), Vec::new())
|
||||
let poi_quant = state.data.poi_metrics.quant_ref();
|
||||
let (parsed_filters, parsed_enum_filters, parsed_poi_filters) = if filter_str.is_empty() {
|
||||
(Vec::new(), Vec::new(), Vec::new())
|
||||
} else {
|
||||
match parse_filters(
|
||||
match parse_filters_with_poi(
|
||||
Some(&filter_str),
|
||||
&state.feature_name_to_index,
|
||||
&state.data.enum_values,
|
||||
&quant,
|
||||
&state.data.poi_metrics.name_to_index,
|
||||
&poi_quant,
|
||||
) {
|
||||
Ok(f) => f,
|
||||
Err(err) => {
|
||||
|
|
@ -686,6 +689,7 @@ fn count_matching_rows(
|
|||
let num_features = state.data.num_features;
|
||||
let num_rows = state.data.lat.len();
|
||||
let (pc_interner, pc_keys) = state.data.postcode_parts();
|
||||
let has_poi_filters = !parsed_poi_filters.is_empty();
|
||||
|
||||
let mut count = 0usize;
|
||||
for (row, pc_key) in pc_keys.iter().enumerate().take(num_rows) {
|
||||
|
|
@ -698,6 +702,11 @@ fn count_matching_rows(
|
|||
) {
|
||||
continue;
|
||||
}
|
||||
if has_poi_filters
|
||||
&& !row_passes_poi_filters(row, &parsed_poi_filters, &state.data.poi_metrics)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if has_travel {
|
||||
let postcode = pc_interner.resolve(pc_key);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use axum::extract::{Path, State};
|
|||
use axum::http::{header, StatusCode};
|
||||
use axum::response::{Html, IntoResponse, Response};
|
||||
use axum::Json;
|
||||
use rand::Rng;
|
||||
use rand::RngExt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::warn;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ use std::sync::Arc;
|
|||
use axum::extract::{Path, Query, State};
|
||||
use axum::http::{header, StatusCode};
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use pmtiles::async_reader::AsyncPmTilesReader;
|
||||
use pmtiles::MmapBackend;
|
||||
use pmtiles::{AsyncPmTilesReader, MmapBackend, TileCoord};
|
||||
use serde::Deserialize;
|
||||
use tracing::warn;
|
||||
|
||||
|
|
@ -14,7 +13,15 @@ pub async fn get_tile(
|
|||
State(reader): State<Arc<TileReader>>,
|
||||
Path((zoom, col, row)): Path<(u8, u32, u32)>,
|
||||
) -> Response {
|
||||
match reader.get_tile(zoom, col as u64, row as u64).await {
|
||||
let tile_coord = match TileCoord::new(zoom, col, row) {
|
||||
Ok(tile_coord) => tile_coord,
|
||||
Err(err) => {
|
||||
warn!(zoom, col, row, error = %err, "Invalid tile coordinate");
|
||||
return StatusCode::BAD_REQUEST.into_response();
|
||||
}
|
||||
};
|
||||
|
||||
match reader.get_tile(tile_coord).await {
|
||||
Ok(Some(tile_bytes)) => (
|
||||
StatusCode::OK,
|
||||
[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue