diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 87048f7..795ba27 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -5,6 +5,7 @@ extern crate log; use std::collections::HashSet; use std::sync::Once; +use std::time::Duration; use chrono::NaiveTime; use geo::Coord; @@ -158,8 +159,14 @@ impl MapModel { ) -> Result { let req: ScoreRequest = serde_wasm_bindgen::from_value(input)?; let poi_kinds: HashSet = req.poi_kinds.into_iter().collect(); - score::calculate(&self.graph, poi_kinds, Timer::new("score", progress_cb)) - .map_err(err_to_js) + let limit = Duration::from_secs(req.max_seconds); + score::calculate( + &self.graph, + poi_kinds, + limit, + Timer::new("score", progress_cb), + ) + .map_err(err_to_js) } } @@ -188,6 +195,7 @@ pub struct RouteRequest { #[derive(Deserialize)] pub struct ScoreRequest { poi_kinds: Vec, + max_seconds: u64, } fn err_to_js(err: E) -> JsValue { diff --git a/backend/src/score.rs b/backend/src/score.rs index fb0c0ff..ef70af3 100644 --- a/backend/src/score.rs +++ b/backend/src/score.rs @@ -9,8 +9,12 @@ use crate::timer::Timer; // Return GeoJSON points for each POI, with info about that POI, a score to the nearest cycle // parking, and the location of that parking -pub fn calculate(graph: &Graph, poi_kinds: HashSet, mut timer: Timer) -> Result { - let limit = Duration::from_secs(10 * 60); +pub fn calculate( + graph: &Graph, + poi_kinds: HashSet, + limit: Duration, + mut timer: Timer, +) -> Result { // Exact time doesn't matter let start_time = NaiveTime::from_hms_opt(7, 0, 0).unwrap(); let end_time = start_time + limit; diff --git a/web/src/ScoreMode.svelte b/web/src/ScoreMode.svelte index 4d65c27..5624f97 100644 --- a/web/src/ScoreMode.svelte +++ b/web/src/ScoreMode.svelte @@ -16,18 +16,20 @@ import { makeColorRamp } from "svelte-utils/map"; let loading: string[] = []; + let maxSeconds = 600; let poiKinds: string[] = []; let showParking = true; let gj: FeatureCollection | null = null; - $: updateScores(poiKinds); + $: updateScores(poiKinds, maxSeconds); - async function updateScores(_x: string[]) { + async function updateScores(_x: string[], _y: number) { loading = [...loading, "Calculating scores"]; gj = await $backend!.score( { poiKinds, + maxSeconds, }, Comlink.proxy(progressCb), ); @@ -39,8 +41,8 @@ let routeGj: FeatureCollection | null = null; - let limits = Array.from(Array(6).keys()).map( - (i) => ((60 * 10) / (6 - 1)) * i, + $: limits = Array.from(Array(6).keys()).map( + (i) => (maxSeconds / (6 - 1)) * i, ); let hoveredAmenity: Feature | null; @@ -94,6 +96,11 @@ + +