Skip to content

Commit

Permalink
Merge pull request #938 from hove-io/feature/gtfs2ntfs_ability_to_dis…
Browse files Browse the repository at this point in the history
…able_tranfers_computing

gtfs2ntfs: ability to disable transfers computing
  • Loading branch information
patochectp committed Jan 31, 2024
2 parents fa7e784 + e3f8870 commit f7c3204
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
22 changes: 15 additions & 7 deletions gtfs2ntfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ struct Opt {
/// Waiting time at stop in seconds.
#[arg(long, short = 't', default_value = transit_model::TRANSFER_WAITING_TIME)]
waiting_time: u32,

/// Don't compute transfers even the transfers of the stop point to itself (max_distance = 0.0)
#[arg(long)]
ignore_transfers: bool,
}

fn run(opt: Opt) -> Result<()> {
Expand All @@ -119,13 +123,17 @@ fn run(opt: Opt) -> Result<()> {

let model = transit_model::gtfs::Reader::new(configuration).parse(opt.input)?;

let model = generates_transfers(
model,
opt.max_distance,
opt.walking_speed,
opt.waiting_time,
None,
)?;
let model = if opt.ignore_transfers {
model
} else {
generates_transfers(
model,
opt.max_distance,
opt.walking_speed,
opt.waiting_time,
None,
)?
};

match opt.output.extension() {
Some(ext) if ext == "zip" => {
Expand Down
21 changes: 21 additions & 0 deletions gtfs2ntfs/tests/gtfs2ntfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ fn test_gtfs2ntfs() {
.assert()
.success();
assert!(output_dir.path().join("feed_infos.txt").is_file());
let collections = transit_model::ntfs::read(output_dir).unwrap();
assert_eq!(81, collections.transfers.len());
}

#[test]
Expand Down Expand Up @@ -70,3 +72,22 @@ fn test_gtfs2ntfs_create_not_zip_extension() {
.success();
assert!(ntfs_foobar.join("feed_infos.txt").is_file());
}

#[test]
fn test_gtfs2ntfs_without_transfers() {
let output_dir = TempDir::new().expect("create temp dir failed");
Command::cargo_bin("gtfs2ntfs")
.expect("Failed to find binary 'gtfs2ntfs'")
.arg("--input")
.arg("../tests/fixtures/gtfs2ntfs/minimal/input")
.arg("--output")
.arg(output_dir.path().to_str().unwrap())
.arg("--current-datetime")
.arg("2019-04-03T17:19:00Z")
.arg("--ignore-transfers")
.assert()
.success();
assert!(output_dir.path().join("feed_infos.txt").is_file());
let collections = transit_model::ntfs::read(output_dir).unwrap();
assert_eq!(0, collections.transfers.len());
}

0 comments on commit f7c3204

Please sign in to comment.