Skip to content

Commit

Permalink
Merge branch 'main' into 51-change-counts-left-or-right-terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
JuhoErvasti authored Oct 31, 2024
2 parents 85c9cbf + 530fb9b commit 10a5e74
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions fvh3t/fvh3t_processing/count_trajectories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)

Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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_negative", "counts_positive")
Expand Down

0 comments on commit 10a5e74

Please sign in to comment.