Skip to content

Commit

Permalink
Merge pull request #4313 from hove-io/add_use_predicted_traffic
Browse files Browse the repository at this point in the history
[Jormun+Asgard ] add use_predicted_traffic
  • Loading branch information
xlqian authored Oct 18, 2024
2 parents 6b42cbe + ceb66da commit 167f0ea
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 3 deletions.
2 changes: 2 additions & 0 deletions source/jormungandr/jormungandr/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ def additional_parameters(self):
co2_emission_car_value = _make_property_getter('co2_emission_car_value')
co2_emission_car_unit = _make_property_getter('co2_emission_car_unit')

use_predicted_traffic = _make_property_getter('use_predicted_traffic')

def get_pt_planner(self, pt_planner_id=None):
pt_planner_id = pt_planner_id or self.default_pt_planner
return self._pt_planner_manager.get_pt_planner(pt_planner_id)
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 @@ -883,6 +883,9 @@ def _set_specific_params(mod):
if args.get('_loki_compute_pt_journey_fare') is None:
args['_loki_compute_pt_journey_fare'] = mod.loki_compute_pt_journey_fare

if args.get('_use_predicted_traffic') is None:
args['_use_predicted_traffic'] = mod.use_predicted_traffic

# When computing 'same_journey_schedules'(is_journey_schedules=True), some parameters need to be overridden
# because they are contradictory to the request
if args.get("is_journey_schedules"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,12 @@ def __init__(self, output_type_serializer):
hidden=True,
help="whether or not to use heuristic to optimized path searching in loki, used in loki exclusively",
)
parser_get.add_argument(
"_use_predicted_traffic",
type=BooleanType(),
hidden=True,
help="whether or not to use predicted/historical traffic data for routing, it affects only car/car_no_park mode in Asgard",
)

def parse_args(self, region=None, uri=None):
args = self.parsers['get'].parse_args()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _init_boundary_shape(self, boundary_geometry):
self.boundary_shape = boundary_shape
except Exception as e:
self.log.error('Error while loading boundary shape : {}'.format(e))
self.log.error("Unable to parse geometry object : ", boundary_geometry)
self.log.error("Unable to parse geometry object : {}".format(boundary_geometry))

def has_boundary_shape(self): # type () : bool
return hasattr(self, 'boundary_shape') and self.boundary_shape != None
Expand Down
2 changes: 2 additions & 0 deletions source/jormungandr/jormungandr/street_network/asgard.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def _create_sn_routing_matrix_request(

req.sn_routing_matrix.datetime = request["datetime"]
req.sn_routing_matrix.use_excluded_zones = request["_use_excluded_zones"]
req.sn_routing_matrix.use_predicted_traffic = request["_use_predicted_traffic"]

# Asgard/Valhalla walking
req.sn_routing_matrix.streetnetwork_params.walking_destination_only_penalty = request[
Expand Down Expand Up @@ -368,6 +369,7 @@ def _create_direct_path_request(
req.direct_path.datetime = fallback_extremity.datetime
req.direct_path.clockwise = fallback_extremity.represents_start
req.direct_path.use_excluded_zones = request["_use_excluded_zones"]
req.direct_path.use_predicted_traffic = request["_use_predicted_traffic"]
profiles = [
DirectPathProfile(
bike_use_roads=request['bike_use_roads'],
Expand Down
2 changes: 1 addition & 1 deletion source/jormungandr/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ requests-mock==1.0.0
flex==6.10.0
jsonschema==2.6.0
pytest-timeout==1.3.3
#pytest-asyncio==0.20.0 ; python_version >= "3.9"

2 changes: 1 addition & 1 deletion source/navitia-proto
Submodule navitia-proto updated 1 files
+3 −0 request.proto
2 changes: 2 additions & 0 deletions source/navitiacommon/navitiacommon/default_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@
co2_emission_car_value = 184.0 # gEC by Km
co2_emission_car_unit = 'gEC'

use_predicted_traffic = False


def get_value_or_default(attr, instance, instance_name):
if not instance or getattr(instance, attr, None) == None:
Expand Down
7 changes: 7 additions & 0 deletions source/navitiacommon/navitiacommon/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,13 @@ class Instance(db.Model): # type: ignore
server_default=str(default_values.co2_emission_car_unit),
)

use_predicted_traffic = db.Column(
db.Boolean,
default=default_values.use_predicted_traffic,
nullable=True,
server_default=false(),
)

def __init__(self, name=None, is_free=False, authorizations=None, jobs=None):
self.name = name
self.is_free = is_free
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""add use_predicted_traffic
Revision ID: fd13bb348665
Revises: d7ff7aea17d9
Create Date: 2024-10-10 15:14:54.523574
"""

# revision identifiers, used by Alembic.
revision = 'fd13bb348665'
down_revision = 'd7ff7aea17d9'

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
'instance', sa.Column('use_predicted_traffic', sa.Boolean(), server_default='False', nullable=True)
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('instance', 'use_predicted_traffic')
# ### end Alembic commands ###

0 comments on commit 167f0ea

Please sign in to comment.