Skip to content

Commit

Permalink
Improving progress info
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogsilva committed Oct 11, 2024
1 parent 9ceb704 commit fc05755
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/qgis_conefor/processing/algorithms/coneforinputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class ConeforInputsBase(base.Base):
_autogenerated_node_id_field_name = "conefor_node_id"
_autogenerated_node_attribute_field_name = "conefor_node_attribute"
_autogenerated_node_attribute_field_name = "conefor_node_attribute (area)"

INPUT_NODE_IDENTIFIER_NAME = (
"node_identifier", "Node identifier (will autogenerate if not set)")
Expand Down Expand Up @@ -267,7 +267,6 @@ def processAlgorithm(self, parameters, context, feedback):
}

if source.featureCount() > 0:
remaining_progress = 100
if node_id_field_name is None: # will be generating a new layer
feedback.pushInfo(
"No node identifier specified - adding a new field to a copy of "
Expand All @@ -283,9 +282,6 @@ def processAlgorithm(self, parameters, context, feedback):
ownsOriginalSource=False,
)
node_id_field_name = self._autogenerated_node_id_field_name
progress_step = 20
remaining_progress -= progress_step
feedback.setProgress(100 - remaining_progress)

result[self.OUTPUT_GENERATED_CONEFOR_LAYER[0]] = final_layer_path
relevant_details = context.layerToLoadOnCompletionDetails(final_layer_path)
Expand All @@ -302,6 +298,7 @@ def processAlgorithm(self, parameters, context, feedback):
num_features_to_process = source.featureCount()
node_file_lines = num_features_to_process
connection_file_lines = num_features_to_process * (num_features_to_process - 1) // 2
remaining_progress = 100
progress_step = remaining_progress / (node_file_lines + connection_file_lines)
node_file_progress_portion = progress_step * node_file_lines

Expand All @@ -313,7 +310,7 @@ def processAlgorithm(self, parameters, context, feedback):
source,
output_dir,
feedback,
start_progress=(100 - remaining_progress),
start_progress=remaining_progress,
progress_step=progress_step,
)
)
Expand Down Expand Up @@ -521,7 +518,6 @@ def processAlgorithm(self, parameters, context, feedback):
self.OUTPUT_GENERATED_CONEFOR_LAYER[0]: None,
}
if source.featureCount() > 0:
remaining_progress = 100
if not all((node_id_field_name, node_attribute_field_name)): # will be generating a new layer
final_layer_path = None
if node_id_field_name is None:
Expand All @@ -539,9 +535,6 @@ def processAlgorithm(self, parameters, context, feedback):
ownsOriginalSource=False,
)
node_id_field_name = self._autogenerated_node_id_field_name
progress_step = 10 if node_attribute_field_name is None else 20
remaining_progress -= progress_step
feedback.setProgress(100 - remaining_progress)

if node_attribute_field_name is None: # being asked to use the area as the attribute
feedback.pushInfo(
Expand All @@ -558,9 +551,6 @@ def processAlgorithm(self, parameters, context, feedback):
context,
ownsOriginalSource=False,
)
progress_step = 10
remaining_progress -= progress_step
feedback.setProgress(100 - remaining_progress)
result[self.OUTPUT_GENERATED_CONEFOR_LAYER[0]] = final_layer_path
# we do not want QGIS to try to automatically load the intermediate
# layers, which will happen when calling this algorithm from the
Expand All @@ -580,6 +570,7 @@ def processAlgorithm(self, parameters, context, feedback):
num_features_to_process = source.featureCount()
node_file_lines = num_features_to_process
connection_file_lines = num_features_to_process * (num_features_to_process - 1) // 2
remaining_progress = 100
progress_step = remaining_progress / (node_file_lines + connection_file_lines)
node_file_progress_portion = progress_step * node_file_lines
node_file_output_path = (
Expand All @@ -590,7 +581,7 @@ def processAlgorithm(self, parameters, context, feedback):
source,
output_dir,
feedback,
start_progress=(100 - remaining_progress),
start_progress=remaining_progress,
progress_step=progress_step,
)
)
Expand Down

0 comments on commit fc05755

Please sign in to comment.