From 61272feb73284104b55ca73e58ffb711ddcb362e Mon Sep 17 00:00:00 2001 From: msorvoja Date: Thu, 31 Oct 2024 13:25:39 +0200 Subject: [PATCH] Minor fixes --- fvh3t/fvh3t_processing/count_trajectories.py | 25 +++++--------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/fvh3t/fvh3t_processing/count_trajectories.py b/fvh3t/fvh3t_processing/count_trajectories.py index 349e09e..2fd172e 100644 --- a/fvh3t/fvh3t_processing/count_trajectories.py +++ b/fvh3t/fvh3t_processing/count_trajectories.py @@ -59,9 +59,8 @@ def initAlgorithm(self, config=None): # noqa N802 self.addParameter( QgsProcessingParameterVectorLayer( name=self.INPUT_LINES, - description="Input line layer", + description="Gates", types=[QgsProcessing.TypeVectorLine], - optional=True, ) ) @@ -117,28 +116,19 @@ def processAlgorithm( # noqa N802 ## CREATE TRAJECTORIES - # TODO: Remove later feedback.pushInfo(f"Original point layer has {point_layer.featureCount()} features.") # Get min and max timestamps from the data - min_timestamp = None - max_timestamp = None - - for feature in point_layer.getFeatures(): - timestamp = feature["timestamp"] - - if min_timestamp is None or timestamp < min_timestamp: - min_timestamp = timestamp - if max_timestamp is None or timestamp > max_timestamp: - max_timestamp = timestamp + timestamp_field_id = point_layer.fields().indexOf("timestamp") + min_timestamp, max_timestamp = point_layer.minimumAndMaximumValue(timestamp_field_id) if min_timestamp is None or max_timestamp is None: msg = "No valid timestamps found in the point layer." raise ValueError(msg) # Check if start and end times are empty. If yes, use min and max timestamps. If not, convert to unix time. - start_time_unix = start_time.toSecsSinceEpoch() * 1000 if start_time.isValid() else min_timestamp - end_time_unix = end_time.toSecsSinceEpoch() * 1000 if end_time.isValid() else max_timestamp + start_time_unix = start_time.toMSecsSinceEpoch() if start_time.isValid() else min_timestamp + end_time_unix = end_time.toMSecsSinceEpoch() if end_time.isValid() else max_timestamp # Check that the set start and end times are in data's range if not (min_timestamp <= start_time_unix <= max_timestamp) or not ( @@ -168,7 +158,6 @@ def processAlgorithm( # noqa N802 id_count[feature_id] = 0 id_count[feature_id] += 1 - # TODO: Remove later feedback.pushInfo(f"Filtered {filtered_layer.featureCount()} features based on timestamp range.") # Prepare another memory layer for features with non-unique id after filtering time @@ -185,9 +174,8 @@ def processAlgorithm( # noqa N802 new_feature = QgsFeature(feature) non_unique_layer.dataProvider().addFeature(new_feature) - # TODO: Remove later feedback.pushInfo( - f"Final filtered layer contains {non_unique_layer.featureCount()} features with non-unique IDs." + f"Final filtered point layer contains {non_unique_layer.featureCount()} features with non-unique IDs." ) trajectory_layer = TrajectoryLayer( @@ -221,7 +209,6 @@ def processAlgorithm( # noqa N802 # CREATE GATES line_layer = self.parameterAsVectorLayer(parameters, self.INPUT_LINES, context) - # TODO: Remove later feedback.pushInfo(f"Line layer has {line_layer.featureCount()} features.") gate_layer = GateLayer(line_layer, "counts_left", "counts_right")