diff trafficintelligence/indicators.py @ 1042:b1ba6d44fcb9

corrected bug in severity indicators
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 04 Jul 2018 16:21:09 -0400
parents c6cf75a2ed08
children 956a66096e91
line wrap: on
line diff
--- a/trafficintelligence/indicators.py	Wed Jul 04 16:06:23 2018 -0400
+++ b/trafficintelligence/indicators.py	Wed Jul 04 16:21:09 2018 -0400
@@ -159,25 +159,24 @@
         TemporalIndicator.__init__(self, name, values, timeInterval, maxValue)
         self.mostSevereIsMax = mostSevereIsMax
 
-    def getMostSevereValue(self, minNInstants=1, centile=15.):
+    def getMostSevereValue(self, minNInstants=None, centile=None):
         '''if there are more than minNInstants observations, 
         returns either the average of these maximum values 
         or if centile is not None the n% centile from the most severe value
 
-        eg for TTC, 15 returns the 15th centile (value such that 15% of observations are lower)'''
-        if self.__len__() < minNInstants:
-            return None
+        eg for TTC, centile = 15 returns the 15th centile (value such that 15% of observations are lower)'''
+        values = list(self.values.values())
+        if centile is not None:
+            if self.mostSevereIsMax:
+                c = 100-centile
+            else:
+                c = centile
+            return percentile(values, c)
+        elif minNInstants is not None and minNInstants <= self.__len__():
+            values = sorted(values, reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values
+            return mean(values[:minNInstants])
         else:
-            values = list(self.values.values())
-            if centile is not None:
-                if self.mostSevereIsMax:
-                    c = 100-centile
-                else:
-                    c = centile
-                return percentile(values, c)
-            else:
-                values = sorted(values, reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values
-                return mean(values[:minNInstants])
+            return None
 
     def getInstantOfMostSevereValue(self):
         '''Returns the instant at which the indicator reaches its most severe value'''