changeset 1265:0f5bebd62a55

minor modifications
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 24 May 2024 16:15:38 -0400
parents dff5b678a33a
children ebb18043616e
files scripts/dltrack.py trafficintelligence/indicators.py trafficintelligence/storage.py
diffstat 3 files changed, 26 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/dltrack.py	Wed May 22 17:11:40 2024 -0400
+++ b/scripts/dltrack.py	Fri May 24 16:15:38 2024 -0400
@@ -235,18 +235,19 @@
 # project, smooth and save
 for num, obj in objects.items():
     features = obj.getFeatures()
-    if moving.userTypeNames[obj.getUserType()] == 'pedestrian':
-        assert len(features) == 2
-        t1 = features[0].getPositions()
-        t2 = features[1].getPositions()
-        t = [[(p1.x+p2.x)/2., max(p1.y, p2.y)] for p1, p2 in zip(t1, t2)]
-    else:
-        t = []
-        for instant in obj.getTimeInterval():
-            points = [f.getPositionAtInstant(instant) for f in features if f.existsAtInstant(instant)]
-            t.append(moving.Point.agg(points, np.mean).aslist())
-        #t = sum([f.getPositions().asArray() for f in features])/len(features)
-        #t = (moving.Trajectory.add(t1, t2)*0.5).asArray()
+    # possible to save bottom pedestrians? not consistent with other users
+    # if moving.userTypeNames[obj.getUserType()] == 'pedestrian':
+    #     assert len(features) == 2
+    #     t1 = features[0].getPositions()
+    #     t2 = features[1].getPositions()
+    #     t = [[(p1.x+p2.x)/2., max(p1.y, p2.y)] for p1, p2 in zip(t1, t2)]
+    # else:
+    t = []
+    for instant in obj.getTimeInterval():
+        points = [f.getPositionAtInstant(instant) for f in features if f.existsAtInstant(instant)]
+        t.append(moving.Point.agg(points, np.mean).aslist())
+    #t = sum([f.getPositions().asArray() for f in features])/len(features)
+    #t = (moving.Trajectory.add(t1, t2)*0.5).asArray()
     projected = cvutils.imageToWorldProject(np.array(t).T, intrinsicCameraMatrix, distortionCoefficients, homography)
     featureNum = features[0].getNum()
     obj.features=[moving.MovingObject(featureNum, obj.getTimeInterval(), moving.Trajectory(projected.tolist()))]
--- a/trafficintelligence/indicators.py	Wed May 22 17:11:40 2024 -0400
+++ b/trafficintelligence/indicators.py	Fri May 24 16:15:38 2024 -0400
@@ -185,12 +185,19 @@
         else:
             return None
 
-    def getInstantOfMostSevereValue(self):
-        '''Returns the instant at which the indicator reaches its most severe value'''
-        if self.mostSevereIsMax:
-            return max(self.values, key=self.values.get)
+    def getInstantOfMostSevereValue(self, minSevereValue = None):
+        '''Returns the instant at which the indicator reaches its most severe value
+        or the instants when value is above minSevereValue (it not None)'''
+        if minSevereValue is None:
+            if self.mostSevereIsMax:
+                return max(self.values, key=self.values.get)
+            else:
+                return min(self.values, key=self.values.get)
         else:
-            return min(self.values, key=self.values.get)
+            if self.mostSevereIsMax:
+                return [t for t in self.values if self.values[t] >= minSevereValue]
+            else:
+                return [t for t in self.values if self.values[t] <= minSevereValue]
 
 # functions to aggregate discretized maps of indicators
 # TODO add values in the cells between the positions (similar to discretizing vector graphics to bitmap)
--- a/trafficintelligence/storage.py	Wed May 22 17:11:40 2024 -0400
+++ b/trafficintelligence/storage.py	Fri May 24 16:15:38 2024 -0400
@@ -497,7 +497,7 @@
     cursor.execute('INSERT INTO interactions VALUES({}, {}, {}, {}, {})'.format(interaction.getNum(), roadUserNumbers[0], roadUserNumbers[1], interaction.getFirstInstant(), interaction.getLastInstant()))
 
 def saveInteractionsToSqlite(filename, interactions):
-    'Saves the interactions in the table'
+    'Saves only the interactions in the table'
     with sqlite3.connect(filename) as connection:
         cursor = connection.cursor()
         try: