From abd6e13b97868adda2cd595a12b12b1a9e73a679 Mon Sep 17 00:00:00 2001 From: Jeremy Steele Date: Wed, 20 Mar 2024 11:56:40 -0400 Subject: [PATCH] Set pickup/drop_off _type on in-seat transfers If a transfer is in_seat, passengers should be able to embark at the last stop of the from_trip of the continuation, and disembark at the first stop of the to_trip of the continuation. Update the stop_times to reflect this. Update a simple test case to ensure that this transformation is applied. --- blocks_to_transfers/__main__.py | 4 ++- blocks_to_transfers/set_pickup_drop_off.py | 22 +++++++++++++ setup.py | 2 +- .../expected_standard/stop_times.txt | 32 +++++++++---------- tests/test_full_loops/input/stop_times.txt | 32 +++++++++---------- 5 files changed, 58 insertions(+), 34 deletions(-) create mode 100644 blocks_to_transfers/set_pickup_drop_off.py diff --git a/blocks_to_transfers/__main__.py b/blocks_to_transfers/__main__.py index f508256..857f366 100644 --- a/blocks_to_transfers/__main__.py +++ b/blocks_to_transfers/__main__.py @@ -4,7 +4,7 @@ import json import sys import gtfs_loader -from . import convert_blocks, config, service_days, classify_transfers, simplify_fix, simplify_linear, simplify_export, logs, runtime_config +from . import convert_blocks, config, service_days, classify_transfers, simplify_fix, simplify_linear, simplify_export, logs, runtime_config, set_pickup_drop_off def process(in_dir, @@ -27,6 +27,8 @@ def process(in_dir, output_graph = graph simplify_export.export_visit(output_graph) + set_pickup_drop_off.set_pickup_drop_off(gtfs) + if remove_existing_files: shutil.rmtree(out_dir, ignore_errors=True) diff --git a/blocks_to_transfers/set_pickup_drop_off.py b/blocks_to_transfers/set_pickup_drop_off.py new file mode 100644 index 0000000..0fccbc2 --- /dev/null +++ b/blocks_to_transfers/set_pickup_drop_off.py @@ -0,0 +1,22 @@ +from gtfs_loader.schema import TransferType, PickupType + +def set_pickup_drop_off(gtfs): + from_trip_ids_to_set = set() + to_trip_ids_to_set = set() + for from_trip_id, transfers in gtfs.transfers.items(): + for transfer in transfers: + transfer_type = transfer.transfer_type + to_trip_id = transfer.to_trip_id + + if not (from_trip_id and to_trip_id): + continue + if transfer_type in TransferType and transfer_type != TransferType.IN_SEAT: + continue + + from_trip_ids_to_set.add(from_trip_id) + to_trip_ids_to_set.add(to_trip_id) + + for trip_id in from_trip_ids_to_set: + gtfs.stop_times.get(trip_id)[-1].pickup_type = PickupType.REGULARLY_SCHEDULED + for trip_id in to_trip_ids_to_set: + gtfs.stop_times.get(trip_id)[0].drop_off_type = PickupType.REGULARLY_SCHEDULED diff --git a/setup.py b/setup.py index 8ce1b1b..62c140f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import dependency_info setup(name='GTFS-blocks-to-transfers', - version='1.5.3', + version='1.6.0', description='Convert GTFS blocks to trip-to-trip transfers', url='https://github.com/TransitApp/GTFS-blocks-to-transfers', author='Nicholas Paun', diff --git a/tests/test_full_loops/expected_standard/stop_times.txt b/tests/test_full_loops/expected_standard/stop_times.txt index febb552..d15bc2f 100644 --- a/tests/test_full_loops/expected_standard/stop_times.txt +++ b/tests/test_full_loops/expected_standard/stop_times.txt @@ -1,16 +1,16 @@ -trip_id,stop_sequence,stop_id,arrival_time,departure_time,start_pickup_drop_off_window,end_pickup_drop_off_window,pickup_type,drop_off_type,mean_duration_factor,mean_duration_offset,safe_duration_factor,safe_duration_offset -trip_1,0,junction,22:00:00,22:00:00,,,0,0,,,, -trip_1,1,slocan-park,22:01:00,22:01:00,,,0,0,,,, -trip_1,2,slocan-city,22:02:00,22:02:00,,,0,0,,,, -trip_1,3,nelson-tc,22:03:00,22:03:00,,,0,0,,,, -trip_1,4,junction,22:04:00,22:04:00,,,0,0,,,, -trip_2,0,junction,22:04:00,22:04:00,,,0,0,,,, -trip_2,1,slocan-park,22:05:00,22:05:00,,,0,0,,,, -trip_2,2,slocan-city,22:06:00,22:06:00,,,0,0,,,, -trip_2,3,nelson-tc,22:07:00,22:07:00,,,0,0,,,, -trip_2,4,junction,22:08:00,22:08:00,,,0,0,,,, -trip_3,0,junction,22:08:00,22:08:00,,,0,0,,,, -trip_3,1,slocan-park,22:09:00,22:09:00,,,0,0,,,, -trip_3,2,slocan-city,22:10:00,22:10:00,,,0,0,,,, -trip_3,3,nelson-tc,22:11:00,22:11:00,,,0,0,,,, -trip_3,4,junction,22:12:00,22:12:00,,,0,0,,,, \ No newline at end of file +trip_id,stop_sequence,stop_id,arrival_time,departure_time,pickup_type,drop_off_type,start_pickup_drop_off_window,end_pickup_drop_off_window,mean_duration_factor,mean_duration_offset,safe_duration_factor,safe_duration_offset +trip_1,0,junction,22:00:00,22:00:00,0,1,,,,,, +trip_1,1,slocan-park,22:01:00,22:01:00,0,0,,,,,, +trip_1,2,slocan-city,22:02:00,22:02:00,0,0,,,,,, +trip_1,3,nelson-tc,22:03:00,22:03:00,0,0,,,,,, +trip_1,4,junction,22:04:00,22:04:00,0,0,,,,,, +trip_2,0,junction,22:04:00,22:04:00,0,0,,,,,, +trip_2,1,slocan-park,22:05:00,22:05:00,0,0,,,,,, +trip_2,2,slocan-city,22:06:00,22:06:00,0,0,,,,,, +trip_2,3,nelson-tc,22:07:00,22:07:00,0,0,,,,,, +trip_2,4,junction,22:08:00,22:08:00,0,0,,,,,, +trip_3,0,junction,22:08:00,22:08:00,0,0,,,,,, +trip_3,1,slocan-park,22:09:00,22:09:00,0,0,,,,,, +trip_3,2,slocan-city,22:10:00,22:10:00,0,0,,,,,, +trip_3,3,nelson-tc,22:11:00,22:11:00,0,0,,,,,, +trip_3,4,junction,22:12:00,22:12:00,1,0,,,,,, diff --git a/tests/test_full_loops/input/stop_times.txt b/tests/test_full_loops/input/stop_times.txt index 265f948..5f61256 100644 --- a/tests/test_full_loops/input/stop_times.txt +++ b/tests/test_full_loops/input/stop_times.txt @@ -1,16 +1,16 @@ -trip_id,stop_sequence,stop_id,arrival_time,departure_time -trip_1,0,junction,22:00:00,22:00:00 -trip_1,1,slocan-park,22:01:00,22:01:00 -trip_1,2,slocan-city,22:02:00,22:02:00 -trip_1,3,nelson-tc,22:03:00,22:03:00 -trip_1,4,junction,22:04:00,22:04:00 -trip_2,0,junction,22:04:00,22:04:00 -trip_2,1,slocan-park,22:05:00,22:05:00 -trip_2,2,slocan-city,22:06:00,22:06:00 -trip_2,3,nelson-tc,22:07:00,22:07:00 -trip_2,4,junction,22:08:00,22:08:00 -trip_3,0,junction,22:08:00,22:08:00 -trip_3,1,slocan-park,22:09:00,22:09:00 -trip_3,2,slocan-city,22:10:00,22:10:00 -trip_3,3,nelson-tc,22:11:00,22:11:00 -trip_3,4,junction,22:12:00,22:12:00 +trip_id,stop_sequence,stop_id,arrival_time,departure_time,pickup_type,drop_off_type +trip_1,0,junction,22:00:00,22:00:00,0,1 +trip_1,1,slocan-park,22:01:00,22:01:00,0,0 +trip_1,2,slocan-city,22:02:00,22:02:00,0,0 +trip_1,3,nelson-tc,22:03:00,22:03:00,0,0 +trip_1,4,junction,22:04:00,22:04:00,1,0 +trip_2,0,junction,22:04:00,22:04:00,0,1 +trip_2,1,slocan-park,22:05:00,22:05:00,0,0 +trip_2,2,slocan-city,22:06:00,22:06:00,0,0 +trip_2,3,nelson-tc,22:07:00,22:07:00,0,0 +trip_2,4,junction,22:08:00,22:08:00,1,0 +trip_3,0,junction,22:08:00,22:08:00,0,1 +trip_3,1,slocan-park,22:09:00,22:09:00,0,0 +trip_3,2,slocan-city,22:10:00,22:10:00,0,0 +trip_3,3,nelson-tc,22:11:00,22:11:00,0,0 +trip_3,4,junction,22:12:00,22:12:00,1,0