-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data structure #89
Closed
Closed
Data structure #89
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# coding=utf-8 | ||
|
||
|
||
class Debug(object): | ||
"""The Debug class contains special functions used for debugging | ||
|
||
""" | ||
|
||
@staticmethod | ||
def print_shape_for_leaflet(shape): | ||
print "var shape = [", | ||
i = 0 | ||
for node in shape: | ||
print "new L.LatLng(" + str(node["lat"]) + ", " + str(node["lon"]) + ")", | ||
if i != len(shape) - 1: | ||
print ",", | ||
i += 1 | ||
print "];" | ||
i = 0 | ||
for node in shape: | ||
print "L.marker([" + str(node["lat"]) + ", " + str(node["lon"]) + "]).addTo(map)" | ||
print " .bindPopup(\"" + str(i) + "\").openPopup();" | ||
i += 1 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# coding=utf-8 | ||
|
||
import attr | ||
|
||
|
||
@attr.s | ||
class Line(object): | ||
"""A general public transport service Line. | ||
|
||
It's a container of meta information and different Itinerary objects for | ||
variants of the same service line. | ||
|
||
In OpenStreetMap this is usually represented as "route_master" relation. | ||
In GTFS this is usually represented as "route" | ||
|
||
""" | ||
osm_id = attr.ib() | ||
route_id = attr.ib() | ||
name = attr.ib() | ||
route_type = attr.ib() # Required (Tram, Subway, Rail, Bus, ...) | ||
|
||
route_desc = attr.ib(default=None) | ||
route_url = attr.ib(default=None) | ||
route_color = attr.ib(default="FFFFFF") | ||
route_text_color = attr.ib(default="000000") | ||
osm_url = attr.ib(default="http://osm.org/relation/" + str(osm_id)) | ||
frequency = attr.ib(default=None) | ||
|
||
# Related route variants | ||
_itineraries = attr.ib(default=attr.Factory(list)) | ||
|
||
def add_itinerary(self, itinerary): | ||
if self.route_id.encode('utf-8') != itinerary.route_id.encode('utf-8'): | ||
raise ValueError('Itinerary route ID (' + | ||
itinerary.route_id + | ||
') does not match Line route ID (' + | ||
self.route_id + ')') | ||
self._itineraries.append(itinerary) | ||
|
||
def get_itineraries(self): | ||
return self._itineraries | ||
|
||
|
||
@attr.s | ||
class Itinerary(object): | ||
"""A public transport service itinerary. | ||
|
||
It's a representation of a possible variant of a line, grouped together by | ||
a Line object. | ||
|
||
In OpenStreetMap this is usually represented as "route" relation. | ||
In GTFS this is not exlicitly presented but used as based to create "trips" | ||
|
||
""" | ||
osm_id = attr.ib() | ||
route_id = attr.ib() | ||
name = attr.ib() | ||
fr = attr.ib() | ||
to = attr.ib() | ||
shape = attr.ib() | ||
stops = attr.ib() | ||
travel_time = attr.ib() | ||
|
||
route_url = attr.ib(default=None) | ||
wheelchair_accessible = attr.ib(default=0) | ||
bikes_allowed = attr.ib(default=0) | ||
osm_url = attr.ib(default="http://osm.org/relation/" + str(osm_id)) | ||
|
||
# Useful information for further calculation | ||
duration = attr.ib(default=None) | ||
|
||
# All stop objects of itinerary | ||
_stop_objects = attr.ib(default=attr.Factory(list)) | ||
|
||
def add_stop(self, stop): | ||
self._stop_objects.append(stop) | ||
|
||
def get_stop_by_position(self, pos): | ||
raise NotImplementedError("Should have implemented this") | ||
|
||
def get_stops(self): | ||
return self._stop_objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# coding=utf-8 | ||
|
||
import attr | ||
|
||
|
||
@attr.s | ||
class Stop(object): | ||
|
||
osm_id = attr.ib() | ||
osm_type = attr.ib() | ||
name = attr.ib() | ||
lat = attr.ib() | ||
lon = attr.ib() | ||
gtfs_id = attr.ib(default=osm_id) | ||
osm_url = attr.ib(default="http://osm.org/" + | ||
str(osm_type) + "/" + str(osm_id)) | ||
|
||
|
||
@attr.s | ||
class StopArea(object): | ||
|
||
osm_id = attr.ib() | ||
name = attr.ib() | ||
lat = attr.ib() | ||
lon = attr.ib() | ||
|
||
stop_members = attr.ib(default=attr.Factory(list)) | ||
|
||
def __init__(self, osm_id, stop_members, name=None): | ||
self.osm_id = osm_id | ||
if name is not None: | ||
self.name = name.encode('utf-8') | ||
else: | ||
self.name = name | ||
self.stop_members = stop_members | ||
|
||
from osm2gtfs.core.osm_connector import OsmConnector | ||
self.lat, self.lon = OsmConnector.get_center_of_nodes(self.stop_members.values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need an
osm_type
? What values can this have?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be either
node
orway
. Depending on the type different behaviours might be necessary. E.g for away
you may want to find the center. And we concretely need it for constructing the url to the object here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another reason is also related to #94:
osm_id
is used for different id spaces, depending onosm_type
. Both together can identify an object in OSM, not onlyosm_id
. For the id of the GTFS it is recommended to combine those two in any way.