Skip to content

Commit

Permalink
Accra - lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nlehuby authored and grote committed Oct 7, 2017
1 parent baf7b8a commit c22af7b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 24 deletions.
4 changes: 2 additions & 2 deletions core/osm_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions core/osm_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions core/osm_stops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions creators/accra/stops_creator_accra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
44 changes: 29 additions & 15 deletions creators/accra/trips_creator_accra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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():
Expand Down

0 comments on commit c22af7b

Please sign in to comment.