From f15bdb221d92986eef70fa1a5d3b7fea0edc0fea Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 24 May 2024 11:43:50 +0100 Subject: [PATCH] Add a timer to transit routing --- backend/src/lib.rs | 3 ++- backend/src/transit_route.rs | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/src/lib.rs b/backend/src/lib.rs index ca287da..c26f098 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -128,7 +128,8 @@ impl MapModel { .data; if req.mode == "transit" { - transit_route::route(&self.graph, start, end).map_err(err_to_js) + transit_route::route(&self.graph, start, end, Timer::new("route request", None)) + .map_err(err_to_js) } else { self.graph.router[mode] .route(&self.graph, start, end) diff --git a/backend/src/transit_route.rs b/backend/src/transit_route.rs index 5041f8a..abbbd07 100644 --- a/backend/src/transit_route.rs +++ b/backend/src/transit_route.rs @@ -11,8 +11,14 @@ use utils::PriorityQueueItem; use crate::costs::cost; use crate::graph::{Graph, IntersectionID, Mode, RoadID}; use crate::gtfs::{StopID, TripID}; +use crate::timer::Timer; -pub fn route(graph: &Graph, start: IntersectionID, end: IntersectionID) -> Result { +pub fn route( + graph: &Graph, + start: IntersectionID, + end: IntersectionID, + mut timer: Timer, +) -> Result { // TODO We'll need a start time too (and a day of the week) let start_time = NaiveTime::from_hms_opt(7, 0, 0).unwrap(); if start == end { @@ -28,17 +34,20 @@ pub fn route(graph: &Graph, start: IntersectionID, end: IntersectionID) -> Resul // or a transit thing. an edge is a turn or a transition to/from transit let mut backrefs: HashMap = HashMap::new(); + timer.step("dijkstra"); let mut queue: BinaryHeap> = BinaryHeap::new(); queue.push(PriorityQueueItem::new(start_time, start)); while let Some(current) = queue.pop() { if current.value == end { + timer.step("render"); // Found the path // TODO Ideally glue together one LineString let mut features = Vec::new(); let mut at = current.value; loop { if at == start { + timer.done(); return Ok(serde_json::to_string(&GeoJson::from(features))?); } let (prev_i, step) = &backrefs[&at];