Skip to content

Commit

Permalink
Merge pull request #4308 from hove-io/fix_all_comparison_with_pt
Browse files Browse the repository at this point in the history
[jormun]: Add ODT in all PT conditions
  • Loading branch information
kadhikari authored Oct 1, 2024
2 parents ab1be21 + 893c30e commit 8a41c97
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def to_value(self, value):
coords.append(get_pt_object_coord(value.destination))
elif value.type == response_pb2.RIDESHARING and len(value.shape) != 0:
coords = value.shape
elif value.type == response_pb2.PUBLIC_TRANSPORT:
elif value.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT):
coords = value.shape
elif value.type == response_pb2.TRANSFER:
if value.street_network and value.street_network.coordinates:
Expand Down
6 changes: 5 additions & 1 deletion source/jormungandr/jormungandr/pt_journey_fare/kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ def __init__(self, instance):

@staticmethod
def _pt_sections(journey):
return [s for s in journey.sections if s.type == response_pb2.PUBLIC_TRANSPORT]
return [
s
for s in journey.sections
if s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT)
]

def create_fare_request(self, pt_journeys):
request = request_pb2.Request()
Expand Down
19 changes: 13 additions & 6 deletions source/jormungandr/jormungandr/scenarios/journey_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ def filter_func(self, journey):
"""
bus_count = 0
for s in journey.sections:
if s.type != response_pb2.PUBLIC_TRANSPORT:
# if s.type != response_pb2.PUBLIC_TRANSPORT:
if s.type not in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT):
continue
if s.pt_display_informations.uris.physical_mode == self.successive_physical_mode_to_limit_id:
bus_count += 1
Expand Down Expand Up @@ -489,7 +490,7 @@ def _similar_non_pt():

def _similar_pt():
for idx, s in enumerate(journey.sections):
if s.type == response_pb2.PUBLIC_TRANSPORT:
if s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT):
yield pt_functor(s)
elif s.type == response_pb2.STREET_NETWORK and is_walk_after_parking(journey, idx):
continue
Expand Down Expand Up @@ -552,7 +553,7 @@ def shared_section_generator(journey):

# Compare each section of the journey with the criteria in the function description
for s in journey.sections:
if s.type == response_pb2.PUBLIC_TRANSPORT:
if s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT):
yield "origin:{}/dest:{}".format(s.origin.uri, s.destination.uri)


Expand Down Expand Up @@ -604,7 +605,7 @@ def shorten(name):

sections = []
for s in journey.sections:
if s.type == response_pb2.PUBLIC_TRANSPORT:
if s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT):
sections.append(
u"{line} ({vj})".format(
line=s.pt_display_informations.uris.line, vj=s.pt_display_informations.uris.vehicle_journey
Expand Down Expand Up @@ -816,7 +817,10 @@ def get_journey_extremity_pt_section(journey, attractivities_virtual_fallbacks):
sections = reversed(journey.sections)
else:
sections = journey.sections
extremity_pt_section = next((s for s in sections if s.type == response_pb2.PUBLIC_TRANSPORT), None)
extremity_pt_section = next(
(s for s in sections if s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT)),
None,
)

return extremity_pt_section

Expand Down Expand Up @@ -1155,7 +1159,10 @@ def _filter_odt_journeys_counter_clockwise(journeys, debug):


def _contains_pt_section(journey):
return any(section.type == response_pb2.PUBLIC_TRANSPORT for section in journey.sections)
return any(
section.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT)
for section in journey.sections
)


def _contains_odt(journey):
Expand Down
18 changes: 12 additions & 6 deletions source/jormungandr/jormungandr/scenarios/new_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@
from functools import cmp_to_key
from datetime import datetime

SECTION_TYPES_TO_RETAIN = {response_pb2.PUBLIC_TRANSPORT, response_pb2.STREET_NETWORK}
SECTION_TYPES_TO_RETAIN = {
response_pb2.PUBLIC_TRANSPORT,
response_pb2.ON_DEMAND_TRANSPORT,
response_pb2.STREET_NETWORK,
}
JOURNEY_TAGS_TO_RETAIN = ['best_olympics']
JOURNEY_TYPES_TO_RETAIN = ['best', 'comfort', 'non_pt_walk', 'non_pt_bike', 'non_pt_bss']
JOURNEY_TYPES_SCORE = {t: i for i, t in enumerate(JOURNEY_TYPES_TO_RETAIN)}
Expand Down Expand Up @@ -273,7 +277,7 @@ def create_pb_request(requested_type, request, dep_mode, arr_mode, direct_path_t


def _has_pt(j):
return any(s.type == response_pb2.PUBLIC_TRANSPORT for s in j.sections)
return any(s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT) for s in j.sections)


def sort_journeys(resp, journey_order, clockwise):
Expand Down Expand Up @@ -362,7 +366,7 @@ def update_best_boarding_positions(pb_resp, instance):
prev_iter = iter(j.sections)
current_iter = itertools.islice(j.sections, 1, None)
for prev, curr in zip(prev_iter, current_iter):
if prev.type != response_pb2.PUBLIC_TRANSPORT:
if prev.type not in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT):
continue
boarding_positions = get_best_boarding_positions(curr, instance)
helpers.fill_best_boarding_position(prev, boarding_positions)
Expand Down Expand Up @@ -423,7 +427,9 @@ def _tag_direct_path(responses):
}

for j in itertools.chain.from_iterable(r.journeys for r in responses if r is not None):
if all(s.type != response_pb2.PUBLIC_TRANSPORT for s in j.sections):
if all(
s.type not in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT) for s in j.sections
):
j.tags.extend(['non_pt'])

# TODO: remove that (and street_network_mode_tag_map) when NMP stops using it
Expand All @@ -444,7 +450,7 @@ def _is_bike_section(s):
def _is_pt_bike_accepted_section(s):
bike_ok = type_pb2.hasEquipments.has_bike_accepted
return (
s.type == response_pb2.PUBLIC_TRANSPORT
s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT)
and bike_ok in s.pt_display_informations.has_equipments.has_equipments
and bike_ok in s.origin.stop_point.has_equipments.has_equipments
and bike_ok in s.destination.stop_point.has_equipments.has_equipments
Expand Down Expand Up @@ -972,7 +978,7 @@ def is_reliable_journey(journey):
if mode not in reliable_fallback_modes:
return False

if section.type != response_pb2.PUBLIC_TRANSPORT:
if section.type not in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT):
continue
if not section.HasField("uris"):
continue
Expand Down
6 changes: 5 additions & 1 deletion source/jormungandr/jormungandr/scenarios/qualifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def get_fallback_duration(journey):
for section in sections:
if section.type not in (
response_pb2.PUBLIC_TRANSPORT,
response_pb2.ON_DEMAND_TRANSPORT,
response_pb2.WAITING,
response_pb2.boarding,
response_pb2.landing,
Expand Down Expand Up @@ -103,7 +104,10 @@ def has_no_bss(journey):

def non_pt_journey(journey):
"""check if the journey has not public transport section"""
has_pt = all(section.type != response_pb2.PUBLIC_TRANSPORT for section in journey.sections)
has_pt = all(
section.type not in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT)
for section in journey.sections
)
return has_pt


Expand Down
2 changes: 1 addition & 1 deletion source/jormungandr/jormungandr/scenarios/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def sort_by_duration_and_transfert(self, j1, j2):
for journey in [j1, j2]:
non_pt_duration = 0
for section in journey.sections:
if section.type != response_pb2.PUBLIC_TRANSPORT:
if section.type not in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT):
non_pt_duration += section.duration
if non_pt_duration_j1 is None:
non_pt_duration_j1 = non_pt_duration
Expand Down
18 changes: 16 additions & 2 deletions source/jormungandr/jormungandr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,25 @@ def is_olympic_site(entry_point, instance):


def get_last_pt_section(journey):
return next((s for s in reversed(journey.sections) if s.type == response_pb2.PUBLIC_TRANSPORT), None)
return next(
(
s
for s in reversed(journey.sections)
if s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT)
),
None,
)


def get_first_pt_section(journey):
return next((s for s in journey.sections if s.type == response_pb2.PUBLIC_TRANSPORT), None)
return next(
(
s
for s in journey.sections
if s.type in (response_pb2.PUBLIC_TRANSPORT, response_pb2.ON_DEMAND_TRANSPORT)
),
None,
)


def record_external_failure(message, connector_type, connector_name):
Expand Down

0 comments on commit 8a41c97

Please sign in to comment.