# HG changeset patch # User Nicolas Saunier # Date 1288331651 14400 # Node ID 40e1508380ed3942345dde044f0968f227b1ef44 # Parent b8b3768f8d543cf62cb840dd7822b3d4491d4f61 developed indicator classes diff -r b8b3768f8d54 -r 40e1508380ed python/moving.py --- 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