Skip to content

Commit

Permalink
Merge pull request #4043 from hove-io/add_odt_stop_points_for_loki
Browse files Browse the repository at this point in the history
Loki: add odt_stop_spoints
  • Loading branch information
Patrick Qian authored Jul 18, 2023
2 parents 29869b7 + 630e390 commit 74b0b1d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
8 changes: 8 additions & 0 deletions source/jormungandr/jormungandr/pt_planners/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,11 @@ def get_crow_fly(
if len(res.feed_publishers) != 0:
logger.error("feed publisher not empty: expect performance regression!")
return res.places_nearby


def get_odt_stop_points(pt_planner, coord, request_id):
req = request_pb2.Request()
req.requested_api = type_pb2.odt_stop_points
req.coord.lon = coord.lon
req.coord.lat = coord.lat
return pt_planner.send_and_receive(req, request_id=request_id).stop_points
8 changes: 5 additions & 3 deletions source/jormungandr/jormungandr/pt_planners/kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
# www.navitia.io
from __future__ import absolute_import, print_function, unicode_literals, division

from jormungandr.pt_planners.common import ZmqSocket, get_crow_fly
from jormungandr.pt_planners.common import ZmqSocket, get_crow_fly, get_odt_stop_points
from jormungandr import utils, app
from .pt_planner import AbstractPtPlanner
from navitiacommon import type_pb2, request_pb2
import logging
from navitiacommon import type_pb2


class Kraken(ZmqSocket, AbstractPtPlanner):
Expand Down Expand Up @@ -87,3 +86,6 @@ def get_crow_fly(
allowed_id,
**kwargs
)

def get_odt_stop_points(self, coord, request_id):
return get_odt_stop_points(self, coord, request_id)
5 changes: 4 additions & 1 deletion source/jormungandr/jormungandr/pt_planners/loki.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# www.navitia.io
from __future__ import absolute_import, print_function, unicode_literals, division

from jormungandr.pt_planners.common import ZmqSocket, get_crow_fly
from jormungandr.pt_planners.common import ZmqSocket, get_crow_fly, get_odt_stop_points
from jormungandr import utils, app
from .pt_planner import AbstractPtPlanner
from navitiacommon import type_pb2
Expand Down Expand Up @@ -93,3 +93,6 @@ def get_crow_fly(
allowed_id,
**kwargs
)

def get_odt_stop_points(self, coord, request_id):
return get_odt_stop_points(self, coord, request_id)
3 changes: 3 additions & 0 deletions source/jormungandr/jormungandr/scenarios/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,14 @@ def _compute_journeys(
future_manager=future_manager,
instance=instance,
requested_place_obj=context.requested_orig_obj,
pt_planner_name=request['_pt_planner'],
request_id="{}_places_free_access_orig".format(request_id),
)
context.dest_places_free_access = PlacesFreeAccess(
future_manager=future_manager,
instance=instance,
requested_place_obj=context.requested_dest_obj,
pt_planner_name=request['_pt_planner'],
request_id="{}_places_free_access_dest".format(request_id),
)

Expand Down Expand Up @@ -376,6 +378,7 @@ def _compute_isochrone_common(
future_manager=future_manager,
instance=instance,
requested_place_obj=requested_obj,
pt_planner_name=request['_pt_planner'],
request_id=request_id,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PlacesFreeAccess:
stop_points that are accessible freely from a given place: odt, stop_points of a stop_area, etc.
"""

def __init__(self, future_manager, instance, requested_place_obj, request_id):
def __init__(self, future_manager, instance, requested_place_obj, pt_planner_name, request_id):
"""
:param instance: instance of the coverage, all outside services callings pass through it(street network,
Expand All @@ -55,6 +55,7 @@ def __init__(self, future_manager, instance, requested_place_obj, request_id):
self._request_id = request_id
self._async_request()
self._logger = logging.getLogger(__name__)
self._pt_planner = self._instance.get_pt_planner(pt_planner_name)

@new_relic.distributedEvent("get_stop_points_for_stop_area", "places")
def _get_stop_points_for_stop_area(self, uri):
Expand All @@ -64,7 +65,7 @@ def _get_stop_points_for_stop_area(self, uri):
@new_relic.distributedEvent("get_odt_stop_points", "places")
def _get_odt_stop_points(self, coord):
with timed_logger(self._logger, 'odt_stop_points_calling_external_service', self._request_id):
return self._instance.georef.get_odt_stop_points(coord, self._request_id)
return self._pt_planner.get_odt_stop_points(coord, self._request_id)

def _do_request(self):
self._logger.debug("requesting places with free access from %s", self._requested_place_obj.uri)
Expand All @@ -85,7 +86,7 @@ def _do_request(self):
odt = set()

if coord:
odt_sps = self._get_odt_stop_points(self._instance.georef, coord)
odt_sps = self._get_odt_stop_points(self._pt_planner, coord)
[odt.add(stop_point.uri) for stop_point in odt_sps]

self._logger.debug("finish places with free access from %s", self._requested_place_obj.uri)
Expand Down

0 comments on commit 74b0b1d

Please sign in to comment.