nsaunier/traffic-intelligence
bug corrected generating last velocity twice and saving it (not saved, duplicated at loading time
Commit 4bc0651d91f9 · Nicolas Saunier · 2026-03-30 15:31 -0400
Comments
No comments yet.
Diff
diff --git a/scripts/dltrack.py b/scripts/dltrack.py
--- a/scripts/dltrack.py
+++ b/scripts/dltrack.py
@@ -258,7 +258,7 @@
feature = moving.MovingObject(featureNum, obj.getTimeInterval(), moving.Trajectory(projected.tolist()))
if smoothingHalfWidth is not None: # smoothing
feature.smoothPositions(smoothingHalfWidth, replace = True)#f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth)
- feature.computeVelocities()
+ feature.computeVelocities(duplicateLastVelocity = False)
obj.features=[feature]
obj.featureNumbers = [featureNum]
#saving
diff --git a/trafficintelligence/moving.py b/trafficintelligence/moving.py
--- a/trafficintelligence/moving.py
+++ b/trafficintelligence/moving.py
@@ -1748,13 +1748,14 @@
else:
return speeds
- def computeVelocities(self, halfWidth = None):
+ def computeVelocities(self, halfWidth = None, duplicateLastVelocity = True):
'''compute velocities, smoothed if halfwidth is not None '''
if halfWidth is None:
self.velocities = self.getPositions().differentiate(True)
else:
self.velocities = self.getPositions().differentiate().filterMovingWindow(halfWidth)
- self.velocities.addPosition(self.velocities[-1])
+ if duplicateLastVelocity:
+ self.velocities.addPosition(self.velocities[-1])
def smoothPositions(self, halfWidth, replace = False):
'Returns the smoothed positions (or replaces them)'