diff --git a/osm2gtfs/creators/cr_gam/__init__.py b/osm2gtfs/creators/cr_gam/__init__.py deleted file mode 100644 index 5c9136ad..00000000 --- a/osm2gtfs/creators/cr_gam/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 diff --git a/osm2gtfs/creators/cr_gam/config.json b/osm2gtfs/creators/cr_gam/config.json index d0b495ea..9a3699ed 100644 --- a/osm2gtfs/creators/cr_gam/config.json +++ b/osm2gtfs/creators/cr_gam/config.json @@ -27,12 +27,11 @@ }, "feed_info": { "publisher_name": "Laboratorio Experimental", - "publisher_url": "http://ic-itcr.ac.cr/~jgutierrez/incofer/", - "version": "0.1", - "start_date" : "20170202", - "end_date": "20170910" + "publisher_url": "http://www.labexp.org", + "version": "0.1" + }, - "schedule_source": "https://raw.githubusercontent.com/jamescr/incofer-datos/master/input_incofer.json", + "schedule_source": "https://raw.githubusercontent.com/jamescr/incofer-datos/master/incofer_schedule.json", "output_file": "data/cr-gam.zip", "selector": "cr_gam" } diff --git a/osm2gtfs/creators/cr_gam/routes_creator_cr_gam.py b/osm2gtfs/creators/cr_gam/routes_creator_cr_gam.py deleted file mode 100644 index 20953ee8..00000000 --- a/osm2gtfs/creators/cr_gam/routes_creator_cr_gam.py +++ /dev/null @@ -1,79 +0,0 @@ -# coding=utf-8 - -import sys -from osm2gtfs.core.elements import Line, Itinerary, Station, Stop -from osm2gtfs.creators.routes_creator import RoutesCreator - - -class RoutesCreatorCrGam(RoutesCreator): - - def add_routes_to_feed(self, feed, data): - ''' - Override routes to feed method, to prepare routes with stops - for the handling in the custom trips creators. - ''' - routes = data.get_routes() - stops = data.get_stops() - - # Loop through routes - for ref, route in routes.iteritems(): - # Replace stop ids with Stop objects - self._fill_stops(stops['regular'], route) - - # debug - # print("DEBUG: creando itinerarios a partir de", str(len(lines)), - # "lineas") - - # Loop through all lines (master_routes) - for line_ref, line in sorted(routes.iteritems()): - route = feed.AddRoute( - short_name=line.route_id.encode('utf-8'), - long_name=line.name, - # TODO: infer transitfeed "route type" from OSM data - route_type="Tram", - route_id=line_ref) - - # AddRoute method add defaut agency as default - route.agency_id = feed.GetDefaultAgency().agency_id - - route.route_desc = "Test line" - - # TODO: get route_url from OSM or other source. - # url = "http://www.incofer.go.cr/tren-urbano-alajuela-rio-segundo" - - # line.route_url = url - route.route_color = "ff0000" - route.route_text_color = "ffffff" - - # debug - # print("información de la linea:", line.name, "agregada.") - return - - def _fill_stops(self, stops, route): - """ - Fill a route object with stop objects for of linked stop ids - """ - if isinstance(route, Itinerary): - i = 0 - for stop in route.stops: - # Replace stop id with Stop objects - route.stops[i] = self._look_up_stop(stop, stops) - i += 1 - - elif isinstance(route, Line): - itineraries = route.get_itineraries() - for itinerary in itineraries: - self._fill_stops(stops, itinerary) - else: - sys.stderr.write("Unknown route: " + str(route) + "\n") - - def _look_up_stop(self, stop_id, stops): - for ref, elem in stops.iteritems(): - if type(elem) is Stop: - if ref == stop_id: - return elem - elif type(elem) is Station: - if stop_id in elem.stop_members: - return elem.stop_members[stop_id] - else: - sys.stderr.write("Unknown stop: " + str(stop_id) + "\n") diff --git a/osm2gtfs/creators/cr_gam/stops_creator_cr_gam.py b/osm2gtfs/creators/cr_gam/stops_creator_cr_gam.py deleted file mode 100644 index 1d0ce152..00000000 --- a/osm2gtfs/creators/cr_gam/stops_creator_cr_gam.py +++ /dev/null @@ -1,13 +0,0 @@ -# coding=utf-8 - -from osm2gtfs.creators.stops_creator import StopsCreator - - -class StopsCreatorCrGam(StopsCreator): - - # Override construction of stop_id - def _define_stop_id(self, stop): - if stop.osm_type == "relation": - return "SA" + str(stop.osm_id) - else: - return str(stop.osm_id) diff --git a/osm2gtfs/creators/cr_gam/trips_creator_cr_gam.py b/osm2gtfs/creators/cr_gam/trips_creator_cr_gam.py deleted file mode 100644 index 3d90e41d..00000000 --- a/osm2gtfs/creators/cr_gam/trips_creator_cr_gam.py +++ /dev/null @@ -1,174 +0,0 @@ -# coding=utf-8 - -from datetime import datetime - -import transitfeed - -from osm2gtfs.creators.trips_creator import TripsCreator - - -class TripsCreatorCrGam(TripsCreator): - - def add_trips_to_feed(self, feed, data): - - lines = data.get_routes() - - # line (osm rounte master | gtfs route) - for line_id, line in lines.iteritems(): - # debug - # print("DEBUG. procesando la línea:", line.name) - - # itinerary (osm route | non existent gtfs element) - itineraries = line.get_itineraries() - for itinerary in itineraries: - # debug - # print("DEBUG. procesando el itinerario", itinerary.name) - - # shape for itinerary - shape_id = self._add_shape_to_feed(feed, itinerary.osm_id, itinerary) - - # service periods | días de opearación (c/u con sus horarios) - operations = self._get_itinerary_operation(itinerary, data) - - # operation (gtfs service period) - for operation in operations: - service_period = self._create_service_period( - feed, operation) - - horarios = load_times(itinerary, data, operation) - estaciones = load_stations(itinerary, data, operation) - - route = feed.GetRoute(line_id) - - add_trips_for_route(feed, route, itinerary, - service_period, shape_id, estaciones, - horarios) - return - - def _get_itinerary_operation(self, itinerary, data): - """ - Retorna un iterable (lista) de objetos str, cada uno un 'keyword' - del día o días de servicio, cuyos viajes (estaciones y horarios) se - incluyen en el archivo de entrada. - """ - - start_date = self.config['feed_info']['start_date'] - enda_date = self.config['feed_info']['end_date'] - - operations = [] - - for operation in data.schedule["itinerario"][itinerary.route_id]: - input_fr = operation["from"] - input_to = operation["to"] - if input_fr == itinerary.fr and input_to == itinerary.to: - - if operation["operacion"] == "weekday": - operations.append("weekday") - - if operation["operacion"] == "saturday": - operations.append("saturday") - - if operation["operacion"] == "sunday": - operations.append("sunday") - return operations - - def _create_service_period(self, feed, operation): - try: - service = feed.GetServicePeriod(operation) - if service is not None: - return service - except KeyError: - print("INFO. There is no service_period for this service:", - operation, " therefore it will be created.") - - if operation == "weekday": - service = transitfeed.ServicePeriod("weekday") - service.SetWeekdayService(True) - service.SetWeekendService(False) - elif operation == "saturday": - service = transitfeed.ServicePeriod("saturday") - service.SetWeekdayService(False) - service.SetWeekendService(False) - service.SetDayOfWeekHasService(5, True) - elif operation == "sunday": - service = transitfeed.ServicePeriod("sunday") - service.SetWeekdayService(False) - service.SetWeekendService(False) - service.SetDayOfWeekHasService(6, True) - else: - raise KeyError("uknown operation keyword") - - service.SetStartDate(self.config['feed_info']['start_date']) - service.SetEndDate(self.config['feed_info']['end_date']) - feed.AddServicePeriodObject(service) - return feed.GetServicePeriod(operation) - - -def add_trips_for_route(feed, gtfs_route, itinerary, service_period, - shape_id, estaciones, horarios): - # debug - # print("DEBUG Adding trips for itinerary", itinerary.name) - - for viaje in horarios: - indice = 0 - trip = gtfs_route.AddTrip(feed, headsign=itinerary.name, - service_period=service_period) - while indice < len(estaciones): - tiempo = viaje[indice] - estacion = estaciones[indice] - if tiempo != "-": - tiempo_parada = datetime.strptime(tiempo, "%H:%M") - tiempo_parada = str(tiempo_parada.time()) - - for stop in itinerary.stops: - if stop.name == estacion: - parada = feed.GetStop(str(stop.stop_id)) - trip.AddStopTime(parada, stop_time=str(tiempo_parada)) - continue - - # add empty attributes to make navitia happy - trip.block_id = "" - trip.wheelchair_accessible = "" - trip.bikes_allowed = "" - trip.shape_id = shape_id - trip.direction_id = "" - - indice = indice + 1 - return - - -def load_stations(route, data, operation): - - stations = [] - for direction in data.schedule["itinerario"][route.route_id]: - data_operation = direction["operacion"] - if (direction["from"] == route.fr and - direction["to"] == route.to and data_operation == operation): - for station in direction["estaciones"]: - stations = stations + [station] - - # debug - # print("(json) estaciones encontradas: " + str(len(stations))) - # for estacion in stations: - # print(estacion) - - return stations - - -def load_times(route, data, operation): - - # route_directions = data.schedule["itinerario"][route.ref]["horarios"] - times = None - - for direction in data.schedule["itinerario"][route.route_id]: - data_operation = direction["operacion"] - if (direction["from"] == route.fr and - direction["to"] == route.to and data_operation == operation): - times = direction["horarios"] - - if times is None: - print("debug: ruta va de", route.fr, - "hacia", route.to) - print("error consiguiendo los tiempos de la ruta") - - return times