Skip to content

Commit

Permalink
Add a timer to transit routing
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed May 24, 2024
1 parent 7533f67 commit f15bdb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion backend/src/transit_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
pub fn route(
graph: &Graph,
start: IntersectionID,
end: IntersectionID,
mut timer: Timer,
) -> Result<String> {
// 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 {
Expand All @@ -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<IntersectionID, (IntersectionID, PathStep)> = HashMap::new();

timer.step("dijkstra");
let mut queue: BinaryHeap<PriorityQueueItem<NaiveTime, IntersectionID>> = 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];
Expand Down

0 comments on commit f15bdb2

Please sign in to comment.