Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix max_nb_journeys with best_olympics when aggregating #4242

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions source/jormungandr/jormungandr/scenarios/new_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ def get_crowfly_air_pollutants(origin, destination):

def aggregate_journeys(journeys):
"""
when building candidates_pool, we should take into count the similarity of journeys, which means, we add a journey
when building candidates_pool, we should take into account the similarity of journeys, which means, we add a journey
into the pool only when there are no other "similar" journey already existing in the pool.

the similarity is defined by a tuple of journeys sections.
Expand All @@ -1130,20 +1130,29 @@ def aggregate_journeys(journeys):
aggregated_journeys = list()
remaining_journeys = list()

def to_retain(j):
return j.type in JOURNEY_TYPES_TO_RETAIN or set(j.tags) & set(JOURNEY_TAGS_TO_RETAIN)

journeys_to_retain = (j for j in journeys if to_retain(j))
journeys_not_to_retain = (j for j in journeys if not to_retain(j))

# we pick out all journeys that must be kept:
for j in (j for j in journeys if j.type in JOURNEY_TYPES_TO_RETAIN):
for j in journeys_to_retain:
section_id = tuple(_get_section_id(s) for s in j.sections if s.type in SECTION_TYPES_TO_RETAIN)
aggregated_journeys.append(j)
added_sections_ids.add(section_id)

for j in (j for j in journeys if j.type not in JOURNEY_TYPES_TO_RETAIN):
for j in journeys_not_to_retain:
section_id = tuple(_get_section_id(s) for s in j.sections if s.type in SECTION_TYPES_TO_RETAIN)

if section_id in added_sections_ids:
remaining_journeys.append(j)
else:
aggregated_journeys.append(j)
added_sections_ids.add(section_id)

# aggregated_journeys will be passed to culling algorithm,
# remaining_journeys are the redundant ones to be removed
return aggregated_journeys, remaining_journeys


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,26 @@ def aggregate_journeys_test():
assert len(aggregated_journeys) == 17
assert len(remaining_journeys) == 2

journeys_uris = {(tuple(s.uris.line for s in j.sections), j.arrival_date_time) for j in aggregated_journeys}
# J19 is dominated by J3, because it arrives later than J3
# J3 should be found in final result
assert ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905600) in journeys_uris
# J3 should NOT be found in final result
assert ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905720) not in journeys_uris

mocked_pb_response = build_mocked_response()
mocked_pb_response.journeys[18].tags.append("best_olympics")

aggregated_journeys, remaining_journeys = new_default.aggregate_journeys(mocked_pb_response.journeys)
assert len(aggregated_journeys) == 17
assert len(remaining_journeys) == 2
journeys_uris = {(tuple(s.uris.line for s in j.sections), j.arrival_date_time) for j in aggregated_journeys}
# J19 is dominated by J3, BUT it has joker because it has been tagged "best_olympics"
# J3 should be NOT found in final result
assert ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905600) not in journeys_uris
# J3 should be found in final result
assert ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905720) in journeys_uris


def merge_responses_on_errors_test():
"""
Expand Down
Loading