diff python/events.py @ 661:dc70d9e711f5

some method name change and new methods for features in objects (MovingObject) and methods to access indicator values in interactions
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 18 May 2015 13:53:25 +0200
parents 3058e00887bc
children 72174e66aba5
line wrap: on
line diff
--- a/python/events.py	Fri May 15 23:09:49 2015 +0200
+++ b/python/events.py	Mon May 18 13:53:25 2015 +0200
@@ -104,6 +104,7 @@
         self.categoryNum = categoryNum
         self.indicators = {}
         self.interactionInterval = None
+        self.collisionPoints = None # distionary for collison points with different prediction methods
 
     def getRoadUserNumbers(self):
         return self.roadUserNumbers
@@ -128,9 +129,24 @@
         return self.indicators.get(indicatorName, None)
 
     def addIndicator(self, indicator):
-        if indicator:
+        if indicator is not None:
             self.indicators[indicator.name] = indicator
 
+    def getIndicatorValueAtInstant(self, indicatorName, instant):
+        indicator = self.getIndicator(indicatorName)
+        if indicator is not None:
+            return indicator[instant]
+        else:
+            return None
+
+    def getIndicatorValuesAtInstant(self, instant):
+        '''Returns list of indicator values at instant
+        as dict (with keys from indicators dict)'''
+        values = {}
+        for k, indicator in self.indicators.iteritems():
+            values[k] = indicator[instant]
+        return values
+        
     def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, **kwargs):
         self.roadUser1.plot(options, withOrigin, timeStep, withFeatures, **kwargs)
         self.roadUser2.plot(options, withOrigin, timeStep, withFeatures, **kwargs)
@@ -177,7 +193,7 @@
         self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[5], speedDifferentials))
 
         # if we have features, compute other indicators
-        if len(self.roadUser1.features) != 0 and len(self.roadUser2.features) != 0:
+        if self.roadUser1.hasFeatures() and self.roadUser2.hasFeatures():
             minDistance={}
             for instant in self.timeInterval:
                 minDistance[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant)
@@ -196,7 +212,9 @@
             commonTimeInterval = timeInterval
         else:
             commonTimeInterval = self.timeInterval
-        self.collisionPoints, self.crossingZones = predictionParameters.computeCrossingsCollisions(self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug, commonTimeInterval, nProcesses,usePrototypes,route1,route2,prototypes,secondStepPrototypes,nMatching,objects,noiseEntryNums,noiseExitNums,minSimilarity,mostMatched,useDestination,useSpeedPrototype,acceptPartialLength, step)
+        self.collisionPoints[predictionParameters.name], crossingZones = predictionParameters.computeCrossingsCollisions(self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug, commonTimeInterval, nProcesses,usePrototypes,route1,route2,prototypes,secondStepPrototypes,nMatching,objects,noiseEntryNums,noiseExitNums,minSimilarity,mostMatched,useDestination,useSpeedPrototype,acceptPartialLength, step)
+        if computeCZ:
+            self.crossingZones[predictionParameters.name] = crossingZones
         for i, cp in self.collisionPoints.iteritems():
             TTCs[i] = prediction.SafetyPoint.computeExpectedIndicator(cp)
         # add probability of collision, and probability of successful evasive action
@@ -213,11 +231,24 @@
         self.pet = moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold)
 
     def addVideoFilename(self,videoFilename):
-        self.videoFilename= videoFilename
+        self.videoFilename = videoFilename
 
     def addInteractionType(self,interactionType):
         ''' interaction types: conflict or collision if they are known'''
-        self.interactionType= interactionType
+        self.interactionType = interactionType
+
+    def getCrossingZones(self, predictionMethodName):
+        if self.hasattr(self, 'crossingZones'):
+            return self.crossingZones[predictionMethodName]
+        else:
+            return None
+
+    def getCollisionPoints(self, predictionMethodName):
+        if self.collisionPoints is not None:
+            return self.collisionPoints[predictionMethodName]
+        else:
+            return None
+
 
 def createInteractions(objects, _others = None):
     '''Create all interactions of two co-existing road users'''