|
101 | 101 | from functools import cmp_to_key
|
102 | 102 |
|
103 | 103 | SECTION_TYPES_TO_RETAIN = {response_pb2.PUBLIC_TRANSPORT, response_pb2.STREET_NETWORK}
|
| 104 | +JOURNEY_TAGS_TO_RETAIN = ['best_olympics'] |
104 | 105 | JOURNEY_TYPES_TO_RETAIN = ['best', 'comfort', 'non_pt_walk', 'non_pt_bike', 'non_pt_bss']
|
| 106 | +JOURNEY_TYPES_SCORE = {t: i for i, t in enumerate(JOURNEY_TYPES_TO_RETAIN)} |
105 | 107 | STREET_NETWORK_MODE_TO_RETAIN = {response_pb2.Ridesharing, response_pb2.Car, response_pb2.Bike, response_pb2.Bss}
|
106 | 108 | TEMPLATE_MSG_UNKNOWN_OBJECT = "The entry point: {} is not valid"
|
107 | 109 |
|
@@ -515,7 +517,7 @@ def _build_candidate_pool_and_sections_set(journeys):
|
515 | 517 | idx_of_jrny_must_keep = list()
|
516 | 518 |
|
517 | 519 | for (i, jrny) in enumerate(journeys):
|
518 |
| - if jrny.type in JOURNEY_TYPES_TO_RETAIN: |
| 520 | + if set(jrny.tags) & set(JOURNEY_TAGS_TO_RETAIN) or jrny.type in set(JOURNEY_TYPES_TO_RETAIN): |
519 | 521 | idx_of_jrny_must_keep.append(i)
|
520 | 522 | sections_set |= set([_get_section_id(s) for s in jrny.sections if s.type in SECTION_TYPES_TO_RETAIN])
|
521 | 523 | candidates_pool.append(jrny)
|
@@ -750,16 +752,16 @@ def _inverse_selection(d, indexes):
|
750 | 752 | )
|
751 | 753 |
|
752 | 754 | # At this point, resp.journeys should contain only must-have journeys
|
753 |
| - list_dict = collections.defaultdict(list) |
754 |
| - for jrny in resp.journeys: |
755 |
| - if not journey_filter.to_be_deleted(jrny): |
756 |
| - list_dict[jrny.type].append(jrny) |
| 755 | + must_have = [j for j in resp.journeys if not journey_filter.to_be_deleted(j)] |
757 | 756 |
|
758 |
| - sorted_by_type_journeys = [] |
759 |
| - for t in JOURNEY_TYPES_TO_RETAIN: |
760 |
| - sorted_by_type_journeys.extend(list_dict.get(t, [])) |
| 757 | + def journey_score(j): |
| 758 | + if set(j.tags) & set(JOURNEY_TAGS_TO_RETAIN): |
| 759 | + return -100 |
| 760 | + return JOURNEY_TYPES_SCORE.get(j.type, float('inf')) |
761 | 761 |
|
762 |
| - for jrny in sorted_by_type_journeys[max_nb_journeys:]: |
| 762 | + must_have.sort(key=journey_score) |
| 763 | + |
| 764 | + for jrny in must_have[max_nb_journeys:]: |
763 | 765 | journey_filter.mark_as_dead(jrny, is_debug, 'Filtered by max_nb_journeys')
|
764 | 766 |
|
765 | 767 | journey_filter.delete_journeys((resp,), request)
|
|
0 commit comments