Skip to content

Commit 24fbe56

Browse files
committed
implement refine_results
1 parent 41c568c commit 24fbe56

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pymmrouting/routeplanner.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,27 @@ def batch_find_path(self, plans):
137137
return result_dict
138138

139139
def refine_results(self, results):
140-
# TODO Deduplicate the routing results
141-
# TODO Remove (set is_existent = false) the path containing pure
142-
# walking path in public_transportation mode
140+
refined_results = []
141+
for r in results['routes']:
142+
if r['existence'] == False:
143+
continue
144+
modes = [f['properties']['mode'] for f in r['geojson']['features']]
145+
pt_modes = ['suburban', 'underground', 'tram', 'bus']
146+
# Eliminate the result claiming using public transit but actually
147+
# does not
148+
if not (set(modes).isdisjoint(set(pt_modes))):
149+
# Claim using public transit
150+
real_switch_types = [sp['properties']['type'] for sp in r['switch_points']]
151+
pt_switch_types = ['suburban_station',
152+
'underground_station',
153+
'tram_station',
154+
'bus_station']
155+
if set(real_switch_types).isdisjoint(set(pt_switch_types)):
156+
# It claims using public transit but no public transit station
157+
# is found in the result path. Such a path will be eliminated.
158+
continue
159+
refined_results.append(r)
160+
results['routes'] = refined_results
143161
return results
144162

145163
def find_path(self, plan):

0 commit comments

Comments
 (0)