diff trafficintelligence/events.py @ 1275:9f1711a85c56

added code to make sure TTC is replaced of recomputed and not having a value
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 19 Jun 2024 16:11:35 -0400
parents 655a1646f0d5
children
line wrap: on
line diff
--- a/trafficintelligence/events.py	Tue Jun 18 15:30:21 2024 -0400
+++ b/trafficintelligence/events.py	Wed Jun 19 16:11:35 2024 -0400
@@ -127,6 +127,10 @@
     def getIndicator(self, indicatorName):
         return self.indicators.get(indicatorName, None)
 
+    def resetIndicator(self, indicatorName):
+        if indicatorName in self.indicators:
+            del self.indicators[indicatorName]
+
     def addIndicator(self, indicator):
         if indicator is not None:
             self.indicators[indicator.name] = indicator
@@ -284,6 +288,9 @@
         if len(TTCs) > 0:
             self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[7], TTCs, mostSevereIsMax=False))
             self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[6], collisionProbabilities))
+        else:
+            for i in [6,7]:
+                self.resetIndicator(Interaction.indicatorNames[i])
         
         # crossing zones and pPET
         if computeCZ:
@@ -299,6 +306,8 @@
         pet, t1, t2=  moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold, computePetWithBoundingPoly)
         if pet is not None:
             self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[10], {min(t1, t2): pet, max(t1, t2): pet}, mostSevereIsMax = False))
+        else:
+            self.resetIndicator(Interaction.indicatorNames[10])
 
     def setCollision(self, collision):
         '''indicates if it is a collision: argument should be boolean'''