From 652780b7025f8c251b9b336c88a8c4a5a4c1bc2d Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Mon, 8 Jan 2024 15:23:18 +0100 Subject: [PATCH] #21 Convert route --- .../plugins/enhancer/services/gtfs_export.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/amarillo/plugins/enhancer/services/gtfs_export.py b/amarillo/plugins/enhancer/services/gtfs_export.py index d389d2f..b792c61 100644 --- a/amarillo/plugins/enhancer/services/gtfs_export.py +++ b/amarillo/plugins/enhancer/services/gtfs_export.py @@ -115,13 +115,17 @@ class GtfsExport: return geodesic_distance_in_m(stop1, stop2) <= MERGE_RANGE_M def convert_route(self, route_group): - # TODO receives a group of trips and turns it into a route object, - # handling cases where there are multiple agencies' routes grouped together - pass + agency = "multiple" + + #if there is only one agency, use that + agencies = set(trip.agency for id, trip in route_group.items()) + if len(agencies) == 1: agency = agencies.pop() + trip = next(iter(route_group.values())) # grab any trip, relevant values should be the same + + self.routes.append(self._create_route(agency, trip.route_id, trip.route_name)) def _convert_trip(self, trip): self.trip_counter += 1 - self.routes.append(self._create_route(trip)) self.calendar.append(self._create_calendar(trip)) if not trip.runs_regularly: self.calendar_dates.append(self._create_calendar_date(trip)) @@ -152,8 +156,8 @@ class GtfsExport: logger.exception(ex) return destination - def _create_route(self, trip): - return GtfsRoute(trip.agency, trip.trip_id, trip.route_long_name(), RIDESHARING_ROUTE_TYPE, trip.url, "") + def _create_route(self, agency, route_id, long_name): + return GtfsRoute(agency, route_id, long_name, RIDESHARING_ROUTE_TYPE, "") def _create_calendar(self, trip): # TODO currently, calendar is not provided by Fahrgemeinschaft.de interface. @@ -174,7 +178,7 @@ class GtfsExport: return GtfsCalendarDate(trip.trip_id, self._convert_stop_date(trip.start), CALENDAR_DATES_EXCEPTION_TYPE_ADDED) def _create_trip(self, trip, shape_id): - return GtfsTrip(trip.route_id, trip.trip_id, trip.trip_id, shape_id, trip.trip_headsign, NO_BIKES_ALLOWED) + return GtfsTrip(trip.route_id, trip.trip_id, trip.trip_id, shape_id, trip.trip_headsign, NO_BIKES_ALLOWED, trip.url) def _convert_stop(self, stop): """