@@ -477,12 +477,32 @@ class OSRMDistanceMatrix:
477477 default_value = _OSRMResultModel .get_default ().name ,
478478 enum = _OSRMResultModel ,
479479 )
480-
480+ min_delay_seconds = knext .IntParameter (
481+ label = "Minimum delay (seconds)" ,
482+ description = "The minimum delay in seconds between two requests to the OSRM server." ,
483+ default_value = 1 ,
484+ since_version = "1.2.0" ,
485+ is_advanced = True ,
486+ )
487+ default_timeout = knext .IntParameter (
488+ label = "Default timeout (seconds)" ,
489+ description = "The default timeout in seconds for a request to the OSRM server." ,
490+ default_value = 10 ,
491+ since_version = "1.2.0" ,
492+ is_advanced = True ,
493+ )
494+ osrm_server = knext .StringParameter (
495+ label = "OSRM server" ,
496+ description = """The URL of the OSRM server to use. The default value is the demo server hosted at https://map.project-osrm.org""" ,
497+ default_value = "https://router.project-osrm.org" ,
498+ since_version = "1.2.0" ,
499+ is_advanced = True ,
500+ )
481501 # Constant for distance matrix
482502 _COL_GEOMETRY = "Route"
483503
484504 # For details see: http://project-osrm.org/docs/v5.5.1/api/#route-service
485- _BASE_URL = "https://router.project-osrm.org"
505+ # _BASE_URL = "https://router.project-osrm.org"
486506 # only supports car as profile: https://github.com/Project-OSRM/osrm-backend/issues/4034
487507 _PROFILE = "driving"
488508 # For details see: http://project-osrm.org/docs/v5.5.1/api/#route-service
@@ -491,10 +511,10 @@ class OSRMDistanceMatrix:
491511 # number of pairs send per request
492512 _BATCH_SIZE = 50
493513 # Number of seconds to wait after each request
494- _REQUEST_DELAY = 1
514+ # _REQUEST_DELAY = 1
495515 # Request timeout
496516 # do not send more than 1 request per second https://github.com/Project-OSRM/osrm-backend/wiki/Demo-server
497- _REQUEST_TIMEOUT = None
517+ # _REQUEST_TIMEOUT = None
498518
499519 def configure (self , configure_context , o_schema , d_schema ):
500520 self .o_geo_col = knut .column_exists_or_preset (
@@ -587,7 +607,7 @@ def update_part(self, model: _OSRMResultModel, df, ns, ne):
587607 # http://project-osrm.org/docs/v5.5.1/api/#route-service
588608 coordinate_query_list = [";" .join (df_batch ["period" ])]
589609 request_url = (
590- self ._BASE_URL
610+ self .osrm_server
591611 + "/route/v1/"
592612 + self ._PROFILE
593613 + "/"
@@ -599,9 +619,9 @@ def update_part(self, model: _OSRMResultModel, df, ns, ne):
599619 request_url ,
600620 params = self ._REQUEST_PARAMETER ,
601621 headers = knut .WEB_REQUEST_HEADER ,
602- timeout = self ._REQUEST_TIMEOUT ,
622+ timeout = self .default_timeout ,
603623 )
604- time .sleep (self ._REQUEST_DELAY )
624+ time .sleep (self .min_delay_seconds )
605625 data = json .loads (r .text )
606626 if data ["code" ] == "Ok" :
607627 if model .append_distance ():
0 commit comments