From f449162cba259bf6e4d2108a0a8018eee75daf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie?= Date: Sat, 12 Aug 2017 18:10:05 +0200 Subject: [PATCH 01/11] Accra : init creator --- core/osm_connector.py | 3 +- core/osm_routes.py | 3 +- creators/accra/__init__.py | 2 + creators/accra/accra.json | 35 ++++++++++ creators/accra/routes_creator_accra.py | 34 +++++++++ creators/accra/trips_creator_accra.py | 97 ++++++++++++++++++++++++++ 6 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 creators/accra/__init__.py create mode 100644 creators/accra/accra.json create mode 100644 creators/accra/routes_creator_accra.py create mode 100644 creators/accra/trips_creator_accra.py diff --git a/core/osm_connector.py b/core/osm_connector.py index dc47f382..4d07af35 100644 --- a/core/osm_connector.py +++ b/core/osm_connector.py @@ -290,7 +290,8 @@ def _build_route_master(self, route_master, members): return name = route_master.tags['name'] - rm = RouteMaster(route_master.id, ref, name, members) + frequency = route_master.tags['frequency'] + rm = RouteMaster(route_master.id, ref, name, members, frequency) print(rm) return rm diff --git a/core/osm_routes.py b/core/osm_routes.py index de891617..25a95cab 100644 --- a/core/osm_routes.py +++ b/core/osm_routes.py @@ -77,9 +77,10 @@ def print_shape_for_leaflet(self): class RouteMaster(BaseRoute): - def __init__(self, osm, ref, name, routes): + def __init__(self, osm, ref, name, routes, frequency = None): BaseRoute.__init__(self, osm, ref, name) self.routes = routes + self.frequency = frequency for route in self.routes.values(): route.master = self diff --git a/creators/accra/__init__.py b/creators/accra/__init__.py new file mode 100644 index 00000000..5c9136ad --- /dev/null +++ b/creators/accra/__init__.py @@ -0,0 +1,2 @@ +#!/usr/bin/env python +# coding=utf-8 diff --git a/creators/accra/accra.json b/creators/accra/accra.json new file mode 100644 index 00000000..41a6717d --- /dev/null +++ b/creators/accra/accra.json @@ -0,0 +1,35 @@ +{ + "query": { + "bbox": { + "n": "5.7844", + "s": "5.4783", + "e": "0.0611", + "w": "-0.4779" + }, + "tags": { + "route": "bus" + } + }, + "stops": { + "name_without": "Stop without name", + "name_auto": "yes" + }, + "agency": { + "agency_id": "AM3", + "agency_name": "TODO", + "agency_url": "http://todo", + "agency_timezone": "Africa/Accra", + "agency_lang": "EN", + "agency_phone": "TODO", + "agency_fare_url": "" + }, + "feed_info": { + "publisher_name": "Jungle Bus - Kisio Digital", + "publisher_url": "http://ic-itcr.ac.cr/~jgutierrez/incofer/", + "version": "0.1", + "start_date": "20170901", + "end_date": "20180730" + }, + "output_file": "data/accra.zip", + "selector": "accra" +} diff --git a/creators/accra/routes_creator_accra.py b/creators/accra/routes_creator_accra.py new file mode 100644 index 00000000..1af204d2 --- /dev/null +++ b/creators/accra/routes_creator_accra.py @@ -0,0 +1,34 @@ +# coding=utf-8 + +from creators.routes_creator import RoutesCreator + + +class RoutesCreatorAccra(RoutesCreator): + + def add_routes_to_schedule(self, schedule, data): + + # Get routes information + lines = data.get_routes() + # debug + # print("DEBUG: creando itinerarios a partir de", str(len(lines)), + # "lineas") + + # Loop through all lines (master_routes) + for line_ref, line in sorted(lines.iteritems()): + route = schedule.AddRoute( + short_name=line.ref.encode('utf-8'), + long_name=line.name, + route_type="Bus", + route_id=line_ref) + + # AddRoute method add defaut agency as default + route.agency_id = schedule.GetDefaultAgency().agency_id + + #route.route_desc = "Esta línea está a prueba" + + route.route_color = "ff0000" + route.route_text_color = "ffffff" + + # debug + print("información de la linea:", line.name, "agregada.") + return diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py new file mode 100644 index 00000000..f4365ad4 --- /dev/null +++ b/creators/accra/trips_creator_accra.py @@ -0,0 +1,97 @@ +# coding=utf-8 + +import sys +import json +import re +import transitfeed +from datetime import timedelta, datetime +from creators.trips_creator import TripsCreator +from core.osm_routes import Route, RouteMaster + +class TripsCreatorAccra(TripsCreator): + + def __init__(self, config): + super(TripsCreatorAccra, self).__init__(config) + + self.service_weekday = transitfeed.ServicePeriod("weekday") + self.service_weekday.SetStartDate(self.config['feed_info']['start_date']) + self.service_weekday.SetEndDate(self.config['feed_info']['end_date']) + self.service_weekday.SetWeekdayService(True) + self.service_weekday.SetWeekendService(False) + + self.service_saturday = transitfeed.ServicePeriod("saturday") + self.service_saturday.SetStartDate(self.config['feed_info']['start_date']) + self.service_saturday.SetEndDate(self.config['feed_info']['end_date']) + self.service_saturday.SetWeekdayService(False) + self.service_saturday.SetWeekendService(False) + self.service_saturday.SetDayOfWeekHasService(5, True) + + self.service_sunday = transitfeed.ServicePeriod("sunday") + self.service_sunday.SetStartDate(self.config['feed_info']['start_date']) + self.service_sunday.SetEndDate(self.config['feed_info']['end_date']) + self.service_sunday.SetWeekdayService(False) + self.service_sunday.SetWeekendService(False) + self.service_sunday.SetDayOfWeekHasService(6, True) + + self.exceptions = None + + def add_trips_to_schedule(self, schedule, data): + lines = data.routes + schedule.AddServicePeriodObject(self.service_weekday) + schedule.AddServicePeriodObject(self.service_saturday) + schedule.AddServicePeriodObject(self.service_sunday) + + ## TODO + # gtfs_trip.AddStopTime(gtfs_stop, stop_time = departure_time.strftime("%H:%M:%S")) + + for route_ref, line in sorted(lines.iteritems()): + if type(line).__name__ != "RouteMaster": + continue + print (line.name) + line_gtfs = schedule.AddRoute( + short_name=line.ref, + long_name=line.name.decode('utf8'), + route_type="Bus") + line_gtfs.agency_id = schedule.GetDefaultAgency().agency_id + line_gtfs.route_desc = "TEST DESCRIPTION" + line_gtfs.route_url = "" + line_gtfs.route_color = "1779c2" + line_gtfs.route_text_color = "ffffff" + + for a_route_ref, a_route in line.routes.iteritems(): + trip_gtfs = line_gtfs.AddTrip(schedule) + ROUTE_FREQUENCY = 18 #TODO + trip_gtfs.AddFrequency("06:00:00", "21:00:00", ROUTE_FREQUENCY * 60) + + for index_stop, a_stop in enumerate(a_route.stops) : + stop_id = a_stop.split('/')[-1] + print (a_stop) + departure_time = datetime(2008, 11, 22, 6, 0, 0) + #trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) + + if index_stop == 0 : + trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) + elif index_stop == len(a_route.stops) -1 : + departure_time += timedelta(hours = 1) #TODO + trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) + else : + trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id))) + + for secs, stop_time, is_timepoint in trip_gtfs.GetTimeInterpolatedStops(): + if not is_timepoint: + print('>>>> Interpolation au milieu') + stop_time.arrival_secs = secs + stop_time.departure_secs = secs + trip_gtfs.ReplaceStopTimeObject(stop_time) + + # interpolate times, because Navitia can not handle this itself + self.interpolate_stop_times(trip_gtfs) + + + @staticmethod + def interpolate_stop_times(trip): + for secs, stop_time, is_timepoint in trip.GetTimeInterpolatedStops(): + if not is_timepoint: + stop_time.arrival_secs = secs + stop_time.departure_secs = secs + trip.ReplaceStopTimeObject(stop_time) From a691f307739e7df8e6ff58fe86b84f2320d5962d Mon Sep 17 00:00:00 2001 From: Pascal Rhod Date: Fri, 11 Aug 2017 17:32:11 +0200 Subject: [PATCH 02/11] Accra - adding frequency and trip-service association --- core/osm_connector.py | 4 ++- creators/accra/routes_creator_accra.py | 34 +++++++++---------- creators/accra/trips_creator_accra.py | 47 +++++++------------------- 3 files changed, 33 insertions(+), 52 deletions(-) diff --git a/core/osm_connector.py b/core/osm_connector.py index 4d07af35..43f7ea2d 100644 --- a/core/osm_connector.py +++ b/core/osm_connector.py @@ -290,7 +290,9 @@ def _build_route_master(self, route_master, members): return name = route_master.tags['name'] - frequency = route_master.tags['frequency'] + frequency = None + if "frequency" in route_master.tags: + frequency = route_master.tags['frequency'] rm = RouteMaster(route_master.id, ref, name, members, frequency) print(rm) return rm diff --git a/creators/accra/routes_creator_accra.py b/creators/accra/routes_creator_accra.py index 1af204d2..361086df 100644 --- a/creators/accra/routes_creator_accra.py +++ b/creators/accra/routes_creator_accra.py @@ -14,21 +14,21 @@ def add_routes_to_schedule(self, schedule, data): # "lineas") # Loop through all lines (master_routes) - for line_ref, line in sorted(lines.iteritems()): - route = schedule.AddRoute( - short_name=line.ref.encode('utf-8'), - long_name=line.name, - route_type="Bus", - route_id=line_ref) - - # AddRoute method add defaut agency as default - route.agency_id = schedule.GetDefaultAgency().agency_id - - #route.route_desc = "Esta línea está a prueba" - - route.route_color = "ff0000" - route.route_text_color = "ffffff" - - # debug - print("información de la linea:", line.name, "agregada.") + # for line_ref, line in sorted(lines.iteritems()): + # route = schedule.AddRoute( + # short_name=line.ref.encode('utf-8'), + # long_name=line.name, + # route_type="Bus", + # route_id=line_ref) + # + # # AddRoute method add defaut agency as default + # route.agency_id = schedule.GetDefaultAgency().agency_id + # + # #route.route_desc = "Esta línea está a prueba" + # + # route.route_color = "ff0000" + # route.route_text_color = "ffffff" + # + # # debug + # print("información de la linea:", line.name, "agregada.") return diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index f4365ad4..1e4fe75f 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -13,59 +13,39 @@ class TripsCreatorAccra(TripsCreator): def __init__(self, config): super(TripsCreatorAccra, self).__init__(config) - self.service_weekday = transitfeed.ServicePeriod("weekday") + + def add_trips_to_schedule(self, schedule, data): + self.service_weekday = schedule.GetDefaultServicePeriod() self.service_weekday.SetStartDate(self.config['feed_info']['start_date']) self.service_weekday.SetEndDate(self.config['feed_info']['end_date']) self.service_weekday.SetWeekdayService(True) - self.service_weekday.SetWeekendService(False) - - self.service_saturday = transitfeed.ServicePeriod("saturday") - self.service_saturday.SetStartDate(self.config['feed_info']['start_date']) - self.service_saturday.SetEndDate(self.config['feed_info']['end_date']) - self.service_saturday.SetWeekdayService(False) - self.service_saturday.SetWeekendService(False) - self.service_saturday.SetDayOfWeekHasService(5, True) - - self.service_sunday = transitfeed.ServicePeriod("sunday") - self.service_sunday.SetStartDate(self.config['feed_info']['start_date']) - self.service_sunday.SetEndDate(self.config['feed_info']['end_date']) - self.service_sunday.SetWeekdayService(False) - self.service_sunday.SetWeekendService(False) - self.service_sunday.SetDayOfWeekHasService(6, True) + self.service_weekday.SetWeekendService(True) - self.exceptions = None - - def add_trips_to_schedule(self, schedule, data): lines = data.routes - schedule.AddServicePeriodObject(self.service_weekday) - schedule.AddServicePeriodObject(self.service_saturday) - schedule.AddServicePeriodObject(self.service_sunday) - - ## TODO - # gtfs_trip.AddStopTime(gtfs_stop, stop_time = departure_time.strftime("%H:%M:%S")) - for route_ref, line in sorted(lines.iteritems()): if type(line).__name__ != "RouteMaster": continue - print (line.name) line_gtfs = schedule.AddRoute( short_name=line.ref, long_name=line.name.decode('utf8'), - route_type="Bus") + route_type="Bus", + route_id=line.id) line_gtfs.agency_id = schedule.GetDefaultAgency().agency_id - line_gtfs.route_desc = "TEST DESCRIPTION" - line_gtfs.route_url = "" + line_gtfs.route_desc = "" line_gtfs.route_color = "1779c2" line_gtfs.route_text_color = "ffffff" for a_route_ref, a_route in line.routes.iteritems(): trip_gtfs = line_gtfs.AddTrip(schedule) - ROUTE_FREQUENCY = 18 #TODO - trip_gtfs.AddFrequency("06:00:00", "21:00:00", ROUTE_FREQUENCY * 60) + try: + ROUTE_FREQUENCY = int(line.frequency) + except Exception as e: + print("Frequency not a number for route_master " + str(line.id)) + ROUTE_FREQUENCY = 10 + trip_gtfs.AddFrequency("06:00:00", "21:00:00", ROUTE_FREQUENCY * 60) #TODO horaires d'ouverture des lignes à confirmer for index_stop, a_stop in enumerate(a_route.stops) : stop_id = a_stop.split('/')[-1] - print (a_stop) departure_time = datetime(2008, 11, 22, 6, 0, 0) #trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) @@ -79,7 +59,6 @@ def add_trips_to_schedule(self, schedule, data): for secs, stop_time, is_timepoint in trip_gtfs.GetTimeInterpolatedStops(): if not is_timepoint: - print('>>>> Interpolation au milieu') stop_time.arrival_secs = secs stop_time.departure_secs = secs trip_gtfs.ReplaceStopTimeObject(stop_time) From 527bdc3e926685fb6b287d1813b31de1c6da8e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie?= Date: Sat, 12 Aug 2017 18:26:10 +0200 Subject: [PATCH 03/11] Accra - add direction_id & headsign on trips --- creators/accra/routes_creator_accra.py | 25 ++----------------------- creators/accra/trips_creator_accra.py | 9 ++++----- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/creators/accra/routes_creator_accra.py b/creators/accra/routes_creator_accra.py index 361086df..14d6e2b8 100644 --- a/creators/accra/routes_creator_accra.py +++ b/creators/accra/routes_creator_accra.py @@ -6,29 +6,8 @@ class RoutesCreatorAccra(RoutesCreator): def add_routes_to_schedule(self, schedule, data): - # Get routes information - lines = data.get_routes() - # debug - # print("DEBUG: creando itinerarios a partir de", str(len(lines)), - # "lineas") + data.get_routes() - # Loop through all lines (master_routes) - # for line_ref, line in sorted(lines.iteritems()): - # route = schedule.AddRoute( - # short_name=line.ref.encode('utf-8'), - # long_name=line.name, - # route_type="Bus", - # route_id=line_ref) - # - # # AddRoute method add defaut agency as default - # route.agency_id = schedule.GetDefaultAgency().agency_id - # - # #route.route_desc = "Esta línea está a prueba" - # - # route.route_color = "ff0000" - # route.route_text_color = "ffffff" - # - # # debug - # print("información de la linea:", line.name, "agregada.") + # GTFS routes are created in TripsCreator return diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index 1e4fe75f..17156cbe 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -10,10 +10,6 @@ class TripsCreatorAccra(TripsCreator): - def __init__(self, config): - super(TripsCreatorAccra, self).__init__(config) - - def add_trips_to_schedule(self, schedule, data): self.service_weekday = schedule.GetDefaultServicePeriod() self.service_weekday.SetStartDate(self.config['feed_info']['start_date']) @@ -35,8 +31,12 @@ def add_trips_to_schedule(self, schedule, data): line_gtfs.route_color = "1779c2" line_gtfs.route_text_color = "ffffff" + route_index = 0 for a_route_ref, a_route in line.routes.iteritems(): trip_gtfs = line_gtfs.AddTrip(schedule) + trip_gtfs.headsign = a_route.to + trip_gtfs.direction_id = route_index % 2 + route_index += 1 try: ROUTE_FREQUENCY = int(line.frequency) except Exception as e: @@ -47,7 +47,6 @@ def add_trips_to_schedule(self, schedule, data): for index_stop, a_stop in enumerate(a_route.stops) : stop_id = a_stop.split('/')[-1] departure_time = datetime(2008, 11, 22, 6, 0, 0) - #trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) if index_stop == 0 : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) From d657d9e1c6fbfc2d0d1ab7912a36ba651dd978d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie?= Date: Sat, 12 Aug 2017 18:35:49 +0200 Subject: [PATCH 04/11] Accra - add shapes on trips --- creators/accra/trips_creator_accra.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index 17156cbe..b202b484 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -8,6 +8,17 @@ from creators.trips_creator import TripsCreator from core.osm_routes import Route, RouteMaster +def _add_shape(schedule, route_id, osm_r): + shape_id = str(route_id) + try: + schedule.GetShape(shape_id) + except KeyError: + shape = transitfeed.Shape(shape_id) + for point in osm_r.shape: + shape.AddPoint(lat=float(point["lat"]), lon=float(point["lon"])) + schedule.AddShapeObject(shape) + return shape_id + class TripsCreatorAccra(TripsCreator): def add_trips_to_schedule(self, schedule, data): @@ -34,7 +45,8 @@ def add_trips_to_schedule(self, schedule, data): route_index = 0 for a_route_ref, a_route in line.routes.iteritems(): trip_gtfs = line_gtfs.AddTrip(schedule) - trip_gtfs.headsign = a_route.to + trip_gtfs.shape_id = _add_shape(schedule, a_route_ref, a_route) + trip_gtfs.trip_headsign = a_route.to trip_gtfs.direction_id = route_index % 2 route_index += 1 try: From 2a6adb92f42ce7f9a2e300cadb3bc1334a7818d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie=20Lehuby?= Date: Mon, 14 Aug 2017 18:47:11 +0200 Subject: [PATCH 05/11] Accra - create Stop Areas --- creators/accra/accra.json | 12 ++-- creators/accra/stops_creator_accra.py | 79 +++++++++++++++++++++++++++ creators/accra/trips_creator_accra.py | 2 +- 3 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 creators/accra/stops_creator_accra.py diff --git a/creators/accra/accra.json b/creators/accra/accra.json index 41a6717d..349a704e 100644 --- a/creators/accra/accra.json +++ b/creators/accra/accra.json @@ -11,21 +11,21 @@ } }, "stops": { - "name_without": "Stop without name", + "name_without": "Add a name to the stop with JungleBus app", "name_auto": "yes" }, "agency": { "agency_id": "AM3", - "agency_name": "TODO", - "agency_url": "http://todo", + "agency_name": "Accra Trotro", + "agency_url": "http://junglebus.io", "agency_timezone": "Africa/Accra", "agency_lang": "EN", - "agency_phone": "TODO", + "agency_phone": "", "agency_fare_url": "" }, "feed_info": { - "publisher_name": "Jungle Bus - Kisio Digital", - "publisher_url": "http://ic-itcr.ac.cr/~jgutierrez/incofer/", + "publisher_name": "Jungle Bus", + "publisher_url": "junglebus.io", "version": "0.1", "start_date": "20170901", "end_date": "20180730" diff --git a/creators/accra/stops_creator_accra.py b/creators/accra/stops_creator_accra.py new file mode 100644 index 00000000..17c59ec4 --- /dev/null +++ b/creators/accra/stops_creator_accra.py @@ -0,0 +1,79 @@ +# coding=utf-8 + + +from creators.stops_creator import StopsCreator +import math + + +def get_crow_fly_distance(from_tuple, to_tuple): + """ + Uses the Haversine formmula to compute distance (https://en.wikipedia.org/wiki/Haversine_formula#The_haversine_formula) + """ + lat1, lon1 = from_tuple + lat2, lon2 = to_tuple + + lat1 = float(lat1) + lat2 = float(lat2) + lon1 = float(lon1) + lon2 = float(lon2) + + radius = 6371 # km + + dlat = math.radians(lat2 - lat1) + dlon = math.radians(lon2 - lon1) + a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(lat1)) * \ + math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2) + c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) + d = radius * c + + return d * 1000 # meters + + +def create_stop_area(stop_data, schedule): + gtfs_stop_area = schedule.AddStop( + lat=float(stop_data.lat), + lng=float(stop_data.lon), + name=stop_data.name, + stop_id="SA" + str(stop_data.id) + ) + gtfs_stop_area.location_type = 1 + return gtfs_stop_area + + +def create_stop_point(stop_data, schedule): + gtfs_stop_point = schedule.AddStop( + lat=float(stop_data.lat), + lng=float(stop_data.lon), + name=stop_data.name, + stop_id=str(stop_data.id) + ) + return gtfs_stop_point + +class StopsCreatorAccra(StopsCreator): + + def add_stops_to_schedule(self, schedule, data): + stops = data.get_stops() + stops_by_name = {} + + for a_stop in stops.values(): + if a_stop.name not in stops_by_name: + stops_by_name[a_stop.name] = [] + stops_by_name[a_stop.name].append(a_stop) + + for a_stop_name in stops_by_name: + stop_areas = [] + + for a_stop_point in stops_by_name[a_stop_name]: + gtfs_stop_point = create_stop_point(a_stop_point, schedule) + stop_point_has_parent_location = False + for a_stop_area in stop_areas : + distance_to_parent_station = get_crow_fly_distance( + (a_stop_area.stop_lat, a_stop_area.stop_lon), (a_stop_point.lat, a_stop_point.lon)) + if distance_to_parent_station < 500: + gtfs_stop_point.parent_station = a_stop_area.stop_id + stop_point_has_parent_location = True + break + if not stop_point_has_parent_location : + new_sa = create_stop_area(a_stop_point, schedule) + gtfs_stop_point.parent_station = new_sa.stop_id + stop_areas.append(new_sa) diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index b202b484..b7744cb7 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -63,7 +63,7 @@ def add_trips_to_schedule(self, schedule, data): if index_stop == 0 : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) elif index_stop == len(a_route.stops) -1 : - departure_time += timedelta(hours = 1) #TODO + departure_time += timedelta(hours = 1) #TODO temps de trajet de bout en bout de chaque ligne à affiner trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) else : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id))) From a9c36d9eeb06e5d6bf0abdc244d475e75858c88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie=20Lehuby?= Date: Thu, 17 Aug 2017 18:40:41 +0200 Subject: [PATCH 06/11] add staticmethods to TripCreator class and refactor existing creators --- creators/accra/trips_creator_accra.py | 28 ++++------------------- creators/fenix/trips_creator_fenix.py | 10 +------- creators/incofer/trips_creator_incofer.py | 16 +------------ creators/trips_creator.py | 28 +++++++++++++++++++++++ 4 files changed, 34 insertions(+), 48 deletions(-) diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index b7744cb7..0f2b9fc6 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -3,21 +3,11 @@ import sys import json import re -import transitfeed from datetime import timedelta, datetime from creators.trips_creator import TripsCreator from core.osm_routes import Route, RouteMaster -def _add_shape(schedule, route_id, osm_r): - shape_id = str(route_id) - try: - schedule.GetShape(shape_id) - except KeyError: - shape = transitfeed.Shape(shape_id) - for point in osm_r.shape: - shape.AddPoint(lat=float(point["lat"]), lon=float(point["lon"])) - schedule.AddShapeObject(shape) - return shape_id + class TripsCreatorAccra(TripsCreator): @@ -45,7 +35,7 @@ def add_trips_to_schedule(self, schedule, data): route_index = 0 for a_route_ref, a_route in line.routes.iteritems(): trip_gtfs = line_gtfs.AddTrip(schedule) - trip_gtfs.shape_id = _add_shape(schedule, a_route_ref, a_route) + trip_gtfs.shape_id = TripsCreator.add_shape(schedule, a_route_ref, a_route) trip_gtfs.trip_headsign = a_route.to trip_gtfs.direction_id = route_index % 2 route_index += 1 @@ -63,7 +53,7 @@ def add_trips_to_schedule(self, schedule, data): if index_stop == 0 : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) elif index_stop == len(a_route.stops) -1 : - departure_time += timedelta(hours = 1) #TODO temps de trajet de bout en bout de chaque ligne à affiner + departure_time += timedelta(hours = 1) #TODO trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) else : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id))) @@ -74,14 +64,4 @@ def add_trips_to_schedule(self, schedule, data): stop_time.departure_secs = secs trip_gtfs.ReplaceStopTimeObject(stop_time) - # interpolate times, because Navitia can not handle this itself - self.interpolate_stop_times(trip_gtfs) - - - @staticmethod - def interpolate_stop_times(trip): - for secs, stop_time, is_timepoint in trip.GetTimeInterpolatedStops(): - if not is_timepoint: - stop_time.arrival_secs = secs - stop_time.departure_secs = secs - trip.ReplaceStopTimeObject(stop_time) + TripsCreator.interpolate_stop_times(trip_gtfs) diff --git a/creators/fenix/trips_creator_fenix.py b/creators/fenix/trips_creator_fenix.py index 0fa5a49e..6db84042 100644 --- a/creators/fenix/trips_creator_fenix.py +++ b/creators/fenix/trips_creator_fenix.py @@ -208,7 +208,7 @@ def add_trips_by_day(self, schedule, line, service, route, horarios, day): self.add_trip_stops(schedule, trip, route, start_time, end_time) # interpolate times, because Navitia can not handle this itself - self.interpolate_stop_times(trip) + TripsCreator.interpolate_stop_times(trip) def get_exception_service_period(self, schedule, date, day): date_string = date.strftime("%Y%m%d") @@ -292,11 +292,3 @@ def add_trip_stops(schedule, trip, route, start_time, end_time): trip.AddStopTime(schedule.GetStop(str(stop.id))) # print "INTER: " + str(stop) i += 1 - - @staticmethod - def interpolate_stop_times(trip): - for secs, stop_time, is_timepoint in trip.GetTimeInterpolatedStops(): - if not is_timepoint: - stop_time.arrival_secs = secs - stop_time.departure_secs = secs - trip.ReplaceStopTimeObject(stop_time) diff --git a/creators/incofer/trips_creator_incofer.py b/creators/incofer/trips_creator_incofer.py index dbc6d8a1..7e3c5ffe 100644 --- a/creators/incofer/trips_creator_incofer.py +++ b/creators/incofer/trips_creator_incofer.py @@ -25,7 +25,7 @@ def add_trips_to_schedule(self, schedule, data): # print("DEBUG. procesando el itinerario", itinerary.name) # shape for itinerary - shape_id = _add_shape(schedule, itinerary_id, itinerary) + shape_id = TripsCreator.add_shape(schedule, itinerary_id, itinerary) # service periods | días de opearación (c/u con sus horarios) operations = self._get_itinerary_operation(itinerary) @@ -110,20 +110,6 @@ def _create_service_period(self, schedule, operation): return schedule.GetServicePeriod(operation) -def _add_shape(schedule, route_id, osm_r): - # get shape id - shape_id = str(route_id) - try: - schedule.GetShape(shape_id) - except KeyError: - shape = transitfeed.Shape(shape_id) - for point in osm_r.shape: - shape.AddPoint(lat=float(point["lat"]), lon=float(point["lon"])) - schedule.AddShapeObject(shape) - - return shape_id - - def add_trips_for_route(schedule, gtfs_route, itinerary, service_period, shape_id, estaciones, horarios): # debug diff --git a/creators/trips_creator.py b/creators/trips_creator.py index 42172631..aa5a18fe 100644 --- a/creators/trips_creator.py +++ b/creators/trips_creator.py @@ -14,3 +14,31 @@ def __repr__(self): def add_trips_to_schedule(self, schedule, data): raise NotImplementedError("Should have implemented this") + + @staticmethod + def interpolate_stop_times(trip): + """ + interpolate stop_times, because Navitia does not handle this itself by now + """ + for secs, stop_time, is_timepoint in trip.GetTimeInterpolatedStops(): + if not is_timepoint: + stop_time.arrival_secs = secs + stop_time.departure_secs = secs + trip.ReplaceStopTimeObject(stop_time) + + @staticmethod + def add_shape(schedule, route_id, osm_r): + """ + create GTFS shape and return shape_id to add on GTFS trip + """ + import transitfeed + shape_id = str(route_id) + try: + schedule.GetShape(shape_id) + except KeyError: + shape = transitfeed.Shape(shape_id) + for point in osm_r.shape: + shape.AddPoint( + lat=float(point["lat"]), lon=float(point["lon"])) + schedule.AddShapeObject(shape) + return shape_id From b6e1b1282376e89b13a2ea79b6f471123a2c3549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie?= Date: Sat, 26 Aug 2017 11:56:34 +0200 Subject: [PATCH 07/11] Accra - adjust config --- creators/accra/accra.json | 6 +++--- creators/accra/trips_creator_accra.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/creators/accra/accra.json b/creators/accra/accra.json index 349a704e..c67d2893 100644 --- a/creators/accra/accra.json +++ b/creators/accra/accra.json @@ -16,8 +16,8 @@ }, "agency": { "agency_id": "AM3", - "agency_name": "Accra Trotro", - "agency_url": "http://junglebus.io", + "agency_name": "Accra Tro tro", + "agency_url": "https://ama.gov.gh/welcome/transport/", "agency_timezone": "Africa/Accra", "agency_lang": "EN", "agency_phone": "", @@ -25,7 +25,7 @@ }, "feed_info": { "publisher_name": "Jungle Bus", - "publisher_url": "junglebus.io", + "publisher_url": "http://junglebus.io", "version": "0.1", "start_date": "20170901", "end_date": "20180730" diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index 0f2b9fc6..8df424f2 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -43,8 +43,8 @@ def add_trips_to_schedule(self, schedule, data): ROUTE_FREQUENCY = int(line.frequency) except Exception as e: print("Frequency not a number for route_master " + str(line.id)) - ROUTE_FREQUENCY = 10 - trip_gtfs.AddFrequency("06:00:00", "21:00:00", ROUTE_FREQUENCY * 60) #TODO horaires d'ouverture des lignes à confirmer + ROUTE_FREQUENCY = 30 + trip_gtfs.AddFrequency("05:00:00", "22:00:00", ROUTE_FREQUENCY * 60) for index_stop, a_stop in enumerate(a_route.stops) : stop_id = a_stop.split('/')[-1] @@ -53,7 +53,7 @@ def add_trips_to_schedule(self, schedule, data): if index_stop == 0 : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) elif index_stop == len(a_route.stops) -1 : - departure_time += timedelta(hours = 1) #TODO + departure_time += timedelta(minutes = 67) #TODO trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) else : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id))) From c41552e0e10eaa4cfe4f8c17704b8fb2eb990a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie?= Date: Sat, 26 Aug 2017 16:37:59 +0200 Subject: [PATCH 08/11] Accra - add travel_time from OSM --- core/osm_connector.py | 7 ++++++- core/osm_routes.py | 3 ++- creators/accra/trips_creator_accra.py | 10 ++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/osm_connector.py b/core/osm_connector.py index 43f7ea2d..e119eb61 100644 --- a/core/osm_connector.py +++ b/core/osm_connector.py @@ -327,6 +327,11 @@ def _build_route_variant(self, route_variant, query_result_set, rm=None): else: name = None + if 'travel_time' in route_variant.tags: + travel_time = route_variant.tags['travel_time'] + else: + travel_time = None + stops = [] # Add ids for stops of this route variant @@ -345,7 +350,7 @@ def _build_route_variant(self, route_variant, query_result_set, rm=None): stops.append(otype + "/" + str(stop_candidate.ref)) shape = self._generate_shape(route_variant, query_result_set) - rv = Route(route_variant.id, fr, to, stops, rm, ref, name, shape) + rv = Route(route_variant.id, fr, to, stops, rm, ref, name, shape, travel_time) print(rv) return rv diff --git a/core/osm_routes.py b/core/osm_routes.py index 25a95cab..d6db4e74 100644 --- a/core/osm_routes.py +++ b/core/osm_routes.py @@ -23,13 +23,14 @@ def __repr__(self): class Route(BaseRoute): - def __init__(self, osm, fr, to, stops, master, ref, name, shape): + def __init__(self, osm, fr, to, stops, master, ref, name, shape, travel_time = None): BaseRoute.__init__(self, osm, ref, name) self.fr = fr self.to = to self.stops = stops self.master = master self.shape = shape + self.travel_time = travel_time self.duration = None def __repr__(self): diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index 8df424f2..fe82150a 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -42,10 +42,16 @@ def add_trips_to_schedule(self, schedule, data): try: ROUTE_FREQUENCY = int(line.frequency) except Exception as e: - print("Frequency not a number for route_master " + str(line.id)) + print("frequency not a number for route_master " + str(line.id)) ROUTE_FREQUENCY = 30 trip_gtfs.AddFrequency("05:00:00", "22:00:00", ROUTE_FREQUENCY * 60) + try: + TRAVEL_TIME = int(a_route.travel_time) + except Exception as e: + print("travel_time not a number for route " + str(a_route.id)) + TRAVEL_TIME = 120 + for index_stop, a_stop in enumerate(a_route.stops) : stop_id = a_stop.split('/')[-1] departure_time = datetime(2008, 11, 22, 6, 0, 0) @@ -53,7 +59,7 @@ def add_trips_to_schedule(self, schedule, data): if index_stop == 0 : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) elif index_stop == len(a_route.stops) -1 : - departure_time += timedelta(minutes = 67) #TODO + departure_time += timedelta(minutes = TRAVEL_TIME) trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) else : trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id))) From 65cd81cd547d2befad27632a09438e953de067cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie?= Date: Sun, 24 Sep 2017 20:33:23 +0200 Subject: [PATCH 09/11] Accra - better handling for default values --- creators/accra/trips_creator_accra.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index fe82150a..7ce5df5d 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -39,18 +39,27 @@ def add_trips_to_schedule(self, schedule, data): trip_gtfs.trip_headsign = a_route.to trip_gtfs.direction_id = route_index % 2 route_index += 1 + DEFAULT_ROUTE_FREQUENCY = 30 + DEFAULT_TRAVEL_TIME = 120 + try: ROUTE_FREQUENCY = int(line.frequency) + if not ROUTE_FREQUENCY > 0 : + print("frequency is invalid for route_master " + str(line.id)) + ROUTE_FREQUENCY = DEFAULT_ROUTE_FREQUENCY except Exception as e: print("frequency not a number for route_master " + str(line.id)) - ROUTE_FREQUENCY = 30 + ROUTE_FREQUENCY = DEFAULT_ROUTE_FREQUENCY trip_gtfs.AddFrequency("05:00:00", "22:00:00", ROUTE_FREQUENCY * 60) try: TRAVEL_TIME = int(a_route.travel_time) + if not TRAVEL_TIME > 0 : + print("travel_time is invalid for route " + str(lia_routene.id)) + TRAVEL_TIME = DEFAULT_TRAVEL_TIME except Exception as e: print("travel_time not a number for route " + str(a_route.id)) - TRAVEL_TIME = 120 + TRAVEL_TIME = DEFAULT_TRAVEL_TIME for index_stop, a_stop in enumerate(a_route.stops) : stop_id = a_stop.split('/')[-1] From ff35b249eb11a976a27ee75c538f32deb0fe7587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mie?= Date: Wed, 27 Sep 2017 21:39:31 +0200 Subject: [PATCH 10/11] Accra - lint --- core/osm_connector.py | 4 +-- core/osm_routes.py | 4 +-- core/osm_stops.py | 6 ++-- creators/accra/stops_creator_accra.py | 7 +++-- creators/accra/trips_creator_accra.py | 44 ++++++++++++++++++--------- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/core/osm_connector.py b/core/osm_connector.py index e119eb61..9d172172 100644 --- a/core/osm_connector.py +++ b/core/osm_connector.py @@ -350,7 +350,8 @@ def _build_route_variant(self, route_variant, query_result_set, rm=None): stops.append(otype + "/" + str(stop_candidate.ref)) shape = self._generate_shape(route_variant, query_result_set) - rv = Route(route_variant.id, fr, to, stops, rm, ref, name, shape, travel_time) + rv = Route(route_variant.id, fr, to, stops, + rm, ref, name, shape, travel_time) print(rv) return rv @@ -530,7 +531,6 @@ def _is_valid_stop_candidate(self, stop): return False def _get_names_for_unnamed_stops(self): - """Intelligently guess stop names for unnamed stops by sourrounding street names and amenities. diff --git a/core/osm_routes.py b/core/osm_routes.py index d6db4e74..07621026 100644 --- a/core/osm_routes.py +++ b/core/osm_routes.py @@ -23,7 +23,7 @@ def __repr__(self): class Route(BaseRoute): - def __init__(self, osm, fr, to, stops, master, ref, name, shape, travel_time = None): + def __init__(self, osm, fr, to, stops, master, ref, name, shape, travel_time=None): BaseRoute.__init__(self, osm, ref, name) self.fr = fr self.to = to @@ -78,7 +78,7 @@ def print_shape_for_leaflet(self): class RouteMaster(BaseRoute): - def __init__(self, osm, ref, name, routes, frequency = None): + def __init__(self, osm, ref, name, routes, frequency=None): BaseRoute.__init__(self, osm, ref, name) self.routes = routes self.frequency = frequency diff --git a/core/osm_stops.py b/core/osm_stops.py index 5accfe7d..ce9828b1 100644 --- a/core/osm_stops.py +++ b/core/osm_stops.py @@ -21,8 +21,10 @@ def __repr__(self): if self.name is not None: rep += self.name if self.lat is not None and self.lon is not None: - rep += " http://www.openstreetmap.org/?mlat=" + str(self.lat) + "&mlon=" + str(self.lon) - rep += " (https://www.openstreetmap.org/" + self.type + "/" + str(self.id) + ")" + rep += " http://www.openstreetmap.org/?mlat=" + \ + str(self.lat) + "&mlon=" + str(self.lon) + rep += " (https://www.openstreetmap.org/" + \ + self.type + "/" + str(self.id) + ")" return rep @staticmethod diff --git a/creators/accra/stops_creator_accra.py b/creators/accra/stops_creator_accra.py index 17c59ec4..6fe4fadf 100644 --- a/creators/accra/stops_creator_accra.py +++ b/creators/accra/stops_creator_accra.py @@ -49,6 +49,7 @@ def create_stop_point(stop_data, schedule): ) return gtfs_stop_point + class StopsCreatorAccra(StopsCreator): def add_stops_to_schedule(self, schedule, data): @@ -66,14 +67,14 @@ def add_stops_to_schedule(self, schedule, data): for a_stop_point in stops_by_name[a_stop_name]: gtfs_stop_point = create_stop_point(a_stop_point, schedule) stop_point_has_parent_location = False - for a_stop_area in stop_areas : + for a_stop_area in stop_areas: distance_to_parent_station = get_crow_fly_distance( - (a_stop_area.stop_lat, a_stop_area.stop_lon), (a_stop_point.lat, a_stop_point.lon)) + (a_stop_area.stop_lat, a_stop_area.stop_lon), (a_stop_point.lat, a_stop_point.lon)) if distance_to_parent_station < 500: gtfs_stop_point.parent_station = a_stop_area.stop_id stop_point_has_parent_location = True break - if not stop_point_has_parent_location : + if not stop_point_has_parent_location: new_sa = create_stop_area(a_stop_point, schedule) gtfs_stop_point.parent_station = new_sa.stop_id stop_areas.append(new_sa) diff --git a/creators/accra/trips_creator_accra.py b/creators/accra/trips_creator_accra.py index 7ce5df5d..96e2d51b 100644 --- a/creators/accra/trips_creator_accra.py +++ b/creators/accra/trips_creator_accra.py @@ -8,12 +8,12 @@ from core.osm_routes import Route, RouteMaster - class TripsCreatorAccra(TripsCreator): def add_trips_to_schedule(self, schedule, data): self.service_weekday = schedule.GetDefaultServicePeriod() - self.service_weekday.SetStartDate(self.config['feed_info']['start_date']) + self.service_weekday.SetStartDate( + self.config['feed_info']['start_date']) self.service_weekday.SetEndDate(self.config['feed_info']['end_date']) self.service_weekday.SetWeekdayService(True) self.service_weekday.SetWeekendService(True) @@ -22,9 +22,13 @@ def add_trips_to_schedule(self, schedule, data): for route_ref, line in sorted(lines.iteritems()): if type(line).__name__ != "RouteMaster": continue + line_gtfs = schedule.AddRoute( short_name=line.ref, long_name=line.name.decode('utf8'), + # we change the route_long_name with the 'from' and 'to' tags + # of the last route as the route_master name tag contains + # the line code (route_short_name) route_type="Bus", route_id=line.id) line_gtfs.agency_id = schedule.GetDefaultAgency().agency_id @@ -35,42 +39,52 @@ def add_trips_to_schedule(self, schedule, data): route_index = 0 for a_route_ref, a_route in line.routes.iteritems(): trip_gtfs = line_gtfs.AddTrip(schedule) - trip_gtfs.shape_id = TripsCreator.add_shape(schedule, a_route_ref, a_route) - trip_gtfs.trip_headsign = a_route.to + trip_gtfs.shape_id = TripsCreator.add_shape( + schedule, a_route_ref, a_route) trip_gtfs.direction_id = route_index % 2 route_index += 1 + + if a_route.fr and a_route.to: + trip_gtfs.trip_headsign = a_route.to + line_gtfs.route_long_name = a_route.fr.decode( + 'utf8') + " ↔ ".decode('utf8') + a_route.to.decode('utf8') + DEFAULT_ROUTE_FREQUENCY = 30 DEFAULT_TRAVEL_TIME = 120 try: ROUTE_FREQUENCY = int(line.frequency) - if not ROUTE_FREQUENCY > 0 : + if not ROUTE_FREQUENCY > 0: print("frequency is invalid for route_master " + str(line.id)) ROUTE_FREQUENCY = DEFAULT_ROUTE_FREQUENCY except Exception as e: print("frequency not a number for route_master " + str(line.id)) ROUTE_FREQUENCY = DEFAULT_ROUTE_FREQUENCY - trip_gtfs.AddFrequency("05:00:00", "22:00:00", ROUTE_FREQUENCY * 60) + trip_gtfs.AddFrequency( + "05:00:00", "22:00:00", ROUTE_FREQUENCY * 60) try: TRAVEL_TIME = int(a_route.travel_time) - if not TRAVEL_TIME > 0 : - print("travel_time is invalid for route " + str(lia_routene.id)) + if not TRAVEL_TIME > 0: + print("travel_time is invalid for route " + + str(lia_routene.id)) TRAVEL_TIME = DEFAULT_TRAVEL_TIME except Exception as e: print("travel_time not a number for route " + str(a_route.id)) TRAVEL_TIME = DEFAULT_TRAVEL_TIME - for index_stop, a_stop in enumerate(a_route.stops) : + for index_stop, a_stop in enumerate(a_route.stops): stop_id = a_stop.split('/')[-1] departure_time = datetime(2008, 11, 22, 6, 0, 0) - if index_stop == 0 : - trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) - elif index_stop == len(a_route.stops) -1 : - departure_time += timedelta(minutes = TRAVEL_TIME) - trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) - else : + if index_stop == 0: + trip_gtfs.AddStopTime(schedule.GetStop( + str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) + elif index_stop == len(a_route.stops) - 1: + departure_time += timedelta(minutes=TRAVEL_TIME) + trip_gtfs.AddStopTime(schedule.GetStop( + str(stop_id)), stop_time=departure_time.strftime("%H:%M:%S")) + else: trip_gtfs.AddStopTime(schedule.GetStop(str(stop_id))) for secs, stop_time, is_timepoint in trip_gtfs.GetTimeInterpolatedStops(): From d05651e835a802c72d96c4c10dd04a46f71bfe5e Mon Sep 17 00:00:00 2001 From: Pascal Rhod Date: Fri, 6 Oct 2017 22:35:55 +0200 Subject: [PATCH 11/11] Accra - fix stoparea stop_id --- creators/accra/stops_creator_accra.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/creators/accra/stops_creator_accra.py b/creators/accra/stops_creator_accra.py index 6fe4fadf..f24f1118 100644 --- a/creators/accra/stops_creator_accra.py +++ b/creators/accra/stops_creator_accra.py @@ -49,6 +49,8 @@ def create_stop_point(stop_data, schedule): ) return gtfs_stop_point +def get_stop_id(stop): + return stop.id class StopsCreatorAccra(StopsCreator): @@ -64,7 +66,7 @@ def add_stops_to_schedule(self, schedule, data): for a_stop_name in stops_by_name: stop_areas = [] - for a_stop_point in stops_by_name[a_stop_name]: + for a_stop_point in sorted(stops_by_name[a_stop_name], key=get_stop_id): gtfs_stop_point = create_stop_point(a_stop_point, schedule) stop_point_has_parent_location = False for a_stop_area in stop_areas: