Skip to content

Commit

Permalink
Reduce the number of ORS API calls
Browse files Browse the repository at this point in the history
Defaults to 100 features per request now and makes it user configurable in settings.

Fixes #732
  • Loading branch information
timlinux committed Jan 10, 2025
1 parent 2fdcd34 commit 707b35b
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 85 deletions.
5 changes: 4 additions & 1 deletion geest/core/workflows/multi_buffer_distances_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ def __init__(
else:
self.measurement = "time"

self.subset_size = 5 # Process 5 features at a time - hardcoded for now
# How many features to pass with each ORS API call
# Managed in the settings panel
self.subset_size = setting(key="ors_request_size", default=30)

self.ors_client = ORSClient("https://api.openrouteservice.org/v2/isochrones")
self.api_key = self.ors_client.check_api_key()
# Create the masked API key for logging
Expand Down
3 changes: 3 additions & 0 deletions geest/gui/geest_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __init__(self, parent=None):
self.ors_key_line_edit.setText(ors_key)
else:
self.ors_key_line_edit.setPlaceholderText("Enter your ORS API key here")
ors_request_size = int(setting(key="ors_request_size", default=100))
self.ors_request_size.setValue(ors_request_size)

def apply(self):
"""Process the animation sequence.
Expand All @@ -81,6 +83,7 @@ def apply(self):
set_setting(key="verbose_mode", value=0)

set_setting(key="ors_key", value=self.ors_key_line_edit.text())
set_setting(key="ors_request_size", value=self.ors_request_size.value())


class GeestOptionsFactory(QgsOptionsWidgetFactory):
Expand Down
206 changes: 122 additions & 84 deletions geest/ui/geest_settings_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,60 @@
<property name="windowTitle">
<string>Geest Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Your API Key for the Open Route Service</string>
<string># Geest Settings</string>
</property>
<property name="textFormat">
<enum>Qt::MarkdownText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="verbose_mode_checkbox">
<property name="text">
<string>Verbose logging mode</string>
</property>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Open Route Service Options</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Your API Key for the Open Route Service</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="ors_key_line_edit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Features per request</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="ors_request_size">
<property name="maximum">
<number>10000</number>
</property>
<property name="singleStep">
<number>10</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="2">
<item row="2" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -41,80 +79,80 @@
</property>
</spacer>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="debug_mode_checkbox">
<property name="text">
<string>Enable developer mode</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QLineEdit" name="ors_key_line_edit"/>
</item>
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_thread_pool_size">
<property name="text">
<string>Concurrent Tasks</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spin_thread_pool_size"/>
</item>
</layout>
</item>
<item row="4" column="1" colspan="2">
<widget class="QLabel" name="thread_pool_description">
<property name="text">
<string>The maximum number of concurrent threads to allow during analysis. Setting to the same number of CPU cores you have would be a good conservative approach. If you want to produce your analysis faster, you could probably run 4 or more on a decently specced machine.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QLabel" name="debug_mode_description">
<property name="text">
<string>This is intended for developers to attach to the plugin using a remote debugger so that they can step through the code. Do not enable it if you do not have a remote debugger set up as it will block QGIS startup until a debugger is attached to the process. In addition, debug mode will enable a log tab in the dock. Requires restart after changing.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string># Geest Settings</string>
</property>
<property name="textFormat">
<enum>Qt::MarkdownText</enum>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<widget class="QLabel" name="verbose_mode_description">
<property name="text">
<string>Adds verbose log message, useful for diagnostics.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>0</number>
</property>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Advanced Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_thread_pool_size">
<property name="text">
<string>Concurrent Tasks</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spin_thread_pool_size"/>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QLabel" name="thread_pool_description">
<property name="text">
<string>The maximum number of concurrent threads to allow during analysis. Setting to the same number of CPU cores you have would be a good conservative approach. If you want to produce your analysis faster, you could probably run 4 or more on a decently specced machine.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="debug_mode_checkbox">
<property name="text">
<string>Enable developer mode</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="debug_mode_description">
<property name="text">
<string>This is intended for developers to attach to the plugin using a remote debugger so that they can step through the code. Do not enable it if you do not have a remote debugger set up as it will block QGIS startup until a debugger is attached to the process. In addition, debug mode will enable a log tab in the dock. Requires restart after changing.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="verbose_mode_checkbox">
<property name="text">
<string>Verbose logging mode</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="verbose_mode_description">
<property name="text">
<string>Adds verbose log message, useful for diagnostics.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
Expand Down

0 comments on commit 707b35b

Please sign in to comment.