Remove overriden __hash__ and __eq__ methods for Station and StopArea classes
This commit is contained in:
parent
dc050ac611
commit
9a94b22145
1 changed files with 9 additions and 20 deletions
|
@ -225,14 +225,6 @@ class Station:
|
|||
return 'Station(id={}, modes={}, name={}, center={})'.format(
|
||||
self.id, ','.join(self.modes), self.name, self.center)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.__repr__())
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, Station):
|
||||
return self.id == other.id
|
||||
return False
|
||||
|
||||
|
||||
class StopArea:
|
||||
@staticmethod
|
||||
|
@ -366,14 +358,6 @@ class StopArea:
|
|||
return 'StopArea(id={}, name={}, station={}, transfer={}, center={})'.format(
|
||||
self.id, self.name, self.station, self.transfer, self.center)
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.__repr__())
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, StopArea):
|
||||
return self.id == other.id and self.station == other.station
|
||||
return False
|
||||
|
||||
|
||||
class RouteStop:
|
||||
def __init__(self, stoparea):
|
||||
|
@ -1237,18 +1221,23 @@ def find_transfers(elements, cities):
|
|||
el.get('tags', {}).get('public_transport') == 'stop_area_group'):
|
||||
stop_area_groups.append(el)
|
||||
|
||||
stations = defaultdict(set) # el_id -> list of station objects
|
||||
# A tuple(sa.id, sa.station is None) uniquely identifies a StopArea.
|
||||
# We must ensure StopArea uniqueness since one stop_area relation may result in
|
||||
# several StopArea instances at inter-city interchanges.
|
||||
stop_area_ids = defaultdict(set) # el_id -> set of tuples (sa.id, sa.station is None)
|
||||
stop_area_objects = dict() # tuple(sa.id, sa.station is None) -> one of StopArea instances
|
||||
for city in cities:
|
||||
for el, st in city.stations.items():
|
||||
stations[el].update(st)
|
||||
stop_area_ids[el].update((sa.id, sa.station is None) for sa in st)
|
||||
stop_area_objects.update(((sa.id, sa.station is None), sa) for sa in st)
|
||||
|
||||
for sag in stop_area_groups:
|
||||
transfer = set()
|
||||
for m in sag['members']:
|
||||
k = el_id(m)
|
||||
if k not in stations:
|
||||
if k not in stop_area_ids:
|
||||
continue
|
||||
transfer.update(stations[k])
|
||||
transfer.update(stop_area_objects[sa_id] for sa_id in stop_area_ids[k])
|
||||
if len(transfer) > 1:
|
||||
transfers.append(transfer)
|
||||
return transfers
|
||||
|
|
Loading…
Add table
Reference in a new issue