Skip to content

Commit c998170

Browse files
authored
Merge pull request #23 from SolverForge/issue/10-cleanup-progress-model
cleanup: remove stale wrappers and align progress reporting
2 parents dfbec9b + 653c3aa commit c998170

4 files changed

Lines changed: 42 additions & 21 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ tokio::spawn(async move {
418418
RoutingProgress::ComputingMatrix { percent, row, total } => {
419419
println!("[{:3}%] Computing matrix row {}/{}", percent, row, total);
420420
}
421+
RoutingProgress::Complete => {
422+
println!("[100%] Done");
423+
}
421424
_ => {}
422425
}
423426
}
@@ -437,7 +440,6 @@ let matrix = network.compute_matrix(&locations, Some(&tx)).await;
437440
| `BuildingGraph { percent }` | Building routing graph |
438441
| `ComputingMatrix { percent, row, total }` | Computing travel time matrix |
439442
| `ComputingGeometries { percent, pair, total }` | Computing route geometries |
440-
| `EncodingGeometries { percent }` | Encoding geometries to polylines |
441443
| `Complete` | Operation finished |
442444

443445
---

src/routing/fetch.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ out body;"#,
191191
let _ = tx
192192
.send(RoutingProgress::BuildingGraph { percent: 50 })
193193
.await;
194+
let _ = tx.send(RoutingProgress::Complete).await;
194195
}
195196

196197
Ok(network)
@@ -557,13 +558,6 @@ fn is_retryable_error(error: &reqwest::Error) -> bool {
557558
error.is_timeout() || error.is_connect() || error.is_request()
558559
}
559560

560-
impl RoadNetwork {
561-
#[doc(hidden)]
562-
pub async fn load_or_fetch_simple(bbox: &BoundingBox) -> Result<NetworkRef, RoutingError> {
563-
Self::load_or_fetch(bbox, &NetworkConfig::default(), None).await
564-
}
565-
}
566-
567561
async fn acquire_in_flight_slot(cache_key: &str) -> (Arc<Mutex<()>>, OwnedMutexGuard<()>) {
568562
let slot = {
569563
let mut in_flight = in_flight_loads().lock().await;

src/routing/matrix.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rayon::prelude::*;
44
use std::collections::HashMap;
5-
use tokio::sync::mpsc::Sender;
5+
use tokio::sync::mpsc::{self, Sender};
66

77
use super::algo::dijkstra;
88
use super::coord::Coord;
@@ -195,8 +195,29 @@ impl RoadNetwork {
195195
})
196196
.collect();
197197

198+
let row_progress = progress.map(|tx| {
199+
let (progress_tx, mut progress_rx) = mpsc::unbounded_channel::<usize>();
200+
let tx = tx.clone();
201+
let handle = tokio::spawn(async move {
202+
let mut completed_rows = 0usize;
203+
while progress_rx.recv().await.is_some() {
204+
completed_rows += 1;
205+
let percent = 55 + ((completed_rows * 44) / n.max(1)) as u8;
206+
let _ = tx
207+
.send(RoutingProgress::ComputingMatrix {
208+
percent,
209+
row: completed_rows,
210+
total: n,
211+
})
212+
.await;
213+
}
214+
});
215+
(progress_tx, handle)
216+
});
217+
198218
// Compute rows in parallel via rayon - each row runs Dijkstra from source endpoints
199219
let graph = &self.graph;
220+
let progress_tx = row_progress.as_ref().map(|(tx, _)| tx.clone());
200221
let rows: Vec<Vec<i64>> = (0..n)
201222
.into_par_iter()
202223
.map(|i| {
@@ -208,6 +229,9 @@ impl RoadNetwork {
208229
*cell = UNREACHABLE;
209230
}
210231
}
232+
if let Some(tx) = &progress_tx {
233+
let _ = tx.send(i);
234+
}
211235
return row;
212236
};
213237

@@ -230,18 +254,20 @@ impl RoadNetwork {
230254
};
231255
}
232256

257+
if let Some(tx) = &progress_tx {
258+
let _ = tx.send(i);
259+
}
233260
row
234261
})
235262
.collect();
236263

264+
if let Some((progress_tx, handle)) = row_progress {
265+
drop(progress_tx);
266+
let _ = handle.await;
267+
}
268+
237269
if let Some(tx) = progress {
238-
let _ = tx
239-
.send(RoutingProgress::ComputingMatrix {
240-
percent: 80,
241-
row: n,
242-
total: n,
243-
})
244-
.await;
270+
let _ = tx.send(RoutingProgress::Complete).await;
245271
}
246272

247273
let data: Vec<i64> = rows.into_iter().flatten().collect();
@@ -283,6 +309,10 @@ impl RoadNetwork {
283309
}
284310
}
285311

312+
if let Some(tx) = progress {
313+
let _ = tx.send(RoutingProgress::Complete).await;
314+
}
315+
286316
geometries
287317
}
288318
}

src/routing/progress.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ pub enum RoutingProgress {
3030
pair: usize,
3131
total: usize,
3232
},
33-
EncodingGeometries {
34-
percent: u8,
35-
},
3633
Complete,
3734
}
3835

@@ -45,7 +42,6 @@ impl RoutingProgress {
4542
Self::BuildingGraph { percent } => *percent,
4643
Self::ComputingMatrix { percent, .. } => *percent,
4744
Self::ComputingGeometries { percent, .. } => *percent,
48-
Self::EncodingGeometries { percent } => *percent,
4945
Self::Complete => 100,
5046
}
5147
}
@@ -58,7 +54,6 @@ impl RoutingProgress {
5854
Self::BuildingGraph { .. } => ("building", "Building routing graph..."),
5955
Self::ComputingMatrix { .. } => ("matrix", "Computing travel times..."),
6056
Self::ComputingGeometries { .. } => ("geometry", "Computing route geometries..."),
61-
Self::EncodingGeometries { .. } => ("encoding", "Encoding geometries..."),
6257
Self::Complete => ("complete", "Ready!"),
6358
}
6459
}

0 commit comments

Comments
 (0)