hrdf_routing_engine/routing/
display.rs1use hrdf_parser::{DataStorage, Model};
2
3use super::models::RouteResult;
4
5impl RouteResult {
6 #[rustfmt::skip]
7 pub fn print(&self, data_storage: &DataStorage) {
8 for section in self.sections() {
9 let journey = section.journey(data_storage);
10
11 if journey.is_none() {
12 let stop = data_storage.stops().find(section.arrival_stop_id()).unwrap_or_else(|| panic!("Stop {:?} not found.", section.arrival_stop_id()));
13 println!("Approx. {}-minute walk to {}", section.duration().unwrap(), stop.name());
14 continue;
15 }
16
17 let journey = journey.unwrap();
18 println!("Journey #{}", journey.id());
19
20 let mut route_iter = journey.route().iter().peekable();
21
22 while route_iter.peek().unwrap().stop_id() != section.departure_stop_id() {
23 route_iter.next();
24 }
25
26 let mut route = Vec::new();
27
28 loop {
29 route.push(route_iter.next().unwrap());
30
31 if route.last().unwrap().stop_id() == section.arrival_stop_id() {
32 break;
33 }
34 }
35
36 println!(" Departure at: {}", section.departure_at().unwrap().format("%Y-%m-%d %H:%M"));
37
38 for (i, route_entry) in route.iter().enumerate() {
39 let arrival_time = if i == 0 {
40 " ".repeat(5)
41 } else {
42 format!("{}", route_entry.arrival_time().as_ref().unwrap().format("%H:%M"))
43 };
44
45 let departure_time = if i == route.len() - 1 {
46 " ".repeat(5)
47 } else {
48 format!("{}", route_entry.departure_time().as_ref().unwrap().format("%H:%M"))
49 };
50
51 let stop = route_entry.stop(data_storage);
52
53 println!(
54 " {:0>7} {: <36} {} - {}",
55 stop.id(),
56 stop.name(),
57 arrival_time,
58 departure_time,
59 );
60 }
61
62 println!(" Arrival at: {}", section.arrival_at().unwrap().format("%Y-%m-%d %H:%M"));
63 }
64 }
65}