Skip to content

Commit 167f0ea

Browse files
authored
Merge pull request #4313 from hove-io/add_use_predicted_traffic
[Jormun+Asgard ] add use_predicted_traffic
2 parents 6b42cbe + ceb66da commit 167f0ea

File tree

10 files changed

+54
-3
lines changed

10 files changed

+54
-3
lines changed

source/jormungandr/jormungandr/instance.py

+2
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,8 @@ def additional_parameters(self):
859859
co2_emission_car_value = _make_property_getter('co2_emission_car_value')
860860
co2_emission_car_unit = _make_property_getter('co2_emission_car_unit')
861861

862+
use_predicted_traffic = _make_property_getter('use_predicted_traffic')
863+
862864
def get_pt_planner(self, pt_planner_id=None):
863865
pt_planner_id = pt_planner_id or self.default_pt_planner
864866
return self._pt_planner_manager.get_pt_planner(pt_planner_id)

source/jormungandr/jormungandr/interfaces/v1/Journeys.py

+3
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,9 @@ def _set_specific_params(mod):
883883
if args.get('_loki_compute_pt_journey_fare') is None:
884884
args['_loki_compute_pt_journey_fare'] = mod.loki_compute_pt_journey_fare
885885

886+
if args.get('_use_predicted_traffic') is None:
887+
args['_use_predicted_traffic'] = mod.use_predicted_traffic
888+
886889
# When computing 'same_journey_schedules'(is_journey_schedules=True), some parameters need to be overridden
887890
# because they are contradictory to the request
888891
if args.get("is_journey_schedules"):

source/jormungandr/jormungandr/interfaces/v1/journey_common.py

+6
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,12 @@ def __init__(self, output_type_serializer):
848848
hidden=True,
849849
help="whether or not to use heuristic to optimized path searching in loki, used in loki exclusively",
850850
)
851+
parser_get.add_argument(
852+
"_use_predicted_traffic",
853+
type=BooleanType(),
854+
hidden=True,
855+
help="whether or not to use predicted/historical traffic data for routing, it affects only car/car_no_park mode in Asgard",
856+
)
851857

852858
def parse_args(self, region=None, uri=None):
853859
args = self.parsers['get'].parse_args()

source/jormungandr/jormungandr/parking_space_availability/abstract_parking_places_provider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _init_boundary_shape(self, boundary_geometry):
5858
self.boundary_shape = boundary_shape
5959
except Exception as e:
6060
self.log.error('Error while loading boundary shape : {}'.format(e))
61-
self.log.error("Unable to parse geometry object : ", boundary_geometry)
61+
self.log.error("Unable to parse geometry object : {}".format(boundary_geometry))
6262

6363
def has_boundary_shape(self): # type () : bool
6464
return hasattr(self, 'boundary_shape') and self.boundary_shape != None

source/jormungandr/jormungandr/street_network/asgard.py

+2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def _create_sn_routing_matrix_request(
199199

200200
req.sn_routing_matrix.datetime = request["datetime"]
201201
req.sn_routing_matrix.use_excluded_zones = request["_use_excluded_zones"]
202+
req.sn_routing_matrix.use_predicted_traffic = request["_use_predicted_traffic"]
202203

203204
# Asgard/Valhalla walking
204205
req.sn_routing_matrix.streetnetwork_params.walking_destination_only_penalty = request[
@@ -368,6 +369,7 @@ def _create_direct_path_request(
368369
req.direct_path.datetime = fallback_extremity.datetime
369370
req.direct_path.clockwise = fallback_extremity.represents_start
370371
req.direct_path.use_excluded_zones = request["_use_excluded_zones"]
372+
req.direct_path.use_predicted_traffic = request["_use_predicted_traffic"]
371373
profiles = [
372374
DirectPathProfile(
373375
bike_use_roads=request['bike_use_roads'],

source/jormungandr/requirements_dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ requests-mock==1.0.0
1717
flex==6.10.0
1818
jsonschema==2.6.0
1919
pytest-timeout==1.3.3
20-
#pytest-asyncio==0.20.0 ; python_version >= "3.9"
20+

source/navitia-proto

source/navitiacommon/navitiacommon/default_values.py

+2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@
254254
co2_emission_car_value = 184.0 # gEC by Km
255255
co2_emission_car_unit = 'gEC'
256256

257+
use_predicted_traffic = False
258+
257259

258260
def get_value_or_default(attr, instance, instance_name):
259261
if not instance or getattr(instance, attr, None) == None:

source/navitiacommon/navitiacommon/models/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,13 @@ class Instance(db.Model): # type: ignore
771771
server_default=str(default_values.co2_emission_car_unit),
772772
)
773773

774+
use_predicted_traffic = db.Column(
775+
db.Boolean,
776+
default=default_values.use_predicted_traffic,
777+
nullable=True,
778+
server_default=false(),
779+
)
780+
774781
def __init__(self, name=None, is_free=False, authorizations=None, jobs=None):
775782
self.name = name
776783
self.is_free = is_free
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""add use_predicted_traffic
2+
3+
Revision ID: fd13bb348665
4+
Revises: d7ff7aea17d9
5+
Create Date: 2024-10-10 15:14:54.523574
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = 'fd13bb348665'
11+
down_revision = 'd7ff7aea17d9'
12+
13+
from alembic import op
14+
import sqlalchemy as sa
15+
from sqlalchemy.dialects import postgresql
16+
17+
18+
def upgrade():
19+
# ### commands auto generated by Alembic - please adjust! ###
20+
op.add_column(
21+
'instance', sa.Column('use_predicted_traffic', sa.Boolean(), server_default='False', nullable=True)
22+
)
23+
# ### end Alembic commands ###
24+
25+
26+
def downgrade():
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
op.drop_column('instance', 'use_predicted_traffic')
29+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)