Skip to content

Commit 92bbea0

Browse files
author
Patrick Qian
authored
Merge pull request #3872 from hove-io/use_access_points_in_transfer_path
[Jormungandr] implement access_points in transfer path
2 parents 578b1b7 + 78190f7 commit 92bbea0

File tree

9 files changed

+398
-115
lines changed

9 files changed

+398
-115
lines changed

source/ed/build_helper.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ void builder::generate_dummy_basis() {
748748
this->data->pt_data->get_or_create_commercial_mode("Bus", "Bus");
749749
this->data->pt_data->get_or_create_commercial_mode("Car", "Car");
750750
this->data->pt_data->get_or_create_commercial_mode("Coach", "Autocar");
751+
this->data->pt_data->get_or_create_commercial_mode("RapidTransit", "RER");
751752

752753
for (navitia::type::CommercialMode* mt : this->data->pt_data->commercial_modes) {
753754
data->pt_data->get_or_create_physical_mode("physical_mode:" + mt->uri, mt->name, get_co2_emission(mt->uri));

source/jormungandr/jormungandr/georef.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ def get_stop_points_for_stop_area(self, uri, request_id):
172172
)
173173
return result.stop_points
174174

175-
def get_stop_points_from_uri(self, uri, request_id):
175+
def get_stop_points_from_uri(self, uri, request_id, depth=0):
176176
req = request_pb2.Request()
177177
req.requested_api = type_pb2.PTREFERENTIAL
178178
req.ptref.requested_type = type_pb2.STOP_POINT
179179
req.ptref.count = 100
180180
req.ptref.start_page = 0
181-
req.ptref.depth = 0
181+
req.ptref.depth = depth
182182
req.ptref.filter = 'stop_point.uri = {uri}'.format(uri=uri)
183183
result = self.instance.send_and_receive(req, request_id=request_id)
184184
return result.stop_points

source/jormungandr/jormungandr/scenarios/distributed.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,9 @@ def finalise_journeys(self, future_manager, request, responses, context, instanc
318318

319319
journeys_to_complete = get_journeys_to_complete(responses, context, is_debug)
320320

321-
transfer_pool = TransferPool(future_manager=future_manager, instance=instance, request=request)
321+
transfer_pool = TransferPool(
322+
future_manager=future_manager, instance=instance, request=request, request_id=request_id
323+
)
322324

323325
if request['_transfer_path'] is True:
324326
for journey in journeys_to_complete:

source/jormungandr/jormungandr/scenarios/helper_classes/helper_utils.py

+82-25
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
SectionSorter,
3636
get_pt_object_coord,
3737
generate_id,
38-
get_overriding_mode,
3938
)
4039
from jormungandr.street_network.utils import crowfly_distance_between
4140
from jormungandr.fallback_modes import FallbackModes, all_fallback_modes
@@ -247,6 +246,34 @@ def _extend_with_car_park(
247246
dp_journey.distances.walking += int(walking_speed * car_park_crowfly_duration)
248247

249248

249+
def append_path_item_with_access_point(path_items, stop_point, access_point):
250+
via = path_items.add()
251+
via.duration = access_point.traversal_time
252+
via.length = access_point.length
253+
via.name = access_point.name
254+
# Use label in stead of name???
255+
via.instruction = u"Then Enter {} via {}.".format(stop_point.label, access_point.name)
256+
via.via_uri = access_point.uri
257+
258+
259+
def prepend_path_item_with_access_point(path_items, stop_point, access_point):
260+
via = path_items.add()
261+
via.duration = access_point.traversal_time
262+
via.length = access_point.length
263+
via.name = access_point.name
264+
# Use label in stead of name???
265+
via.instruction = u"Exit {} via {}.".format(stop_point.label, access_point.name)
266+
via.via_uri = access_point.uri
267+
268+
# we cannot insert an element at the beginning of a list :(
269+
# a little algo to move the last element to the beginning
270+
tmp_item = response_pb2.PathItem()
271+
for i in range(len(path_items)):
272+
tmp_item.CopyFrom(path_items[i])
273+
path_items[i].CopyFrom(path_items[-1])
274+
path_items[-1].CopyFrom(tmp_item)
275+
276+
250277
def _extend_with_via_access_point(fallback_dp, pt_object, fallback_type, via_access_point):
251278
if via_access_point is None:
252279
return
@@ -266,37 +293,21 @@ def _extend_with_via_access_point(fallback_dp, pt_object, fallback_type, via_acc
266293
dp_journey.sections[0].street_network.duration += traversal_time
267294
dp_journey.sections[0].street_network.length += length
268295

269-
via = dp_journey.sections[-1].street_network.path_items.add()
270-
via.duration = traversal_time
271-
via.length = length
272-
via.name = via_access_point.name
273-
# Use label in stead of name???
274-
via.instruction = u"Then Enter {} via {}.".format(pt_object.stop_point.label, via_access_point.name)
275-
via.via_uri = via_access_point.uri
296+
append_path_item_with_access_point(
297+
dp_journey.sections[-1].street_network.path_items,
298+
pt_object.stop_point,
299+
via_access_point.access_point,
300+
)
276301

277302
elif fallback_type == StreetNetworkPathType.ENDING_FALLBACK:
278303
dp_journey.sections[-1].end_date_time += traversal_time
279304
dp_journey.sections[-1].duration += traversal_time
280305
dp_journey.sections[-1].street_network.duration += traversal_time
281306
dp_journey.sections[-1].street_network.length += length
282307

283-
path_items = dp_journey.sections[0].street_network.path_items
284-
285-
via = dp_journey.sections[0].street_network.path_items.add()
286-
via.duration = traversal_time
287-
via.length = length
288-
via.name = via_access_point.name
289-
# Use label in stead of name???
290-
via.instruction = u"Exit {} via {}.".format(pt_object.stop_point.label, via_access_point.name)
291-
via.via_uri = via_access_point.uri
292-
293-
# we cannot insert an element at the beginning of a list :(
294-
# a little algo to move the last element to the beginning
295-
tmp_item = response_pb2.PathItem()
296-
for i in range(len(path_items)):
297-
tmp_item.CopyFrom(path_items[i])
298-
path_items[i].CopyFrom(path_items[-1])
299-
path_items[-1].CopyFrom(tmp_item)
308+
prepend_path_item_with_access_point(
309+
dp_journey.sections[0].street_network.path_items, pt_object.stop_point, via_access_point.access_point
310+
)
300311

301312

302313
def _update_fallback_sections(journey, fallback_dp, fallback_period_extremity, fallback_type, via_access_point):
@@ -766,3 +777,49 @@ def complete_transfer(pt_journey, transfer_pool):
766777
if section.type != response_pb2.TRANSFER:
767778
continue
768779
transfer_pool.wait_and_complete(section)
780+
781+
782+
def is_valid_direct_path_streetwork(dp):
783+
if not dp or not dp.journeys or not dp.journeys[0].sections:
784+
return False
785+
786+
# a valid journey's must comprise at least two coordinates
787+
nb_coords = sum((len(sec.street_network.coordinates) for sec in dp.journeys[0].sections))
788+
if nb_coords < 2:
789+
return False
790+
return True
791+
792+
793+
def prepend_first_coord(dp, pt_obj):
794+
"""
795+
prepend pt_object's coord to journeys' coordinates (geojson)
796+
"""
797+
if not is_valid_direct_path_streetwork(dp):
798+
return
799+
800+
starting_coords = dp.journeys[0].sections[0].street_network.coordinates
801+
# we are inserting the coord of the origin at the beginning of the geojson
802+
coord = get_pt_object_coord(pt_obj)
803+
if starting_coords and coord != starting_coords[0]:
804+
starting_coords.add(lon=coord.lon, lat=coord.lat)
805+
# we cannot insert an element at the beginning of a list :(
806+
# a little algo to move the last element to the beginning
807+
tmp = type_pb2.GeographicalCoord()
808+
for i in range(len(starting_coords)):
809+
tmp.CopyFrom(starting_coords[i])
810+
starting_coords[i].CopyFrom(starting_coords[-1])
811+
starting_coords[-1].CopyFrom(tmp)
812+
813+
814+
def append_last_coord(dp, pt_obj):
815+
"""
816+
append pt_object's coord to journeys' coordinates (geojson)
817+
"""
818+
if not is_valid_direct_path_streetwork(dp):
819+
return
820+
821+
ending_coords = dp.journeys[0].sections[-1].street_network.coordinates
822+
# we are appending the coord of the destination at the end of the geojson
823+
coord = get_pt_object_coord(pt_obj)
824+
if ending_coords and coord != ending_coords[-1]:
825+
ending_coords.add(lon=coord.lon, lat=coord.lat)

source/jormungandr/jormungandr/scenarios/helper_classes/streetnetwork_path.py

+3-30
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from jormungandr import utils, new_relic
3131
from jormungandr.street_network.street_network import StreetNetworkPathType
3232
import logging
33-
from .helper_utils import timed_logger
33+
from .helper_utils import timed_logger, prepend_first_coord, append_last_coord
3434
from navitiacommon import type_pb2, response_pb2
3535
from jormungandr.exceptions import GeoveloTechnicalError
3636
from .helper_exceptions import StreetNetworkException
@@ -101,33 +101,6 @@ def _direct_path_with_fp(self):
101101
logging.getLogger(__name__).exception('')
102102
return None
103103

104-
def _add_first_and_last_coord(self, dp):
105-
if not dp or not dp.journeys or not dp.journeys[0].sections:
106-
return
107-
108-
nb_coords = sum((len(sec.street_network.coordinates) for sec in dp.journeys[0].sections))
109-
if nb_coords < 2:
110-
return
111-
112-
starting_coords = dp.journeys[0].sections[0].street_network.coordinates
113-
# we are inserting the coord of the origin at the beginning of the geojson
114-
coord = utils.get_pt_object_coord(self._orig_obj)
115-
if starting_coords and coord != starting_coords[0]:
116-
starting_coords.add(lon=coord.lon, lat=coord.lat)
117-
# we cannot insert an element at the beginning of a list :(
118-
# a little algo to move the last element to the beginning
119-
tmp = type_pb2.GeographicalCoord()
120-
for i in range(len(starting_coords)):
121-
tmp.CopyFrom(starting_coords[i])
122-
starting_coords[i].CopyFrom(starting_coords[-1])
123-
starting_coords[-1].CopyFrom(tmp)
124-
125-
ending_coords = dp.journeys[0].sections[-1].street_network.coordinates
126-
# we are appending the coord of the destination at the end of the geojson
127-
coord = utils.get_pt_object_coord(self._dest_obj)
128-
if ending_coords and coord != ending_coords[-1]:
129-
ending_coords.add(lon=coord.lon, lat=coord.lat)
130-
131104
def _do_request(self):
132105
self._logger.debug(
133106
"requesting %s direct path from %s to %s by %s",
@@ -138,8 +111,8 @@ def _do_request(self):
138111
)
139112

140113
dp = self._direct_path_with_fp(self._streetnetwork_service)
141-
142-
self._add_first_and_last_coord(dp)
114+
prepend_first_coord(dp, self._orig_obj)
115+
append_last_coord(dp, self._dest_obj)
143116

144117
if getattr(dp, "journeys", None):
145118
dp.journeys[0].internal_id = str(utils.generate_id())

0 commit comments

Comments
 (0)