Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 58:40e1508380ed
developed indicator classes
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 29 Oct 2010 01:54:11 -0400 |
parents | 61fe73df2d36 |
children | 290fceb125d2 |
line wrap: on
line diff
--- a/python/moving.py Fri Oct 29 01:53:38 2010 -0400 +++ b/python/moving.py Fri Oct 29 01:54:11 2010 -0400 @@ -325,11 +325,42 @@ '''Class for temporal indicators i.e. indicators that take a value at specific instants + values should be + * a dict, for the values at specific time instants + * or a list with a time interval object if continuous measurements + it should have more information like name, unit''' - def __init__(self, name, values = {}): + def __init__(self, name, values, timeInterval=None): self.name = name self.values = values + self.timeInterval = timeInterval + +class SeverityIndicator(TemporalIndicator): + '''Class for severity indicators + field mostSevereIsMax is True + if the most severe value taken by the indicator is the maximum''' + + def __init__(self, name, values, mostSevereIsMax=True, ignoredValue = None): + # , timeInterval=None # implement later + TemporalIndicator.__init__(self, name, values, timeInterval=None) + self.mostSevereIsMax = mostSevereIsMax + self.ignoredValue = ignoredValue + + def getMostSevereValue(self, minNInstants=1): + from matplotlib.mlab import find + from numpy.core.multiarray import array + from numpy.core.fromnumeric import mean + values = array(self.values.values()) + if self.ignoredValue: + indices = find(values != self.ignoredValue) + else: + indices = range(len(values)) + if len(indices) >= minNInstants: + values = sorted(values[indices], reverse = self.mostSevereIsMax) # inverted if most severe is max -> take the first values + return mean(values[:minNInstants]) + else: + return None if __name__ == "__main__": import doctest