Skip to content

Commit

Permalink
Merge pull request #4320 from hove-io/penality_parking_bike
Browse files Browse the repository at this point in the history
[NAV-3444] add penality bike parking
  • Loading branch information
azime authored Dec 3, 2024
2 parents d389810 + 49a0db8 commit c730ce2
Show file tree
Hide file tree
Showing 22 changed files with 476 additions and 37 deletions.
2 changes: 2 additions & 0 deletions source/jormungandr/jormungandr/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,8 @@ def additional_parameters(self):
additional_time_after_first_section_taxi = _make_property_getter('additional_time_after_first_section_taxi')
additional_time_before_last_section_taxi = _make_property_getter('additional_time_before_last_section_taxi')

on_street_bike_parking_duration = _make_property_getter('on_street_bike_parking_duration')

max_walking_direct_path_duration = _make_property_getter('max_walking_direct_path_duration')
max_bike_direct_path_duration = _make_property_getter('max_bike_direct_path_duration')
max_bss_direct_path_duration = _make_property_getter('max_bss_direct_path_duration')
Expand Down
3 changes: 3 additions & 0 deletions source/jormungandr/jormungandr/interfaces/v1/Journeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ def _set_specific_params(mod):
if args.get('additional_time_before_last_section_taxi') is None:
args['additional_time_before_last_section_taxi'] = mod.additional_time_before_last_section_taxi

if args.get("on_street_bike_parking_duration") is None:
args["on_street_bike_parking_duration"] = mod.on_street_bike_parking_duration

if args.get('_stop_points_nearby_duration') is None:
args['_stop_points_nearby_duration'] = mod.stop_points_nearby_duration

Expand Down
23 changes: 22 additions & 1 deletion source/jormungandr/jormungandr/interfaces/v1/journey_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# www.navitia.io

from __future__ import absolute_import, print_function, unicode_literals, division
from jormungandr import i_manager, fallback_modes, partner_services, app
from jormungandr import i_manager, fallback_modes, park_modes, partner_services, app
from jormungandr.interfaces.v1.ResourceUri import ResourceUri
from datetime import datetime
from jormungandr.resources_utils import ResourceUtc
Expand Down Expand Up @@ -239,6 +239,20 @@ def __init__(self, output_type_serializer):
action="append",
help='Same as first_section_mode but for the last section.',
)

parser_get.add_argument(
"park_mode[]",
type=OptionValue(park_modes.all_park_modes),
dest="park_mode",
action="append",
help='Force the park mode for the first or last section of a journey\n'
'Need to be set with one of the first_section_mode[] or last_section_mode[] corresponding to vehicles that could be parked\n'
'Note: Only work with the first or last section mode being a bike for the moment\n'
'Eg: If you want to park a bike at the departure, you need:\n'
'`first_section_mode[]=bike&park_mode[]=on_street`'
'Eg: If you want to park a bike at the arrival, you need:\n'
'`last_section_mode[]=bike&park_mode[]=on_street`',
)
# for retrocompatibility purpose, we duplicate (without []):
parser_get.add_argument(
"first_section_mode",
Expand Down Expand Up @@ -506,6 +520,13 @@ def __init__(self, output_type_serializer):
type=int,
help="the additional time added to the taxi section, right before riding the taxi but after hopping off the public transit",
)

parser_get.add_argument(
"on_street_bike_parking_duration",
type=int,
help="the additional time added to the bike section before and after parking the bike",
)

parser_get.add_argument(
"_pt_planner",
type=OptionValue(['kraken', 'loki']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class ParametersSerializer(serpy.Serializer):
max_extra_second_pass = Field(schema_type=int)
additional_time_after_first_section_taxi = Field(schema_type=int)
additional_time_before_last_section_taxi = Field(schema_type=int)
on_street_bike_parking_duration = Field(schema_type=int)
max_walking_direct_path_duration = Field(schema_type=int)
max_bike_direct_path_duration = Field(schema_type=int)
max_bss_direct_path_duration = Field(schema_type=int)
Expand Down
48 changes: 48 additions & 0 deletions source/jormungandr/jormungandr/park_modes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright (c) 2001-2024, Hove and/or its affiliates. All rights reserved.
#
# This file is part of Navitia,
# the software to build cool stuff with public transport.
#
# Hope you'll enjoy and contribute to this project,
# powered by Hove (www.hove.com).
# Help us simplify mobility and open public transport:
# a non ending quest to the responsive locomotion way of traveling!
#
# LICENCE: This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Stay tuned using
# twitter @navitia
# channel `#navitia` on riot https://riot.im/app/#/room/#navitia:matrix.org
# https://groups.google.com/d/forum/navitia
# www.navitia.io
#
#


from enum import Enum
from navitiacommon import request_pb2


class ParkMode(Enum):
none = request_pb2.NONE
on_street = request_pb2.OnStreet
park_and_ride = request_pb2.ParkAndRide

@classmethod
def modes_str(cls):

return {e.name for e in cls}


all_park_modes = ParkMode.modes_str()
8 changes: 7 additions & 1 deletion source/jormungandr/jormungandr/scenarios/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from jormungandr.new_relic import record_custom_parameter
from navitiacommon import response_pb2, type_pb2
from flask_restful import abort
from .helper_classes.helper_utils import timed_logger
from .helper_classes.timer_logger_helper import timed_logger
from .helper_classes.helper_exceptions import (
NoGraphicalIsochroneFoundException,
PtException,
Expand Down Expand Up @@ -355,6 +355,9 @@ def finalise_journeys(self, future_manager, request, responses, context, instanc
request=request,
journeys=journeys_to_complete,
request_id="{}_complete_pt_journey".format(request_id),
instance=instance,
future_manager=future_manager,
_request_id=request_id,
)
if request['_loki_compute_pt_journey_fare'] is True and request['_pt_planner'] == "loki":
wait_and_complete_pt_journey_fare(
Expand Down Expand Up @@ -589,6 +592,9 @@ def graphical_isochrones(self, request, instance):
'additional_time_before_last_section_taxi'
] = instance.additional_time_after_first_section_taxi

if request.get('on_street_bike_parking_duration') is None:
request['on_street_bike_parking_duration'] = instance.on_street_bike_parking_duration

krakens_call = set({(request["origin_mode"][0], request["destination_mode"][0], "indifferent")})
pt_object_origin = None
pt_object_destination = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
complete_pt_journey,
compute_fallback,
_build_crowflies,
timed_logger,
complete_transfer,
)
from .timer_logger_helper import timed_logger
from .helper_exceptions import InvalidDateBoundException
from jormungandr.street_network.street_network import StreetNetworkPathType
from collections import namedtuple
Expand Down Expand Up @@ -166,6 +166,7 @@ def wait_and_complete_pt_journey(
request,
journeys,
request_id,
**kwargs
):
"""
In this function, we compute all fallback path once the pt journey is finished, then we build the
Expand Down Expand Up @@ -206,6 +207,7 @@ def wait_and_complete_pt_journey(
orig_fallback_durations_pool=orig_fallback_durations_pool,
dest_fallback_durations_pool=dest_fallback_durations_pool,
request=request,
**kwargs
)
if {pt_element.dep_mode, pt_element.arr_mode} & {'car', 'car_no_park'}:
tag_LEZ(pt_element.pt_journeys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from jormungandr import new_relic, excluded_zones_manager
from jormungandr.fallback_modes import FallbackModes
import logging
from .helper_utils import timed_logger
from .timer_logger_helper import timed_logger
import six
from navitiacommon import type_pb2
from jormungandr.exceptions import GeoveloTechnicalError
Expand Down
Loading

0 comments on commit c730ce2

Please sign in to comment.