From 0063d09cc72575de62ee11e98bb48f956c206662 Mon Sep 17 00:00:00 2001 From: msorvoja Date: Tue, 5 Nov 2024 13:15:18 +0200 Subject: [PATCH 1/5] Add class of traveler and name attributes --- fvh3t/core/gate.py | 14 +++++++++- fvh3t/core/gate_layer.py | 27 +++++++++++++++++--- fvh3t/core/line_layer.py | 1 + fvh3t/fvh3t_processing/count_trajectories.py | 16 ++++++++++-- tests/conftest.py | 12 ++++++--- tests/core/test_gate.py | 8 +++--- tests/core/test_gate_layer.py | 6 ++++- tests/processing/test_count_trajectories.py | 9 ++++--- 8 files changed, 75 insertions(+), 18 deletions(-) diff --git a/fvh3t/core/gate.py b/fvh3t/core/gate.py index 73393e8..e7949a9 100644 --- a/fvh3t/core/gate.py +++ b/fvh3t/core/gate.py @@ -20,7 +20,14 @@ class Gate: must be a line. """ - def __init__(self, geom: QgsGeometry, *, counts_negative: bool = False, counts_positive: bool = False) -> None: + def __init__( + self, + geom: QgsGeometry, + name: str, + *, + counts_negative: bool = False, + counts_positive: bool = False, + ) -> None: if geom.type() != QgsWkbTypes.GeometryType.LineGeometry: msg = "Gate must be created from a line geometry!" raise InvalidGeometryTypeException(msg) @@ -28,6 +35,8 @@ def __init__(self, geom: QgsGeometry, *, counts_negative: bool = False, counts_p self.__geom: QgsGeometry = geom self.__trajectory_count: int = 0 + self.__name: str = name + self.__counts_negative: bool = counts_negative self.__counts_positive: bool = counts_positive @@ -40,6 +49,9 @@ def __init__(self, geom: QgsGeometry, *, counts_negative: bool = False, counts_p self.__segments: tuple[GateSegment, ...] = () self.create_segments() + def name(self) -> str: + return self.__name + def set_counts_negative(self, *, state: bool) -> None: self.__counts_negative = state diff --git a/fvh3t/core/gate_layer.py b/fvh3t/core/gate_layer.py index 9b1228b..36450be 100644 --- a/fvh3t/core/gate_layer.py +++ b/fvh3t/core/gate_layer.py @@ -1,7 +1,7 @@ from __future__ import annotations from qgis.core import QgsFeature, QgsFeatureSource, QgsField, QgsVectorLayer, QgsWkbTypes -from qgis.PyQt.QtCore import QMetaType, QVariant +from qgis.PyQt.QtCore import QDateTime, QMetaType, QVariant from fvh3t.core.exceptions import InvalidFeatureException, InvalidLayerException from fvh3t.core.gate import Gate @@ -20,10 +20,12 @@ class GateLayer: def __init__( self, layer: QgsVectorLayer, + name_field: str, counts_negative_field: str, counts_positive_field: str, ) -> None: self.__layer: QgsVectorLayer = layer + self.__name_field = name_field self.__counts_negative_field = counts_negative_field self.__counts_positive_field = counts_positive_field @@ -32,16 +34,23 @@ def __init__( self.create_gates() def create_gates(self) -> None: + name_field_idx: int = self.__layer.fields().indexOf(self.__name_field) counts_negative_field_idx: int = self.__layer.fields().indexOf(self.__counts_negative_field) counts_positive_field_idx: int = self.__layer.fields().indexOf(self.__counts_positive_field) gates: list[Gate] = [] for feature in self.__layer.getFeatures(): + name: str = feature[name_field_idx] counts_negative: bool = feature[counts_negative_field_idx] counts_positive: bool = feature[counts_positive_field_idx] - gate = Gate(feature.geometry(), counts_negative=counts_negative, counts_positive=counts_positive) + gate = Gate( + feature.geometry(), + name=name, + counts_negative=counts_negative, + counts_positive=counts_positive, + ) gates.append(gate) @@ -50,12 +59,16 @@ def create_gates(self) -> None: def gates(self) -> tuple[Gate, ...]: return self.__gates - def as_line_layer(self) -> QgsVectorLayer | None: + def as_line_layer(self, traveler_class: str, start_time: QDateTime, end_time: QDateTime) -> QgsVectorLayer | None: line_layer = QgsVectorLayer("LineString?crs=3067", "Line Layer", "memory") line_layer.startEditing() line_layer.addAttribute(QgsField("fid", QVariant.Int)) + line_layer.addAttribute(QgsField("name", QVariant.String)) + line_layer.addAttribute(QgsField("traveler_class", QVariant.String)) + line_layer.addAttribute(QgsField("start_time", QVariant.Time)) + line_layer.addAttribute(QgsField("end_time", QVariant.Time)) line_layer.addAttribute(QgsField("counts_negative", QVariant.Bool)) line_layer.addAttribute(QgsField("counts_positive", QVariant.Bool)) line_layer.addAttribute(QgsField("trajectory_count", QVariant.Int)) @@ -68,6 +81,10 @@ def as_line_layer(self) -> QgsVectorLayer | None: feature.setAttributes( [ i, + gate.name(), + traveler_class, + start_time, + end_time, gate.counts_negative(), gate.counts_positive(), gate.trajectory_count(), @@ -119,6 +136,10 @@ def is_valid(self) -> bool: msg = "Layer has no features." raise InvalidLayerException(msg) + if not self.is_field_valid(self.__name_field, accepted_types=[QMetaType.Type.QString]): + msg = "Name field either not found or of incorrect type." + raise InvalidLayerException(msg) + if not self.is_field_valid(self.__counts_negative_field, accepted_types=[QMetaType.Type.Bool]): msg = "Counts negative field either not found or of incorrect type." raise InvalidLayerException(msg) diff --git a/fvh3t/core/line_layer.py b/fvh3t/core/line_layer.py index fdd6845..f6b56cc 100644 --- a/fvh3t/core/line_layer.py +++ b/fvh3t/core/line_layer.py @@ -9,6 +9,7 @@ def create_line_layer() -> QgsVectorLayer: layer.startEditing() + layer.addAttribute(QgsField("name", QVariant.String)) layer.addAttribute(QgsField("counts_negative", QVariant.Bool)) layer.addAttribute(QgsField("counts_positive", QVariant.Bool)) diff --git a/fvh3t/fvh3t_processing/count_trajectories.py b/fvh3t/fvh3t_processing/count_trajectories.py index 9020e81..4bab142 100644 --- a/fvh3t/fvh3t_processing/count_trajectories.py +++ b/fvh3t/fvh3t_processing/count_trajectories.py @@ -10,6 +10,7 @@ QgsProcessingFeedback, QgsProcessingParameterDateTime, QgsProcessingParameterFeatureSink, + QgsProcessingParameterString, QgsProcessingParameterVectorLayer, QgsUnitTypes, ) @@ -22,6 +23,7 @@ class CountTrajectories(QgsProcessingAlgorithm): INPUT_POINTS = "INPUT_POINTS" INPUT_LINES = "INPUT_LINES" + TRAVELER_CLASS = "TRAVELER_CLASS" START_TIME = "START_TIME" END_TIME = "END_TIME" OUTPUT_GATES = "OUTPUT_GATES" @@ -62,6 +64,13 @@ def initAlgorithm(self, config=None): # noqa N802 ) ) + self.addParameter( + QgsProcessingParameterString( + name=self.TRAVELER_CLASS, + description="Class of traveler", + ) + ) + self.addParameter( QgsProcessingParameterDateTime( name=self.START_TIME, @@ -109,6 +118,7 @@ def processAlgorithm( # noqa N802 feedback = QgsProcessingFeedback() point_layer = self.parameterAsVectorLayer(parameters, self.INPUT_POINTS, context) + traveler_class = self.parameterAsString(parameters, self.TRAVELER_CLASS, context) start_time: QDateTime = self.parameterAsDateTime(parameters, self.START_TIME, context) end_time: QDateTime = self.parameterAsDateTime(parameters, self.END_TIME, context) @@ -186,14 +196,16 @@ def processAlgorithm( # noqa N802 feedback.pushInfo(f"Line layer has {line_layer.featureCount()} features.") - gate_layer = GateLayer(line_layer, "counts_negative", "counts_positive") + gate_layer = GateLayer(line_layer, "name", "counts_negative", "counts_positive") gates = gate_layer.gates() for gate in gates: gate.count_trajectories_from_layer(trajectory_layer) - exported_gate_layer = gate_layer.as_line_layer() + exported_gate_layer = gate_layer.as_line_layer( + traveler_class=traveler_class, start_time=start_time, end_time=end_time + ) if exported_gate_layer is None: msg = "Gate layer is None" diff --git a/tests/conftest.py b/tests/conftest.py index 72d8299..0028d6a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -66,6 +66,7 @@ def size_changing_trajectory(): def two_point_gate(): return Gate( QgsGeometry.fromPolylineXY([QgsPointXY(-0.5, 0.5), QgsPointXY(0.5, 0.5)]), + name="two_point_gate", counts_negative=True, counts_positive=True, ) @@ -75,6 +76,7 @@ def two_point_gate(): def three_point_gate(): return Gate( QgsGeometry.fromPolylineXY([QgsPointXY(1, 1), QgsPointXY(2, 1), QgsPointXY(2, 2)]), + name="three_point_gate", counts_negative=True, counts_positive=True, ) @@ -328,11 +330,12 @@ def qgis_gate_line_layer(): layer.startEditing() + layer.addAttribute(QgsField("name", QVariant.String)) layer.addAttribute(QgsField("counts_negative", QVariant.Bool)) layer.addAttribute(QgsField("counts_positive", QVariant.Bool)) gate1 = QgsFeature(layer.fields()) - gate1.setAttributes([True, True]) + gate1.setAttributes(["name", True, True]) gate1.setGeometry( QgsGeometry.fromPolylineXY( [ @@ -344,7 +347,7 @@ def qgis_gate_line_layer(): ) gate2 = QgsFeature(layer.fields()) - gate2.setAttributes([False, True]) + gate2.setAttributes(["name", False, True]) gate2.setGeometry( QgsGeometry.fromPolylineXY( [ @@ -355,7 +358,7 @@ def qgis_gate_line_layer(): ) gate3 = QgsFeature(layer.fields()) - gate3.setAttributes([True, False]) + gate3.setAttributes(["name", True, False]) gate3.setGeometry( QgsGeometry.fromPolylineXY( [ @@ -383,11 +386,12 @@ def qgis_gate_line_layer_wrong_field_type(): layer.startEditing() + layer.addAttribute(QgsField("name", QVariant.String)) layer.addAttribute(QgsField("counts_negative", QVariant.Bool)) layer.addAttribute(QgsField("counts_positive", QVariant.Int)) gate = QgsFeature(layer.fields()) - gate.setAttributes([True, True]) + gate.setAttributes(["name", True, True]) gate.setGeometry( QgsGeometry.fromPolylineXY( [ diff --git a/tests/core/test_gate.py b/tests/core/test_gate.py index 097d453..ecde839 100644 --- a/tests/core/test_gate.py +++ b/tests/core/test_gate.py @@ -17,16 +17,16 @@ def test_trajectory_count(qgis_point_layer_for_gate_count): ) geom1 = QgsGeometry.fromPolylineXY([QgsPointXY(-0.5, 0.5), QgsPointXY(0.5, 0.5)]) - gate1 = Gate(geom1, counts_positive=True) + gate1 = Gate(geom1, name="gate1", counts_positive=True) geom2 = QgsGeometry.fromPolylineXY([QgsPointXY(-1, 0.75), QgsPointXY(1, 1)]) - gate2 = Gate(geom2, counts_negative=True) + gate2 = Gate(geom2, name="gate2", counts_negative=True) geom3 = QgsGeometry.fromPolylineXY([QgsPointXY(0.5, 0), QgsPointXY(-0.75, 2)]) - gate3 = Gate(geom3, counts_negative=True, counts_positive=True) + gate3 = Gate(geom3, name="gate3", counts_negative=True, counts_positive=True) geom4 = QgsGeometry.fromPolylineXY([QgsPointXY(-1, -0.5), QgsPointXY(1, -0.5)]) - gate4 = Gate(geom4, counts_negative=True, counts_positive=True) + gate4 = Gate(geom4, name="gate4", counts_negative=True, counts_positive=True) gate1.count_trajectories_from_layer(traj_layer) assert gate1.trajectory_count() == 1 diff --git a/tests/core/test_gate_layer.py b/tests/core/test_gate_layer.py index 938ab8d..06fd8d2 100644 --- a/tests/core/test_gate_layer.py +++ b/tests/core/test_gate_layer.py @@ -9,6 +9,7 @@ def test_gate_layer_create_gates(qgis_gate_line_layer): gate_layer = GateLayer( qgis_gate_line_layer, + "name", "counts_negative", "counts_positive", ) @@ -43,6 +44,7 @@ def test_is_field_valid(qgis_gate_line_layer, qgis_gate_line_layer_wrong_field_t with pytest.raises(InvalidLayerException, match="Counts negative field either not found or of incorrect type."): GateLayer( qgis_gate_line_layer, + "name", "count_positive", # use wrong field names on purpose "count_negative", ) @@ -50,6 +52,7 @@ def test_is_field_valid(qgis_gate_line_layer, qgis_gate_line_layer_wrong_field_t with pytest.raises(InvalidLayerException, match="Counts positive field either not found or of incorrect type."): GateLayer( qgis_gate_line_layer_wrong_field_type, + "name", "counts_negative", "counts_positive", ) @@ -61,7 +64,7 @@ def test_create_valid_gate_from_empty_line_layer(): layer.startEditing() gate = QgsFeature(layer.fields()) - gate.setAttributes([True, True]) + gate.setAttributes(["name", True, True]) gate.setGeometry( QgsGeometry.fromPolylineXY( [ @@ -77,6 +80,7 @@ def test_create_valid_gate_from_empty_line_layer(): gate_layer = GateLayer( layer, + "name", "counts_negative", "counts_positive", ) diff --git a/tests/processing/test_count_trajectories.py b/tests/processing/test_count_trajectories.py index 9b3cda0..96553ab 100644 --- a/tests/processing/test_count_trajectories.py +++ b/tests/processing/test_count_trajectories.py @@ -16,11 +16,12 @@ def input_gate_layer_for_algorithm(): layer.startEditing() + layer.addAttribute(QgsField("name", QVariant.String)) layer.addAttribute(QgsField("counts_negative", QVariant.Bool)) layer.addAttribute(QgsField("counts_positive", QVariant.Bool)) gate1 = QgsFeature(layer.fields()) - gate1.setAttributes([True, False]) + gate1.setAttributes(["gate1", True, False]) gate1.setGeometry( QgsGeometry.fromPolylineXY( [ @@ -31,7 +32,7 @@ def input_gate_layer_for_algorithm(): ) gate2 = QgsFeature(layer.fields()) - gate2.setAttributes([False, True]) + gate2.setAttributes(["gate2", False, True]) gate2.setGeometry( QgsGeometry.fromPolylineXY( [ @@ -42,7 +43,7 @@ def input_gate_layer_for_algorithm(): ) gate3 = QgsFeature(layer.fields()) - gate3.setAttributes([True, True]) + gate3.setAttributes(["gate3", True, True]) gate3.setGeometry( QgsGeometry.fromPolylineXY( [ @@ -170,6 +171,7 @@ def test_count_trajectories( params = { "INPUT_POINTS": input_point_layer_for_algorithm, "INPUT_LINES": input_gate_layer_for_algorithm, + "TRAVELER_CLASS": "CAR", "START_TIME": None, "END_TIME": None, "OUTPUT_GATES": "TEMPORARY_OUTPUT", @@ -302,6 +304,7 @@ def test_count_trajectories( case2_params = { "INPUT_POINTS": input_point_layer_for_algorithm, "INPUT_LINES": input_gate_layer_for_algorithm, + "TRAVELER_CLASS": "CAR", "START_TIME": QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0), QTimeZone.utc()), "END_TIME": QDateTime(QDate(1970, 1, 1), QTime(0, 5, 0), QTimeZone.utc()), "OUTPUT_GATES": "TEMPORARY_OUTPUT", From b3d7db25b60416dc9ca0fc8b9e68189127173b73 Mon Sep 17 00:00:00 2001 From: msorvoja Date: Tue, 5 Nov 2024 14:11:14 +0200 Subject: [PATCH 2/5] Add class of traveler filtering by using expression --- fvh3t/fvh3t_processing/count_trajectories.py | 6 ++++ tests/processing/test_count_trajectories.py | 33 ++++++++++---------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/fvh3t/fvh3t_processing/count_trajectories.py b/fvh3t/fvh3t_processing/count_trajectories.py index 4bab142..abf081b 100644 --- a/fvh3t/fvh3t_processing/count_trajectories.py +++ b/fvh3t/fvh3t_processing/count_trajectories.py @@ -68,6 +68,7 @@ def initAlgorithm(self, config=None): # noqa N802 QgsProcessingParameterString( name=self.TRAVELER_CLASS, description="Class of traveler", + optional=True, ) ) @@ -161,6 +162,11 @@ def processAlgorithm( # noqa N802 filter_expression: str | None = None if start_time_unix != min_timestamp or end_time_unix != max_timestamp: filter_expression = f'"timestamp" BETWEEN {start_time_unix} AND {end_time_unix}' + if not filter_expression: + if traveler_class: + filter_expression = f'"label" = {traveler_class}' + elif traveler_class: + filter_expression += f' AND "label" = {traveler_class}' trajectory_layer = TrajectoryLayer( point_layer, diff --git a/tests/processing/test_count_trajectories.py b/tests/processing/test_count_trajectories.py index 96553ab..a65f3ea 100644 --- a/tests/processing/test_count_trajectories.py +++ b/tests/processing/test_count_trajectories.py @@ -74,61 +74,62 @@ def input_point_layer_for_algorithm(): layer.addAttribute(QgsField("size_x", QVariant.Int)) layer.addAttribute(QgsField("size_y", QVariant.Int)) layer.addAttribute(QgsField("size_z", QVariant.Int)) + layer.addAttribute(QgsField("label", QVariant.String)) traj1_f1 = QgsFeature(layer.fields()) - traj1_f1.setAttributes([1, 0, 1, 1, 1]) + traj1_f1.setAttributes([1, 0, 1, 1, 1, "car"]) traj1_f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(1, 1.5))) traj1_f2 = QgsFeature(layer.fields()) - traj1_f2.setAttributes([1, 1000, 2, 2, 2]) + traj1_f2.setAttributes([1, 1000, 2, 2, 2, "car"]) traj1_f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(0.5, 1.5))) traj1_f3 = QgsFeature(layer.fields()) - traj1_f3.setAttributes([1, 2000, 1, 1, 1]) + traj1_f3.setAttributes([1, 2000, 1, 1, 1, "car"]) traj1_f3.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(-0.5, 1.5))) traj1_f4 = QgsFeature(layer.fields()) - traj1_f4.setAttributes([1, 3000, 2, 2, 2]) + traj1_f4.setAttributes([1, 3000, 2, 2, 2, "car"]) traj1_f4.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(-1, 2))) traj2_f1 = QgsFeature(layer.fields()) - traj2_f1.setAttributes([2, 0, 1, 1, 1]) + traj2_f1.setAttributes([2, 0, 1, 1, 1, "car"]) traj2_f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(-0.5, 1))) traj2_f2 = QgsFeature(layer.fields()) - traj2_f2.setAttributes([2, 1000, 2, 2, 2]) + traj2_f2.setAttributes([2, 1000, 2, 2, 2, "car"]) traj2_f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(0.5, 2))) traj3_f1 = QgsFeature(layer.fields()) - traj3_f1.setAttributes([3, 0, 1, 1, 1]) + traj3_f1.setAttributes([3, 0, 1, 1, 1, "car"]) traj3_f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(1.5, 0.5))) traj3_f2 = QgsFeature(layer.fields()) - traj3_f2.setAttributes([3, 1000, 2, 2, 2]) + traj3_f2.setAttributes([3, 1000, 2, 2, 2, "car"]) traj3_f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(1.5, 1.5))) traj4_f1 = QgsFeature(layer.fields()) - traj4_f1.setAttributes([4, 301000, 1, 1, 1]) + traj4_f1.setAttributes([4, 301000, 1, 1, 1, "car"]) traj4_f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(1.5, 2))) traj4_f2 = QgsFeature(layer.fields()) - traj4_f2.setAttributes([4, 302000, 2, 2, 2]) + traj4_f2.setAttributes([4, 302000, 2, 2, 2, "car"]) traj4_f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(2.5, 1))) traj5_f1 = QgsFeature(layer.fields()) - traj5_f1.setAttributes([5, 305000, 1, 1, 1]) + traj5_f1.setAttributes([5, 305000, 1, 1, 1, "car"]) traj5_f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(1, 0.5))) traj5_f2 = QgsFeature(layer.fields()) - traj5_f2.setAttributes([5, 306000, 2, 2, 2]) + traj5_f2.setAttributes([5, 306000, 2, 2, 2, "car"]) traj5_f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(0, -0.5))) traj6_f1 = QgsFeature(layer.fields()) - traj6_f1.setAttributes([6, 309000, 1, 1, 1]) + traj6_f1.setAttributes([6, 309000, 1, 1, 1, "car"]) traj6_f1.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(0.5, -0.5))) traj6_f2 = QgsFeature(layer.fields()) - traj6_f2.setAttributes([6, 310000, 2, 2, 2]) + traj6_f2.setAttributes([6, 310000, 2, 2, 2, "car"]) traj6_f2.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(0, 0.5))) layer.addFeature(traj1_f1) @@ -171,7 +172,7 @@ def test_count_trajectories( params = { "INPUT_POINTS": input_point_layer_for_algorithm, "INPUT_LINES": input_gate_layer_for_algorithm, - "TRAVELER_CLASS": "CAR", + "TRAVELER_CLASS": "car", "START_TIME": None, "END_TIME": None, "OUTPUT_GATES": "TEMPORARY_OUTPUT", @@ -304,7 +305,7 @@ def test_count_trajectories( case2_params = { "INPUT_POINTS": input_point_layer_for_algorithm, "INPUT_LINES": input_gate_layer_for_algorithm, - "TRAVELER_CLASS": "CAR", + "TRAVELER_CLASS": "car", "START_TIME": QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0), QTimeZone.utc()), "END_TIME": QDateTime(QDate(1970, 1, 1), QTime(0, 5, 0), QTimeZone.utc()), "OUTPUT_GATES": "TEMPORARY_OUTPUT", From f7ceba33b048cc2c745045c6b5555418013a1883 Mon Sep 17 00:00:00 2001 From: msorvoja Date: Tue, 5 Nov 2024 14:22:19 +0200 Subject: [PATCH 3/5] Fix expression --- fvh3t/fvh3t_processing/count_trajectories.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fvh3t/fvh3t_processing/count_trajectories.py b/fvh3t/fvh3t_processing/count_trajectories.py index abf081b..ac544a3 100644 --- a/fvh3t/fvh3t_processing/count_trajectories.py +++ b/fvh3t/fvh3t_processing/count_trajectories.py @@ -164,9 +164,9 @@ def processAlgorithm( # noqa N802 filter_expression = f'"timestamp" BETWEEN {start_time_unix} AND {end_time_unix}' if not filter_expression: if traveler_class: - filter_expression = f'"label" = {traveler_class}' + filter_expression = f"\"label\" = '{traveler_class}'" elif traveler_class: - filter_expression += f' AND "label" = {traveler_class}' + filter_expression += f" AND \"label\" = '{traveler_class}'" trajectory_layer = TrajectoryLayer( point_layer, From 6a912532f3205088a99fa7d6a68c3a18acc33ce2 Mon Sep 17 00:00:00 2001 From: msorvoja Date: Tue, 5 Nov 2024 14:41:00 +0200 Subject: [PATCH 4/5] Fix empty start/end time in exported Gate Layer --- fvh3t/fvh3t_processing/count_trajectories.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fvh3t/fvh3t_processing/count_trajectories.py b/fvh3t/fvh3t_processing/count_trajectories.py index ac544a3..039204e 100644 --- a/fvh3t/fvh3t_processing/count_trajectories.py +++ b/fvh3t/fvh3t_processing/count_trajectories.py @@ -209,6 +209,10 @@ def processAlgorithm( # noqa N802 for gate in gates: gate.count_trajectories_from_layer(trajectory_layer) + if not start_time: + start_time = QDateTime.fromMSecsSinceEpoch(min_timestamp) + if not end_time: + end_time = QDateTime.fromMSecsSinceEpoch(max_timestamp) exported_gate_layer = gate_layer.as_line_layer( traveler_class=traveler_class, start_time=start_time, end_time=end_time ) From b2d6fe723bc968ee5d6ab795ceee6fff091cce19 Mon Sep 17 00:00:00 2001 From: msorvoja Date: Tue, 5 Nov 2024 14:46:49 +0200 Subject: [PATCH 5/5] Fix test --- fvh3t/fvh3t_processing/count_trajectories.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fvh3t/fvh3t_processing/count_trajectories.py b/fvh3t/fvh3t_processing/count_trajectories.py index 039204e..b529b7f 100644 --- a/fvh3t/fvh3t_processing/count_trajectories.py +++ b/fvh3t/fvh3t_processing/count_trajectories.py @@ -210,9 +210,9 @@ def processAlgorithm( # noqa N802 gate.count_trajectories_from_layer(trajectory_layer) if not start_time: - start_time = QDateTime.fromMSecsSinceEpoch(min_timestamp) + start_time = QDateTime.fromMSecsSinceEpoch(int(min_timestamp)) if not end_time: - end_time = QDateTime.fromMSecsSinceEpoch(max_timestamp) + end_time = QDateTime.fromMSecsSinceEpoch(int(max_timestamp)) exported_gate_layer = gate_layer.as_line_layer( traveler_class=traveler_class, start_time=start_time, end_time=end_time )