Skip to content

Commit

Permalink
Merge pull request #4224 from hove-io/nav_2793
Browse files Browse the repository at this point in the history
Fix opg network
  • Loading branch information
azime authored Feb 23, 2024
2 parents d5cce15 + 5b3c04d commit 49d02cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
13 changes: 8 additions & 5 deletions source/jormungandr/jormungandr/olympic_site_params_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ def fill_olympic_site_params_from_s3(self):
instance_name=self.instance.name, bucket_name=self.bucket_name, folder=self.folder, **self.args
)

def manage_navette(self, api_request):
# Add forbidden_uri
if self.instance.olympics_forbidden_uris and self.instance.olympics_forbidden_uris:
self.manage_forbidden_uris(
api_request, self.instance.olympics_forbidden_uris.pt_object_olympics_forbidden_uris
)

def build(self, pt_object_origin, pt_object_destination, api_request):
# Warning, the order of functions is important
# Order 1 : get_olympic_site_params
Expand Down Expand Up @@ -251,11 +258,6 @@ def build_api_request(self, api_request):
else:
api_request[key] = value

# Add forbidden_uri
self.manage_forbidden_uris(
api_request, self.instance.olympics_forbidden_uris.pt_object_olympics_forbidden_uris
)

# Add criteria
if api_request.get("criteria") in ["departure_stop_attractivity", "arrival_stop_attractivity"]:
return
Expand Down Expand Up @@ -285,6 +287,7 @@ def get_olympic_site_params(self, pt_origin_detail, pt_destination_detail, api_r
destination_olympic_site = self.get_olympic_site(pt_destination_detail)

if not origin_olympic_site and not destination_olympic_site:
self.manage_navette(api_request)
return {}

self.fill_olympic_site_params_from_s3()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def test_build_departure_and_arrival_poi_jo():
assert api_request.get("max_walking_duration_to_pt") == 12000
assert api_request.get('night_bus_filter_max_factor') == 2
assert api_request.get('night_bus_filter_base_factor') == 1800
assert len(api_request.get('forbidden_uris[]')) == 2
assert len(api_request.get('forbidden_uris[]')) == 1
olympic_site_params = api_request["olympic_site_params"]
assert not olympic_site_params['show_natural_opg_journeys']
assert olympic_site_params["strict"]
Expand Down Expand Up @@ -568,6 +568,7 @@ def test_build_departure_and_arrival_poi_jo_empty_olympic_site_params():
api_request["datetime"] = osp.get_timestamp('20230715T110000')
osp.build(pt_origin_detail, pt_destination_detail, api_request)
assert not api_request["olympic_site_params"]
assert "forbidden_uris[]" not in api_request


def test_build_departure_and_arrival_poi_jo_add_forbidden_uris():
Expand All @@ -593,7 +594,7 @@ def test_build_departure_and_arrival_poi_jo_add_forbidden_uris():
api_request["datetime"] = osp.get_timestamp('20230715T110000')
osp.build(pt_origin_detail, pt_destination_detail, api_request)
assert api_request["olympic_site_params"]
assert len(api_request["forbidden_uris[]"]) == 4
assert len(api_request["forbidden_uris[]"]) == 3
assert not api_request["olympic_site_params"]['show_natural_opg_journeys']


Expand Down Expand Up @@ -621,7 +622,7 @@ def test_get_dict_scenario_invalid_scanario_name():
osp.build(pt_origin_detail, pt_destination_detail, api_request)
assert api_request["olympic_site_params"]
assert not api_request["olympic_site_params"]['show_natural_opg_journeys']
assert len(api_request["forbidden_uris[]"]) == 2
assert len(api_request["forbidden_uris[]"]) == 1
scenario_name = osp.get_valid_scenario_name(
osp.olympic_site_params["poi:BCD"]["events"], "departure_scenario", osp.get_timestamp('20230720T110000')
)
Expand Down
24 changes: 12 additions & 12 deletions source/jormungandr/tests/olympic_sites_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,18 @@ def test_address_with_invalid_within_to_address_journeys(self):
template_journey_query.format(place_from=from_addr_uri, place_to=to_addr_uri)
)
journeys = [journey for journey in response['journeys']]
assert len(journeys) == 2
assert len(journeys) == 1
first_journey = response['journeys'][0]
assert len(first_journey["sections"]) == 3
assert len(first_journey["sections"]) == 1
physical_mode_id = next(
(
link["id"]
for link in first_journey["sections"][1]["links"]
for link in first_journey["sections"][0]["links"]
if link["type"] == 'physical_mode'
),
None,
)
assert physical_mode_id
assert not physical_mode_id

def test_address_to_address_journeys(self):
# forbidden_uris not used : physical_mode:0x0
Expand Down Expand Up @@ -451,18 +451,18 @@ def test_address_to_address_journeys(self):
template_journey_query.format(place_from=from_addr_uri, place_to=to_addr_uri)
)
journeys = [journey for journey in response['journeys']]
assert len(journeys) == 2
assert len(journeys) == 1
first_journey = response['journeys'][0]
assert len(first_journey["sections"]) == 3
assert len(first_journey["sections"]) == 1
physical_mode_id = next(
(
link["id"]
for link in first_journey["sections"][1]["links"]
for link in first_journey["sections"][0]["links"]
if link["type"] == 'physical_mode'
),
None,
)
assert physical_mode_id
assert not physical_mode_id

def test_address_to_olympic_poi_journeys(self):
# forbidden_uris used : physical_mode:0x0
Expand Down Expand Up @@ -512,18 +512,18 @@ def test_address_to_not_olympic_poi_journeys(self):
template_journey_query.format(place_from=from_addr_uri, place_to=to_poi_uri)
)
journeys = [journey for journey in response['journeys']]
assert len(journeys) == 2
assert len(journeys) == 1
first_journey = response['journeys'][0]
assert len(first_journey["sections"]) == 3
assert len(first_journey["sections"]) == 1
physical_mode_id = next(
(
link["id"]
for link in first_journey["sections"][1]["links"]
for link in first_journey["sections"][0]["links"]
if link["type"] == 'physical_mode'
),
None,
)
assert physical_mode_id
assert not physical_mode_id

def test_olympic_poi_to_address_journeys(self):
# forbidden_uris used : physical_mode:0x0
Expand Down

0 comments on commit 49d02cd

Please sign in to comment.