From 8bb257066b0e4101574a5b04eeb04ae074e17fc4 Mon Sep 17 00:00:00 2001 From: Xiaokang Fu <1072534112@qq.com> Date: Mon, 25 Sep 2023 15:57:13 -0400 Subject: [PATCH 1/2] expose some options as advanced configrations --- knime_extension/src/nodes/spatialnetwork.py | 33 +++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/knime_extension/src/nodes/spatialnetwork.py b/knime_extension/src/nodes/spatialnetwork.py index 9ad90000..c5e5118b 100644 --- a/knime_extension/src/nodes/spatialnetwork.py +++ b/knime_extension/src/nodes/spatialnetwork.py @@ -471,6 +471,27 @@ class OSRMDistanceMatrix: include_row_key=False, include_none_column=False, ) + min_delay_seconds = knext.IntParameter( + label="Minimum delay (seconds)", + description="The minimum delay in seconds between two requests to the OSRM server.", + default_value=1, + since_version="1.2.0", + is_advanced=True, + ) + default_timeout = knext.IntParameter( + label="Default timeout (seconds)", + description="The default timeout in seconds for a request to the OSRM server.", + default_value=10, + since_version="1.2.0", + is_advanced=True, + ) + osrm_server = knext.StringParameter( + label="OSRM server", + description="""The URL of the OSRM server to use. The default value is the demo server hosted at https://map.project-osrm.org""", + default_value="https://router.project-osrm.org", + since_version="1.2.0", + is_advanced=True, + ) result_model = knext.EnumParameter( label="Result mode", description="Supports the following result modes:", @@ -482,7 +503,7 @@ class OSRMDistanceMatrix: _COL_GEOMETRY = "Route" # For details see: http://project-osrm.org/docs/v5.5.1/api/#route-service - _BASE_URL = "https://router.project-osrm.org" + # _BASE_URL = "https://router.project-osrm.org" # only supports car as profile: https://github.com/Project-OSRM/osrm-backend/issues/4034 _PROFILE = "driving" # For details see: http://project-osrm.org/docs/v5.5.1/api/#route-service @@ -491,10 +512,10 @@ class OSRMDistanceMatrix: # number of pairs send per request _BATCH_SIZE = 50 # Number of seconds to wait after each request - _REQUEST_DELAY = 1 + # _REQUEST_DELAY = 1 # Request timeout # do not send more than 1 request per second https://github.com/Project-OSRM/osrm-backend/wiki/Demo-server - _REQUEST_TIMEOUT = None + # _REQUEST_TIMEOUT = None def configure(self, configure_context, o_schema, d_schema): self.o_geo_col = knut.column_exists_or_preset( @@ -587,7 +608,7 @@ def update_part(self, model: _OSRMResultModel, df, ns, ne): # http://project-osrm.org/docs/v5.5.1/api/#route-service coordinate_query_list = [";".join(df_batch["period"])] request_url = ( - self._BASE_URL + self.osrm_server + "/route/v1/" + self._PROFILE + "/" @@ -599,9 +620,9 @@ def update_part(self, model: _OSRMResultModel, df, ns, ne): request_url, params=self._REQUEST_PARAMETER, headers=knut.WEB_REQUEST_HEADER, - timeout=self._REQUEST_TIMEOUT, + timeout=self.default_timeout, ) - time.sleep(self._REQUEST_DELAY) + time.sleep(self.min_delay_seconds) data = json.loads(r.text) if data["code"] == "Ok": if model.append_distance(): From 2e639cec10b6a1ba8744f9d50cfb4e89ec26326c Mon Sep 17 00:00:00 2001 From: Xiaokang Fu <1072534112@qq.com> Date: Mon, 25 Sep 2023 15:58:54 -0400 Subject: [PATCH 2/2] change the order of the configrations --- knime_extension/src/nodes/spatialnetwork.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/knime_extension/src/nodes/spatialnetwork.py b/knime_extension/src/nodes/spatialnetwork.py index c5e5118b..6b51adab 100644 --- a/knime_extension/src/nodes/spatialnetwork.py +++ b/knime_extension/src/nodes/spatialnetwork.py @@ -471,6 +471,12 @@ class OSRMDistanceMatrix: include_row_key=False, include_none_column=False, ) + result_model = knext.EnumParameter( + label="Result mode", + description="Supports the following result modes:", + default_value=_OSRMResultModel.get_default().name, + enum=_OSRMResultModel, + ) min_delay_seconds = knext.IntParameter( label="Minimum delay (seconds)", description="The minimum delay in seconds between two requests to the OSRM server.", @@ -492,13 +498,6 @@ class OSRMDistanceMatrix: since_version="1.2.0", is_advanced=True, ) - result_model = knext.EnumParameter( - label="Result mode", - description="Supports the following result modes:", - default_value=_OSRMResultModel.get_default().name, - enum=_OSRMResultModel, - ) - # Constant for distance matrix _COL_GEOMETRY = "Route"