Skip to content

Commit

Permalink
Add filter since and until for journeys
Browse files Browse the repository at this point in the history
  • Loading branch information
kadhikari committed Aug 1, 2024
1 parent 1f218a7 commit 4a310da
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class AddressSerializer(PbGenericSerializer):

class PoiSerializer(PbGenericSerializer):
coord = CoordSerializer(required=False)
links = DisruptionLinkSerializer(attr='impact_uris', display_none=True)
links = DisruptionLinkSerializer(attr='impact_uris', display_none=False)
label = jsonschema.Field(schema_type=str)
administrative_regions = AdminSerializer(many=True, display_none=False)
poi_type = PoiTypeSerializer(display_none=False)
Expand Down
7 changes: 6 additions & 1 deletion source/jormungandr/jormungandr/scenarios/new_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
from six.moves import range
from six.moves import zip
from functools import cmp_to_key
from datetime import datetime

SECTION_TYPES_TO_RETAIN = {response_pb2.PUBLIC_TRANSPORT, response_pb2.STREET_NETWORK}
JOURNEY_TAGS_TO_RETAIN = ['best_olympics']
Expand Down Expand Up @@ -504,16 +505,20 @@ def update_disruptions_on_pois(instance, pb_resp):
return
# Add uri of all the pois in a set
poi_uris = set()
since_datetime = date_to_timestamp(datetime.utcnow())
until_datetime = date_to_timestamp(datetime.utcnow())
for j in pb_resp.journeys:
for s in j.sections:
if s.origin.embedded_type == type_pb2.POI:
poi_uris.add(s.origin.uri)
since_datetime = min(since_datetime, s.begin_date_time)

if s.destination.embedded_type == type_pb2.POI:
poi_uris.add(s.destination.uri)
until_datetime = max(until_datetime, s.end_date_time)

# Get disruptions for poi_uris calling loki with api poi_disruptions and poi_uris in param
poi_disruptions = get_disruptions_on_poi(instance, poi_uris)
poi_disruptions = get_disruptions_on_poi(instance, poi_uris, since_datetime, until_datetime)
if poi_disruptions is None:
return

Expand Down
7 changes: 5 additions & 2 deletions source/jormungandr/jormungandr/scenarios/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,19 @@ def fill_disruptions_on_places_nearby(instance, response):
add_disruptions(response, resp_poi)


def get_disruptions_on_poi(instance, uris):
def get_disruptions_on_poi(instance, uris, since_datetime=None, until_datetime=None):
if not uris:
return None
try:
pt_planner = instance.get_pt_planner("loki")
req = request_pb2.Request()
req.requested_api = type_pb2.poi_disruptions

# add all poi_ids as parameters
req.poi_disruptions.pois.extend(uris)
if since_datetime:
req.poi_disruptions.since_datetime = since_datetime
if until_datetime:
req.poi_disruptions.until_datetime = until_datetime

# calling loki with api api_disruptions
resp_poi = pt_planner.send_and_receive(req)
Expand Down
2 changes: 1 addition & 1 deletion source/navitia-proto
Submodule navitia-proto updated 1 files
+3 −1 request.proto

0 comments on commit 4a310da

Please sign in to comment.