Skip to content

Commit

Permalink
Merge pull request #702 from woshilapin/no-dumb-transfers
Browse files Browse the repository at this point in the history
[fix] Do not create transfers when geolocation is (0, 0)
  • Loading branch information
Jean SIMARD authored Sep 11, 2020
2 parents 118963f + 4d8f8ad commit 7a7cd08
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
use crate::{
model::Model,
objects::{StopPoint, Transfer},
objects::{Coord, StopPoint, Transfer},
Result,
};
use log::info;
use log::{info, warn};
use std::collections::HashMap;
use typed_index_collection::{Collection, CollectionWithId, Idx};

Expand Down Expand Up @@ -58,8 +58,16 @@ fn generate_transfers_from_sp(
info!("Adding missing transfers from stop points.");
let sq_max_distance = max_distance * max_distance;
for (idx1, sp1) in model.stop_points.iter() {
if sp1.coord == Coord::default() {
warn!("Stop Point {} geolocation is (0, 0), no transfer from this StopPoint will be generated.", sp1.id);
continue;
}
let approx = sp1.coord.approx();
for (idx2, sp2) in model.stop_points.iter() {
if sp2.coord == Coord::default() {
warn!("Stop Point {} geolocation is (0, 0), no transfer to this StopPoint will be generated.", sp2.id);
continue;
}
if transfers_map.contains_key(&(idx1, idx2)) {
continue;
}
Expand Down Expand Up @@ -102,6 +110,9 @@ fn generate_transfers_from_sp(
/// If you need an additional condition, you can use this parameter. For instance
/// you could create transfers between 2 stop points of different contributors only.
///
/// WARNING: if geolocation of either `StopPoint` is (0, 0), it's considered
/// incorrect and transfer is not generated to or from this `StopPoint`.
///
/// # Example
///
/// | from_stop_id | to_stop_id | transfer_time | |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
trip_id,arrival_time,departure_time,stop_id,stop_sequence
trip:1,15:45:00,15:45:00,sp_1,0
trip:1,15:46:00,15:46:00,sp_2,1
trip:1,15:47:00,15:47:00,sp_3,2
trip:1,15:47:00,15:47:00,sp_3,2
trip:1,15:48:00,15:48:00,sp_4,2
3 changes: 2 additions & 1 deletion tests/fixtures/transfers/mono_contributor/input/stops.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ stop_id,stop_name,stop_lat,stop_lon,location_type,parent_station
sp_1,sp name 1,48.84608210211328,2.372075915336609,0,sa_1
sp_2,sp name 2,48.845665532277096,2.371437549591065,0,sa_1
sp_3,sp name 3,48.845301913401144,2.369517087936402,0,sa_1
sa_1,sa name 1,48.844745,2.372986,1,
sp_4,sp name 4 (empty geolocation -> no transfer),0.0,0.0,0,sa_1
sa_1,sa name 1,48.844745,2.372986,1,

0 comments on commit 7a7cd08

Please sign in to comment.