Skip to content

Commit

Permalink
Configure the max time threshold. #5
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jun 2, 2024
1 parent f4525f6 commit 703460f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
12 changes: 10 additions & 2 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,8 +159,14 @@ impl MapModel {
) -> Result<String, JsValue> {
let req: ScoreRequest = serde_wasm_bindgen::from_value(input)?;
let poi_kinds: HashSet<String> = 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)
}
}

Expand Down Expand Up @@ -188,6 +195,7 @@ pub struct RouteRequest {
#[derive(Deserialize)]
pub struct ScoreRequest {
poi_kinds: Vec<String>,
max_seconds: u64,
}

fn err_to_js<E: std::fmt::Display>(err: E) -> JsValue {
Expand Down
8 changes: 6 additions & 2 deletions backend/src/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, mut timer: Timer) -> Result<String> {
let limit = Duration::from_secs(10 * 60);
pub fn calculate(
graph: &Graph,
poi_kinds: HashSet<String>,
limit: Duration,
mut timer: Timer,
) -> Result<String> {
// Exact time doesn't matter
let start_time = NaiveTime::from_hms_opt(7, 0, 0).unwrap();
let end_time = start_time + limit;
Expand Down
26 changes: 16 additions & 10 deletions web/src/ScoreMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<Point, ScoreProps> | 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),
);
Expand All @@ -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<Point, ScoreProps> | null;
Expand Down Expand Up @@ -94,19 +96,23 @@

<SequentialLegend {colorScale} {limits} />

<label>
<input type="number" bind:value={maxSeconds} />
Max time (seconds)
</label>

<label>
<input type="checkbox" bind:checked={showParking} />
Show parking
</label>

<p>
This is an early experiment of a mode to show an "access score". Right
now, it's starting from every POI based on the types chosen below and
walking up to 10 minutes to the nearest bicycle parking. This is a simple
way of showing POIs without any nearby parking. Note the granularity of
results is poor; the search begins and ends at the nearest intersection,
and the time to walk doesn't take into account the side of the road or
walking partly down some road.
now, it's starting from every POI chosen and walking up to some time to
the nearest bicycle parking. This is a simple way of showing POIs without
any nearby parking. Note the granularity of results is poor; the search
begins and ends at the nearest intersection, and the time to walk doesn't
take into account the side of the road or walking partly down some road.
</p>
<p>
Parking icon from <a
Expand Down
2 changes: 2 additions & 0 deletions web/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class Backend {
score(
req: {
poiKinds: string[];
maxSeconds: number;
},
progressCb: (msg: string) => void,
): FeatureCollection<Point, ScoreProps> {
Expand All @@ -131,6 +132,7 @@ export class Backend {
this.inner.score(
{
poi_kinds: req.poiKinds,
max_seconds: req.maxSeconds,
},
progressCb,
),
Expand Down

0 comments on commit 703460f

Please sign in to comment.