Skip to content

Commit 359c223

Browse files
authored
Merge pull request #4242 from hove-io/fix_max_nb_journeys_with_best_olympics_in_aggregation
fix max_nb_journeys with best_olympics when aggregating
2 parents 928ae02 + ec029b8 commit 359c223

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

source/jormungandr/jormungandr/scenarios/new_default.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ def get_crowfly_air_pollutants(origin, destination):
11211121

11221122
def aggregate_journeys(journeys):
11231123
"""
1124-
when building candidates_pool, we should take into count the similarity of journeys, which means, we add a journey
1124+
when building candidates_pool, we should take into account the similarity of journeys, which means, we add a journey
11251125
into the pool only when there are no other "similar" journey already existing in the pool.
11261126
11271127
the similarity is defined by a tuple of journeys sections.
@@ -1130,20 +1130,29 @@ def aggregate_journeys(journeys):
11301130
aggregated_journeys = list()
11311131
remaining_journeys = list()
11321132

1133+
def to_retain(j):
1134+
return j.type in JOURNEY_TYPES_TO_RETAIN or set(j.tags) & set(JOURNEY_TAGS_TO_RETAIN)
1135+
1136+
journeys_to_retain = (j for j in journeys if to_retain(j))
1137+
journeys_not_to_retain = (j for j in journeys if not to_retain(j))
1138+
11331139
# we pick out all journeys that must be kept:
1134-
for j in (j for j in journeys if j.type in JOURNEY_TYPES_TO_RETAIN):
1140+
for j in journeys_to_retain:
11351141
section_id = tuple(_get_section_id(s) for s in j.sections if s.type in SECTION_TYPES_TO_RETAIN)
11361142
aggregated_journeys.append(j)
11371143
added_sections_ids.add(section_id)
11381144

1139-
for j in (j for j in journeys if j.type not in JOURNEY_TYPES_TO_RETAIN):
1145+
for j in journeys_not_to_retain:
11401146
section_id = tuple(_get_section_id(s) for s in j.sections if s.type in SECTION_TYPES_TO_RETAIN)
11411147

11421148
if section_id in added_sections_ids:
11431149
remaining_journeys.append(j)
11441150
else:
11451151
aggregated_journeys.append(j)
11461152
added_sections_ids.add(section_id)
1153+
1154+
# aggregated_journeys will be passed to culling algorithm,
1155+
# remaining_journeys are the redundant ones to be removed
11471156
return aggregated_journeys, remaining_journeys
11481157

11491158

source/jormungandr/jormungandr/scenarios/tests/new_default_tests.py

+20
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,26 @@ def aggregate_journeys_test():
318318
assert len(aggregated_journeys) == 17
319319
assert len(remaining_journeys) == 2
320320

321+
journeys_uris = {(tuple(s.uris.line for s in j.sections), j.arrival_date_time) for j in aggregated_journeys}
322+
# J19 is dominated by J3, because it arrives later than J3
323+
# J3 should be found in final result
324+
assert ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905600) in journeys_uris
325+
# J3 should NOT be found in final result
326+
assert ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905720) not in journeys_uris
327+
328+
mocked_pb_response = build_mocked_response()
329+
mocked_pb_response.journeys[18].tags.append("best_olympics")
330+
331+
aggregated_journeys, remaining_journeys = new_default.aggregate_journeys(mocked_pb_response.journeys)
332+
assert len(aggregated_journeys) == 17
333+
assert len(remaining_journeys) == 2
334+
journeys_uris = {(tuple(s.uris.line for s in j.sections), j.arrival_date_time) for j in aggregated_journeys}
335+
# J19 is dominated by J3, BUT it has joker because it has been tagged "best_olympics"
336+
# J3 should be NOT found in final result
337+
assert ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905600) not in journeys_uris
338+
# J3 should be found in final result
339+
assert ((u'uri_2', u'uri_3', u'uri_4', u'walking'), 1444905720) in journeys_uris
340+
321341

322342
def merge_responses_on_errors_test():
323343
"""

0 commit comments

Comments
 (0)