update isstationary

Commit 9012fb72d79a · Nicolas Saunier · 2024-07-26 21:53 +0200

Changeset
9012fb72d79a3130e3b9d6b61bf1a0f1783c15d6

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/trafficintelligence/moving.py b/trafficintelligence/moving.py
--- a/trafficintelligence/moving.py
+++ b/trafficintelligence/moving.py
@@ -1766,7 +1766,7 @@
             self.velocities = self.getPositions().differentiate(True)
         else:
             self.velocities = self.getPositions().differentiate().filterMovingWindow(halfWidth)
-            self.velocities.addPosition(self.velocities[-1])
+        self.velocities.addPosition(self.velocities[-1])
         
     def smoothPositions(self, halfWidth, replace = False):
         'Returns the smoothed positions (or replaces them)'
@@ -1862,7 +1862,7 @@
             if len(indices) >= 2:
                 i = 0
                 j = len(indices)-1
-                #incrementI = True
+                incrementI = True
                 while i<j and (quantile(speeds[indices[i]:indices[j]+1], 0.5) > speedThreshold or Point.distanceNorm2(self.getPositionAt(indices[i]),self.getPositionAt(indices[j])) > distanceThreshold):
                     #if incrementI:
                     i+=1
@@ -1870,6 +1870,15 @@
                     j-=1
                     #incrementI = not incrementI
                 if i<j: # we found a smaller subset
+                    # try to grow the subset
+                    i-=1
+                    while i>=0 and (mean(speeds[indices[i]:indices[j]+1]) <= speedThreshold and Point.distanceNorm2(self.getPositionAt(indices[i]),self.getPositionAt(indices[j])) <= distanceThreshold):
+                        i-=1 # it will go 1 too far
+                    i+=1
+                    j+=1
+                    while j<len(indices) and (mean(speeds[indices[i]:indices[j]+1]) <= speedThreshold and Point.distanceNorm2(self.getPositionAt(indices[i]),self.getPositionAt(indices[j])) <= distanceThreshold):
+                        j+=1 # it will go 1 too far
+                    j-=1
                     firstInstant = self.getFirstInstant()
                     return True, [indices[i]+firstInstant, indices[j]+firstInstant]
                 else: