Skip to content

Commit 1f5d9d6

Browse files
authored
Merge pull request #47 from TransitApp/jsteelz/fix-patch-gtfs
Fix: patch_gtfs calling wrong function with wrong params, simpler itineraries arg in CLI
2 parents aad119d + 44ffd9c commit 1f5d9d6

File tree

5 files changed

+34
-347
lines changed

5 files changed

+34
-347
lines changed

gtfs_flex_to_gofs/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def print_args_warnings(args):
5252
parser.add_argument(
5353
'--split-by-route', help='Split gofs by route', action='store_true')
5454
parser.add_argument(
55-
'--itineraries', help='read from transit\'s itinerary_cells format', type=bool, default=False)
55+
'--itineraries', help='read from transit\'s itinerary_cells format', action='store_true')
5656

5757

5858
args = parser.parse_args()

gtfs_flex_to_gofs/files/operation_rules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from ..gofs_data import GofsTransfer
77
from gtfs_loader.schema import PickupType, DropOffType
88

9-
from gtfs_flex_to_gofs.utils import get_locations_group, get_zones
109
from enum import Enum
1110

1211
FILENAME = 'operating_rules'

gtfs_flex_to_gofs/patch_gtfs.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from gtfs_flex_to_gofs.gofs_data import GofsData
21
import gtfs_loader
32
from .files import operation_rules
43

54

65
def patch_gtfs(args, gtfs, itineraries=False):
76
clean_up_gtfs(gtfs, itineraries)
87

9-
is_empty = len(gtfs.itinerary_cells) == 0 if itineraries else len(gtfs.stop_times) == 0
8+
is_empty = len(gtfs.trips) == 0
109

1110
if not is_empty:
1211
gtfs_loader.patch(gtfs, args.gtfs_dir, args.out_gtfs_dir)
@@ -16,20 +15,22 @@ def patch_gtfs(args, gtfs, itineraries=False):
1615

1716

1817
def clean_up_gtfs(gtfs, itineraries=False):
18+
trip_ids_to_remove = []
1919
for trip in gtfs.trips.values():
2020
stop_times = gtfs.itinerary_cells[trip.itinerary_index] if itineraries else gtfs.stop_times[trip.trip_id]
2121
if itineraries:
2222
for i, st in enumerate(stop_times):
2323
st.start_pickup_drop_off_window = trip.start_pickup_drop_off_windows[i]
2424
st.end_pickup_drop_off_window = trip.end_pickup_drop_off_windows[i]
2525

26-
type_of_trip = operation_rules.get_type_of_itinerary_trip(trip)
26+
type_of_trip = operation_rules.get_type_of_trip(stop_times)
2727
if type_of_trip == operation_rules.TripType.OTHER:
2828
print(f"WARNING : Trip {trip.trip_id} is not a normal gtfs trip, not microtransit and not deviated service only. We are not supproting this yet, it will be removed from the GTFS and not shown anywhere")
2929

3030
if type_of_trip == operation_rules.TripType.OTHER or type_of_trip == operation_rules.TripType.PURE_MICROTRANSIT:
31-
del gtfs.trips[trip.trip_id]
32-
if itineraries and trip.itinerary_index in gtfs.itinerary_cells:
33-
del gtfs.itinerary_cells[trip.itinerary_index]
34-
else:
31+
trip_ids_to_remove.append(trip.trip_id)
32+
if not itineraries:
3533
del gtfs.stop_times[trip.trip_id]
34+
35+
for trip_id in trip_ids_to_remove:
36+
del gtfs.trips[trip_id]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "GTFS-flex-to-GOFS"
7-
version = "0.5.1"
7+
version = "0.5.2"
88
description = "Convert GTFS Flex to GOFS"
99
readme = "README.md"
1010
license = {text = "MIT"}

0 commit comments

Comments
 (0)